Everything seems to be well, but NOTHING GET PLAYED!!!! :oops:
I have tried and tried but doesn't work. WHAT IS WRONG???? :shock:
#media control
#Copyright 2008 Evstevemd
#Just media Player to play the playee
import wx
import wx.media as media
import os, sys
class MediaPlayer(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size = (600, 400))
self.panel = wx.Panel(self, -1)
#self.panel.SetBackgroundColour('grey')
#Main Sizer
main_sizer = wx.BoxSizer(wx.VERTICAL)
#Media Control
hbox = wx.BoxSizer(wx.HORIZONTAL)
self.player = media.MediaCtrl(self.panel, -1, size = (400, 300))
hbox.Add(self.player, 1, wx.EXPAND)
#playlist and its Title in same sizer
playlist_sizer = wx.BoxSizer(wx.VERTICAL)
self.file_list = []
#Playlist title
self.playlist_title = wx.StaticText(self.panel, -1, "Current Play List", style = wx.ALIGN_CENTER)
playlist_sizer.Add(self.playlist_title , 0, wx.EXPAND |wx.ALL, 5)
#Play List display
self.playlist = wx.ListCtrl(self.panel, -1, size = (250, 300), style = wx.LC_REPORT)
self.playlist.InsertColumn(col=0, heading = "Song Name", width = 150)
self.playlist.InsertColumn(col=1, heading = "Directory", width = 100)
self.playlist.InsertColumn(col=2, heading = "Artist", width = 175)
#operate
playlist_sizer.Add(self.playlist , 1, wx.EXPAND |wx.LEFT|wx.RIGHT, 5)
#Add them to a sizer
hbox.Add(playlist_sizer, 1, wx.EXPAND)
main_sizer.Add(hbox,1, wx.EXPAND)
#Load widgets sizers & Bind to events
hsizer1 = wx.BoxSizer()
#open
self.bopen = wx.Button(self.panel, -1, "Open File" )
hsizer1.Add(self.bopen, 0, wx.ALL, 5)
self.Bind(wx.EVT_BUTTON, self.onLoad, id = self.bopen.GetId() )
#stop
self.bstop = wx.BitmapButton(self.panel, -1, wx.Bitmap("./icon/media-playback-stop.png"),size = (22, 22) )
hsizer1.Add(self.bstop, 0, wx.LEFT|wx.TOP|wx.BOTTOM, 5)
self.Bind(wx.EVT_BUTTON, self.onStop, id = self.bstop.GetId())
#Play
self.bplay = wx.BitmapButton(self.panel, -1,wx.Bitmap("./icon/media-playback-start.png"),size = (22, 22) )
hsizer1.Add(self.bplay, 0, wx.LEFT|wx.TOP|wx.BOTTOM, 5)
self.Bind(wx.EVT_BUTTON, self.onPlay, id = self.bplay.GetId())
#Pause
self.bpause = wx.BitmapButton(self.panel, -1,wx.Bitmap("./icon/media-playback-pause.png"),size = (22, 22))
hsizer1.Add(self.bpause, 0, wx.LEFT|wx.TOP|wx.BOTTOM, 5)
self.Bind(wx.EVT_BUTTON, self.onPause, id = self.bpause.GetId())
#Slider
vsizer1 = wx.BoxSizer(wx.VERTICAL)
self.slider = wx.Slider(self.panel, -1,size = (150,-1))
vsizer1.Add(self.slider, 0, wx.ALL, 5)
self.Bind(wx.EVT_SLIDER, self.onSlide)
#Volume Label
volume = self.player.GetVolume()
self.label = wx.StaticText(self.panel, -1, "Volume: %s" %(volume,))
vsizer1.Add(self.label, 0, wx.LEFT|wx.TOP|wx.BOTTOM, 5)
hsizer1.Add(vsizer1, 0, wx.EXPAND)
#Volume up
vsizer2 = wx.BoxSizer(wx.VERTICAL)
self.volup = wx.Button(self.panel, -1, "Vol +", size = (40, 22))
vsizer2.Add(self.volup, 0, wx.LEFT|wx.TOP|wx.BOTTOM, 5)
self.Bind(wx.EVT_BUTTON, self.onVolup, id = self.volup.GetId() )
#Volume down
self.voldown = wx.Button(self.panel, -1, "Vol -", size = (40, 22))
vsizer2.Add(self.voldown, 0, wx.ALL, 5)
self.Bind(wx.EVT_BUTTON, self.onVoldown, id = self.voldown.GetId() )
hsizer1.Add( vsizer2, 0, wx.EXPAND)
#Add to main sizer
main_sizer.Add(hsizer1, 0, wx.EXPAND)
self.panel.SetSizer(main_sizer)
self.panel.Layout()
#Events
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.onTimer)
self.timer.Start(100)
#self.panel.SetInitialSize()
#self.SetInitialSize()
#Load File
def onLoad(self, evt):
msg = wx.FileDialog(self, message = "Open a media file", style = wx.OPEN |wx.FD_CHANGE_DIR |wx.FD_MULTIPLE, wildcard = "Media Files|*.wma;*.mp3;*.avi")
if msg.ShowModal() == wx.ID_OK:
paths = msg.GetPaths()
self.onLoadPlaylist(paths)
#Check format
def onCheck(self, path):
self.path = path
if not self.player.Load(path):
wx.MessageBox("Unable to Play this file, it is in the wrong format")
else:
print "Loaded! %s" %(self.path,)
self.player.Play()
#play it
def onPlay(self, evt):
self.onSetPath()
self.player.Play()
print self.player.Play()
print 'now PLAYING'
self.slider.SetRange(0, self.player.Length())
self.player.SetVolume(0.404459081855)
volume = str(self.player.GetVolume())
self.label.SetLabel("Vol: %s" %(volume,))
#Stop
def onStop(self, evt):
self.player.Stop()
#Pause
def onPause(self, evt):
self.player.Pause()
#Timer
def onTimer(self, evt):
offset = self.player.Tell()
self.slider.SetValue(offset)
#Slider
def onSlide(self, evt):
offset = self.slider.GetValue()
self.player.Seek(offset)
#Volume Up
def onVolup(self, evt):
volume = float(self.player.GetVolume())
volume = volume + 0.05
self.player.SetVolume(volume)
self.label.SetLabel("Vol: %s" %str(volume,))
#Volume Up
def onVoldown(self, evt):
volume = float(self.player.GetVolume())
volume = volume - 0.05
self.player.SetVolume(volume)
self.label.SetLabel("Vol: %s" %str(volume,))
#Loads playList to the List box with name, Format, directory
def onLoadPlaylist(self, paths):
#get list of directories with file names eg c:\steve.mp3
file_list_paths = paths
file_list = []
file_path = dict() #hold filename_ext as keyword and path as value and can be compared to selected file in playlist and get its path as value
for path_s in file_list_paths :
path= path_s.strip()
directory, filename_and_ext = os.path.split(path)
full_tuple = (filename_and_ext, directory, "" )
file_list.append(full_tuple)
file_path[filename_and_ext] = path
#Insert values in Col and Rows
for i in file_list:
index = self.playlist.InsertStringItem(sys.maxint, i[0])
self.playlist.SetStringItem(index, 1, i[1])
self.playlist.SetStringItem(index, 2, i[2])
# Make dictionary the attribute of the class
self.file_path = file_path
# Get selected from list and set it
def onSetPath(self):
index1 = self.playlist.GetFirstSelected()
filename1 = str(self.playlist.GetItemText(index1))
filename = filename1.strip()
path = self.file_path[filename]
self.onCheck(path)
app = wx.App(False)
f = MediaPlayer(None, -1, "Elijah Player")
f.Center()
f.Show(True)
app.MainLoop()