Dear seniors,

I am a newbie in wxPython and I have to write a code that can immediately start playing a video after I load the file. I have been going through a lot of forums tried to implement 10 - 20 codes, but the wx.media is not playing the video file at all. I am able to load the file but not play it.

:(

I need a simple code in which I will manually enter the path name of the video file and after this file is loaded it should start playing.

I am using windows XP, Python 2.7 and wxPython for Python 2.7.

I would be very grateful to all of you if you could help me on this one.

Thanking you.

import wx 
import wx.media
import os

class Panel1(wx.Panel):
    def __init__(self, parent, id):
        #self.log = log
        wx.Panel.__init__(self, parent, -1, style=wx.TAB_TRAVERSAL|wx.CLIP_CHILDREN)
 
        # Create some controls
        try:
            self.mc = wx.media.MediaCtrl(self, style=wx.SIMPLE_BORDER)
        except NotImplementedError:
            self.Destroy()
            raise
        self.mc.Load("C:\Users\Rohit\Videos\Debut\paint.wmv")
        #self.slider.SetRange(0, self.mc.Length())
        #folder, filename = os.path.split("C:\Documents and Settings\N1002401B\Desktop\test1.wmv")
        
        self.mc.Play()
        
class MyApp(wx.App): 
    def OnInit(self): 
        frame = MyFrame(None,'Form1') 
        frame.Show(True) 
        return True 
app = wx.PySimpleApp()
# create a window/frame, no parent, -1 is default ID
frame = wx.Frame(None, -1, "play audio and video files", size = (320, 350))
# call the derived class
Panel1(frame, -1)
frame.Show(1)
app.MainLoop()

This code is not working at all. It is not giving any error but it does not open up the video at all. It just shows a gray screen.

Dear sir,

I am really sorry for my mistake. I did not see that part of the code at all. I have been so much focused on getting the self.mc.play() section working I completely overlooked the MyApp class. I am sorry for the mistake. Can you tell me why is it that even after I load the file still the video does not?

My modified code is :

import wx 
import wx.media
 
class Panel1(wx.Panel):
    def __init__(self, parent, id):
        #self.log = log
        wx.Panel.__init__(self, parent, -1, style=wx.TAB_TRAVERSAL|wx.CLIP_CHILDREN)
 
        # Create some controls
        try:
            self.mc = wx.media.MediaCtrl(self, style=wx.SIMPLE_BORDER)
        except NotImplementedError:
            self.Destroy()
            raise
        self.mc.Load("C:\Users\Rohit\Videos\Debut\paint.wmv")
        #self.slider.SetRange(0, self.mc.Length())
        #folder, filename = os.path.split("C:\Documents and Settings\N1002401B\Desktop\test1.wmv")
 
        self.mc.Play()
 

app = wx.PySimpleApp()
# create a window/frame, no parent, -1 is default ID
frame = wx.Frame(None, -1, "play audio and video files", size = (320, 350))
# call the derived class
Panel1(frame, -1)
frame.Show(1)
app.MainLoop()
This article has been dead for over six months. Start a new discussion instead.