| | |
my music player
Thread Solved |
i have made a simple music player that will randomly choose a song from the list (music)
how can i expand this to a whole directory of music without having to make a list with them all in
heres the code:
how can i expand this to a whole directory of music without having to make a list with them all in
heres the code:
Python Syntax (Toggle Plain Text)
import webbrowser, random music = [#music was here] while 1: choice = float(raw_input("Press 1 to play a new song")) if choice == 1: song = random.choice(music) webbrowser.open(song)
Last edited by leegeorg07; Feb 6th, 2009 at 6:30 am. Reason: didnt attach the file
don't judge me because I'm a year 8!
'it is better to fight for something than to live for nothing'General George S Patton
'it is better to fight for something than to live for nothing'General George S Patton
•
•
Join Date: Jun 2008
Posts: 122
Reputation:
Solved Threads: 30
I think Python cannot pick a random file in a directory. If that is the question....
Maybe you can walk through the files, and after a random time you play the current music. But that does not make much sense for me.
Is the music directory too large?
I would recommend a more straightforward method, first without recursion.
Maybe you can walk through the files, and after a random time you play the current music. But that does not make much sense for me.
Is the music directory too large?
I would recommend a more straightforward method, first without recursion.
Python Syntax (Toggle Plain Text)
import webbrowser, random import os import os.path DIR="your directory containing mp3- files" music = filter(lambda x: x.lower().endswith("mp3"),os.listdir(DIR)) while 1: choice = int(raw_input("Press 1 to play a new song")) if choice == 1: song = random.choice(music) webbrowser.open(os.path.join(DIR,song))
Isn't file list a string? Then I guess it should be able to play that. But here is the way I suggest, instead of using directly file names, use indices and random module:
1. Load all paths into list
2. Load random module
3. After music has ended, use random module to select a random index
4. play the file whose index is chosen
here is the random module issue
http://www.google.co.tz/search?q=pyt...ient=firefox-a
1. Load all paths into list
2. Load random module
3. After music has ended, use random module to select a random index
4. play the file whose index is chosen
here is the random module issue
http://www.google.co.tz/search?q=pyt...ient=firefox-a
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
thanks it worked but i needed to add
otherwise it was a string like estevemd said
this is my code now
Python Syntax (Toggle Plain Text)
music = list(music)
this is my code now
Python Syntax (Toggle Plain Text)
import webbrowser, random import os import os.path DIR="C:/Documents and Settings/Owner/My Documents/georges poopy/main music" music = filter(lambda x: x.lower().endswith("mp3"),os.listdir(DIR)) music = list(music) while 1: choice = int(raw_input("Press 1 to play a new song")) if choice == 1: song = random.choice(music) webbrowser.open(os.path.join(DIR,song))
don't judge me because I'm a year 8!
'it is better to fight for something than to live for nothing'General George S Patton
'it is better to fight for something than to live for nothing'General George S Patton
![]() |
Similar Threads
- Toshiba Gigabeat MEG-F40S 40 GB Digital Audio Player Silver (Cellphones, PDAs and Handheld Devices)
- Setting Windows Media Player as default music player (Windows NT / 2000 / XP)
- Music player for flash site (Graphics and Multimedia)
- making flash music player (Graphics and Multimedia)
- Windows Media Player 11 Backup (Windows Software)
- MP3 Player Doesn't Show Up In "My Computer" (Cellphones, PDAs and Handheld Devices)
- MP3 Player Trouble (Cellphones, PDAs and Handheld Devices)
- .cab files? drivers? ('MOSMP028'- ministry of sound mp3 player) (Windows 95 / 98 / Me)
Other Threads in the Python Forum
- Previous Thread: PyDAV question
- Next Thread: Speeding up finding all spaces (' ') in text
| Thread Tools | Search this Thread |
abrupt ansi anti apache approximation array assignment avogadro backend beginner binary bluetooth book builtin calculator character code converter countpasswordentry curved customdialog dan08 dictionaries dictionary dynamic examples exe file float format function gnu graphics gui heads homework ideas import inches input java launcher library line lines linux list lists loop mouse mysqlquery number numbers numeric output parsing path phonebook plugin pointer port prime programming progressbar projects py2exe pygame python random recursion redirect scrolledtext software statictext statistics string strings sum table terminal text textarea thread threading time tlapse trick tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable wordgame write wxpython xlib






