python3 wx.media视频和图像显示?

时间:2017-05-22 03:31:08

标签: python-3.x wxpython

# -*- coding: utf-8 -*-

import wx, wx.media
import time

class TestPanel(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None)
        self.testMedia = wx.media.MediaCtrl(self,
                                            szBackend=wx.media.MEDIABACKEND_WMP10,
                                            style=wx.SIMPLE_BORDER,)

        self.MOVE = ('6.mpg', '7.wmv','1.avi','4.jpg')
        self.testMedia.Load(self.MOVE[0])
        self.testMedia.Bind(wx.media.EVT_MEDIA_LOADED, self.play, self.testMedia)
        self.testMedia.Bind(wx.media.EVT_MEDIA_STATECHANGED, self.play2, self.testMedia)

    def play(self, e):
        self.testMedia.GetBestSize()
        self.testMedia.Play()

    def play2(self, e): 
        if self.testMedia.GetState() == wx.media.MEDIASTATE_STOPPED:
            for i in range(len(self.MOVE)):
                if i == 1:
                    self.testMedia.Load(self.MOVE[1])
                elif i == 2:
                    self.testMedia.Load(self.MOVE[2])
                elif i == 3:
                    self.testMedia.Load(self.MOVE[3])                   

if __name__ == '__main__':
    app = wx.App()
    Fream = TestPanel()
    Fream.Show(True)
    app.MainLoop()

帮助我plz下一个self.MOVE [0] - > [1] - > [2] - > [3] - > [0] ....循环播放 我不知道下一步该做什么......哪里可以看到wx.media教程和exmple代码?

1 个答案:

答案 0 :(得分:0)

你不应该使用wx.media.EVT_MEDIA_STATECHANGED它可能因媒体完成之外的其他原因而改变。请改用wx.media.EVT_MEDIA_FINISHED 你可以使用一个简单的计数器循环 在状态完成时使用索引执行下一个Load,代码应该起作用 我注意到你加载的最后一项是.jpg。不确定这是什么意思"完成"!

# -*- coding: utf-8 -*-

import wx, wx.media
import time

class TestPanel(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None)
        self.testMedia = wx.media.MediaCtrl(self,
                                            szBackend=wx.media.MEDIABACKEND_WMP10,
#                                            szBackend=wx.media.MEDIABACKEND_GSTREAMER,
                                            style=wx.SIMPLE_BORDER,)

        self.MOVE = ('6.mpg', '7.wmv','1.avi','4.jpg')
#        self.MOVE = ('V1.mp4', 'V2.mp4','V3.mp4','V4.mp4')
        self.Mrange = 0
        self.testMedia.Bind(wx.media.EVT_MEDIA_LOADED, self.play, self.testMedia)
        self.testMedia.Bind(wx.media.EVT_MEDIA_FINISHED, self.play2, self.testMedia)
        self.testMedia.Load(self.MOVE[self.Mrange])

    def play(self, e):
        print "Playing:",self.MOVE[self.Mrange]
        self.testMedia.Play()

    def play2(self, e): 
        self.testMedia.Stop()
        self.Mrange += 1
        print self.Mrange
        if self.Mrange > len(self.MOVE) -1:
            self.Mrange = 0
        self.testMedia.Load(self.MOVE[self.Mrange])

if __name__ == '__main__':
    app = wx.App()
    Fream = TestPanel()
    Fream.Show(True)
    app.MainLoop()