My first program (Mp3 player)

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2009
Posts: 2
Reputation: Icklebitt is an unknown quantity at this point 
Solved Threads: 0
Icklebitt Icklebitt is offline Offline
Newbie Poster

My first program (Mp3 player)

 
0
  #1
Jul 20th, 2009
Hi, I have recently started trying to teach myself python, I've watched a few video tutorials and am reading "Learning Python".
I have been making an Mp3 player and have hit a point that I cant work my way past so was hoping some kind person here could help me work it out.

The problem is I want to go from only opening one mp3 file and playing it to a playlist system but I cant work out how.

Here is my current code Using (Python 2.6 with Tkinter and mp3play).

{Edit}Just thought I should put a bit more detail in as to what I have tried so far.
basically I have tried using askopenfilenames to get the names of the files and put them in a list, but I have no idea what to do after that . Hope I am making some sense.

  1. from Tkinter import *
  2. import mp3play
  3. import tkFileDialog
  4. import Tkinter
  5.  
  6.  
  7. def open_file(): #Opens a dialog box to open .mp3 file
  8. global music #then sends filename to file_name_label.
  9. global mp3
  10. global play_list
  11. filename.set (tkFileDialog.askopenfilename(defaultextension = ".mp3", filetypes=[("All Types", ".*"), ("MP3", ".mp3")]))
  12. playlist = filename.get()
  13. playlist_pieces = playlist.split("/")
  14. play_list.set (playlist_pieces[-1])
  15. playl = play_list.get()
  16. play_list_display.insert(END, playl)
  17. mp3 = filename.get()
  18. print mp3
  19. music = mp3play.load(mp3)
  20. pieces = mp3.split("/")
  21. name.set (pieces[-1])
  22.  
  23.  
  24. def play(): #Plays the .mp3 file
  25. music.play()
  26.  
  27. def stop(): #Stops the .mp3 file
  28. music.stop()
  29.  
  30. def pause(): #Pauses or unpauses the .mp3 file
  31. if music.ispaused() == True:
  32. music.unpause()
  33. elif music.ispaused() == False:
  34. music.pause()
  35.  
  36.  
  37. def vol(event): #Allows volume to be changed with the slider
  38. v = Scale.get(volume_slider)
  39. music.volume(v)
  40.  
  41. def Exit():
  42. exit()
  43.  
  44.  
  45. root = Tk()
  46. root.title("Ickle Music Player")
  47. root.geometry('300x100+250+100')
  48. filename = Tkinter.StringVar()
  49. name = Tkinter.StringVar()
  50. play_list = Tkinter.StringVar()
  51.  
  52.  
  53. menubar = Menu(root)
  54. filemenu = Menu(menubar, tearoff=0)
  55.  
  56. menubar.add_cascade(label='File', menu = filemenu)
  57. filemenu.add_command(label='Open', command = open_file)
  58. filemenu.add_separator()
  59. filemenu.add_command(label='Exit', command = Exit)
  60.  
  61.  
  62. root.config(menu=menubar)
  63.  
  64. open_file = Button(root, width = 6, height = 1, text = 'Open file', command = open_file)
  65. open_file.grid(row=0, column=3)
  66.  
  67. play_button = Button(root, width = 5, height = 1, text='Play', command = play)
  68. play_button.grid(row=0, column=0, sticky = W)
  69.  
  70. stop_button = Button(root, width = 5, height = 1, text='Stop', command = stop)
  71. stop_button.grid(row=0, column=1, sticky = W)
  72.  
  73. pause_button = Button(root, width = 5, height = 1, text='Pause', command = pause)
  74. pause_button.grid(row=0, column=2)
  75.  
  76. volume_slider = Scale(root, label='Volume', orient = 'horizontal', fg = 'black', command = vol)
  77. volume_slider.grid(row=0, column=4)
  78.  
  79. file_name_label = Label(root, font=('Verdana', 8), fg = 'black', wraplength = 300, textvariable=name )
  80. file_name_label.grid(row=3, column=0, columnspan=8)
  81.  
  82. play_list_window = Toplevel(root, height = 150, width = 100)
  83. play_list_window.title("Playlist")
  84.  
  85. play_list_display = Listbox(play_list_window, width = 50)
  86. play_list_display.pack()
  87.  
  88. play_list_window.mainloop()
  89. root.mainloop()

Thanks
Last edited by Icklebitt; Jul 20th, 2009 at 8:12 am. Reason: More info
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 36
Reputation: Dixtosa is an unknown quantity at this point 
Solved Threads: 1
Dixtosa Dixtosa is offline Offline
Light Poster

Re: My first program (Mp3 player)

 
-1
  #2
Jul 24th, 2009
veeeeery very bad source
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 2
Reputation: Icklebitt is an unknown quantity at this point 
Solved Threads: 0
Icklebitt Icklebitt is offline Offline
Newbie Poster

Re: My first program (Mp3 player)

 
0
  #3
Jul 24th, 2009
Err sorry if I offended you with my newb source.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum


Views: 532 | Replies: 2
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC