Seite 1 von 1

ein kompakter mediaplayer

Verfasst: Montag 13. August 2007, 13:13
von uruk-kai
ich programmiere gerade einen mediaplayer. ich habe mir bereits pymedia heruntergeladen. :)

nun fehlt mir der lösungsansatz: der player soll alle dateien(*.mp3) in einem verzeichnis abspielen, das der user wählen kann. unterverzeichnisse sollen auch mit einbezogen werden.

Wie kann ich die mp3s komfortabel suchen, finden und abspielen?

Gibt es ein dialogfenster, in dem der user einen ordner auswählen kann?

Verfasst: Montag 13. August 2007, 13:51
von BlackJack
Rekursiv nach MP3s suchen kannst Du mit `os.walk()` programmieren.

Einen Dateidialog für `Tkinter` gibt's zum Beispiel im `FileDialog`-Modul.

Verfasst: Montag 13. August 2007, 14:04
von uruk-kai
danke! :)
Einen Dateidialog für `Tkinter` gibt's zum Beispiel im `FileDialog`-Modul.
ok, das krieg ich hin.
Rekursiv nach MP3s suchen kannst Du mit `os.walk()` programmieren.
sagt mir leider gar nix, bin noch anfänger :oops:

Verfasst: Montag 13. August 2007, 15:29
von schlangenbeschwörer
help(os.walk) hat geschrieben:Help on function walk in module os:

walk(top, topdown=True, onerror=None)
Directory tree generator.

For each directory in the directory tree rooted at top (including top
itself, but excluding '.' and '..'), yields a 3-tuple

dirpath, dirnames, filenames

dirpath is a string, the path to the directory. dirnames is a list of
the names of the subdirectories in dirpath (excluding '.' and '..').
filenames is a list of the names of the non-directory files in dirpath.
Note that the names in the lists are just names, with no path components.
To get a full path (which begins with top) to a file or directory in
dirpath, do os.path.join(dirpath, name).

If optional arg 'topdown' is true or not specified, the triple for a
directory is generated before the triples for any of its subdirectories
(directories are generated top down). If topdown is false, the triple
for a directory is generated after the triples for all of its
subdirectories (directories are generated bottom up).

When topdown is true, the caller can modify the dirnames list in-place
(e.g., via del or slice assignment), and walk will only recurse into the
subdirectories whose names remain in dirnames; this can be used to prune
the search, or to impose a specific order of visiting. Modifying
dirnames when topdown is false is ineffective, since the directories in
dirnames have already been generated by the time dirnames itself is
generated.

By default errors from the os.listdir() call are ignored. If
optional arg 'onerror' is specified, it should be a function; it
will be called with one argument, an os.error instance. It can
report the error to continue with the walk, or raise the exception
to abort the walk. Note that the filename is available as the
filename attribute of the exception object.

Caution: if you pass a relative pathname for top, don't change the
current working directory between resumptions of walk. walk never
changes the current directory, and assumes that the client doesn't
either.

Example:

Code: Alles auswählen

from os.path import join, getsize
    for root, dirs, files in walk('python/Lib/email'):
        print root, "consumes",
        print sum([getsize(join(root, name)) for name in files]),
        print "bytes in", len(files), "non-directory files"
        if 'CVS' in dirs:
            dirs.remove('CVS')  # don't visit CVS directories
[/color]

Verfasst: Montag 13. August 2007, 17:33
von uruk-kai
ok danke. ich schau es mir gleich mal an

Verfasst: Dienstag 14. August 2007, 11:30
von Markus12
Hier etwas zum Modul "tkFileDialog", das Dialogboxen öffnet und du dir eine Datei auswählen kannst ;)

Funktionen:

Code: Alles auswählen

askopenfile() = Erzeugt eine Dialogboy zum Öffnen einer Datei. Zurückgegeben wird ein geöffnetes File-Objekt.

askopenfilename() = Erzeugt Dialogbox zum Öffnen einer Datei. Zurückgegeben wird ein String, der den Pfad der ausgewählten Datei enthält.

asksaveasfile() = Erzeugt Dialogbox zum Speichern einer Datei Zurückgegeben wird ein geöffnetes File-Objekt.

asksaveasfilename() = Erzeugt Dialogbox zum Speichern einer Datei. Zurückgegeben wird ein String, der den Pfad der ausgewählten Datei enthält
Denke, das hilft dir ;)

Gruß Markus