I am trying to play a video using wx.MediaCtrl. When I run my code, the video does not play, only the audio does. I have tried with different videos and file formats but the problem persists.
Here is my code:
import wx
import wx.media
class Video(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
self.Media = wx.media.MediaCtrl(self, style=wx.SIMPLE_BORDER, szBackend=wx.media.MEDIABACKEND_QUICKTIME)
videoPath = "/Users/sherylhsu/Documents/sadf.mp4"
self.Media.Load(videoPath)
self.Media.Play()
app = wx.App(redirect=False)
mainFrame = wx.Frame(None, title="Temp")
video = Video(mainFrame, wx.ID_ANY)
mainFrame.Show()
app.MainLoop()
Thanks for all of your help!
You are showing the mainFrame
so the video doesn't appear.
The simplest way to get this to work is to make Video
the frame:
import wx
import wx.media
class Video(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id)
self.Media = wx.media.MediaCtrl(self, style=wx.SIMPLE_BORDER)
videoPath = "/Users/sherylhsu/Documents/sadf.mp4"
self.Media.Load(videoPath)
self.Media.Play()
self.Show()
app = wx.App(redirect=False)
video = Video(None, wx.ID_ANY)
app.MainLoop()
or keeping your exisiting code, simply move the Show
into the Video
class.
import wx
import wx.media
class Video(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
self.Media = wx.media.MediaCtrl(self, style=wx.SIMPLE_BORDER)
videoPath = "/Users/sherylhsu/Documents/sadf.mp4"
self.Media.Load(videoPath)
self.Media.Play()
self.Show()
app = wx.App(redirect=False)
mainFrame = wx.Frame(None, title="Temp")
video = Video(mainFrame, wx.ID_ANY)
app.MainLoop()
Note: if you don't give MediaCtrl
a backend
, it will pick the most appropriate.