Hi,
I have been trying to incorporate the wxPython mediactrl into a Music
player program in am writng in Python. I am running the program in
Win7 and XP.
I have used the program player_skeleton2.py as a guide to the use of
mediactrl control. I have run this program and it runs fine on Win7
and Xp and plays music fine.
Unfortunately, I have not been able to play any file in my program. I
have assumed that all one needs to do is to define the control, load
the file and play it. It apparently loads the file, but does not play.
I then tried to reproduce the problem by testing my assumption above.
I removed what I thought are the unnecessary bits to reproduce the
problem in the player_skeleton2.py program and tried to run it. It did
not run! Ihave included the program and the output below.
I am sure some crucial step is missing from it. But what? I have been
at it for many hours and still cannot find the missing piece.
I must say that I am rather new to wxPython.
Thanks for any help
============ Output ===================
F:\My Programs\Python\Test Programs\music_player_v2>tryplay.py
F:\z1.mp3
Cannot Play
-1
===================== Program =================
···
#----------------------------------------------------------------------
# player_skeleton2.py
#
# Created: 04/15/2010
#
# Author: Mike Driscoll - mike@pythonlibrary.org
#----------------------------------------------------------------------
import os
import wx
import wx.media
import wx.lib.buttons as buttons
class MediaPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent=parent)
self.mediaPlayer = wx.media.MediaCtrl(self)
dlg = wx.FileDialog(self, "Select Library") # Display
dialog box
if dlg.ShowModal() == wx.ID_OK: # If OK
pressed -
File=dlg.GetPath() # Get path selected
dlg.Destroy()
print File
if not self.mediaPlayer.Load(File):
print "Cannot Load"
else:
self.mediaPlayer.SetInitialSize()
if not self.mediaPlayer.Play():
print "Cannot Play"
print self.mediaPlayer.GetState()
else:
print self.mediaPlayer.GetState()
class MediaFrame(wx.Frame):
#----------------------------------------------------------------------
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Python Music
Player")
panel = MediaPanel(self)
if __name__ == "__main__":
app = wx.App(False)
frame = MediaFrame()
frame.Show()
app.MainLoop()