I have simple player with wx.ListCtrl as playlist. I first Load List through open file dialog. I populate a dictionary with filenames (populated in Playlist) as keys with their path as values. When I press play, the onPlay method calls onSetPath method which looks up for selected file from list and Loads it path to wx.media.MediaCtrl and then it plays file.
The List Loads fine and onSetPath Loads the path but cannot play the file. Any correction on where I mess up?? Below is the code for mentioned method (Full code is little huge)
#Load File paths def onLoad(self, evt): dlg = wx.FileDialog(self, message = "Choose Media File to Open", defaultDir = os.getcwd(), defaultFile = "", wildcard = "Media Files|*.mp3;*.wma; *.avi; *.au;*.mpg", style = wx.FD_OPEN| wx.CHANGE_DIR |wx.FD_MULTIPLE) ret = dlg.ShowModal() if ret == wx.ID_OK: self.paths = dlg.GetPaths() self.onLoadPlaylist(self.paths) dlg.Destroy()
#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 in file_list_paths : path.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) self.playlist.SetStringItem(index, 1, i) self.playlist.SetStringItem(index, 2, i) # 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() filename = self.playlist.GetItemText(index1) path = self.file_path[filename] self.path = path return self.player.Load(self.path)
#play it def onPlay(self, evt): wx.CallAfter(self.onSetPath()) self.player.Play() self.slider.SetRange(0, self.player.Length()) self.player.SetVolume(0.404459081855) volume = str(self.player.GetVolume()) self.label.SetLabel("Vol: %s" %(volume,))