2 qq 36042601 qq_36042601 于 2017.01.06 10:54 提问

python调用vlc显示视频实例

将libvlc.dll和libvlccore.dll放在sdk文件夹中,plugins文件夹也放在sdk文件夹中,sdk文件夹放在程序目录下。
我弄这个,实际上是为了推广,我在北京。有意者请加我微信,我的微商微信:xi9902
myvlc.py文件:
import ctypes
import os
class myvlc():
def init(self):
plugin_arg = r"--plugin-path=" + os.path.join(os.getcwd(), r'sdk\plugins')
arguments = ["-I", "dummy", "--no-ignore-config", plugin_arg]
arguments = [bytes(a,"utf-8") for a in arguments]
p = os.getcwd()
os.chdir(os.path.join(p, 'sdk'))
dll = ctypes.CDLL("libvlc.dll")
os.chdir(p)
self.dll = dll
self.libvlc_instance_ = self.dll.libvlc_new(len(arguments),(ctypes.c_char_p * len(arguments))(*arguments))
self.libvlc_media_player_ = self.dll.libvlc_media_player_new(self.libvlc_instance_)
self.libvlc_media = None
def del(self):
self.Stop()
if(self.libvlc_media):
self.dll.libvlc_media_release(self.libvlc_media)
if(self.libvlc_media_player_):
self.dll.libvlc_media_player_release(self.libvlc_media_player_)
if(self.libvlc_instance_):
self.dll.libvlc_release(self.libvlc_instance_)
def SetRenderWindow(self,hwnd):#嵌入窗体
if(self.libvlc_instance_):
self.dll.libvlc_media_player_set_hwnd(self.libvlc_media_player_,hwnd)
def PlayFile(self,filePath):#播放文件
if(self.libvlc_media):
self.dll.libvlc_media_release(self.libvlc_media)
self.libvlc_media = None
self.libvlc_media = self.dll.libvlc_media_new_path(self.libvlc_instance_, filePath.encode("utf-8"))
if(self.libvlc_media):
self.dll.libvlc_media_player_set_media(self.libvlc_media_player_, self.libvlc_media)
self.dll.libvlc_media_player_play(self.libvlc_media_player_)
def PlayUrl(self,filePath):#播放网络流
if(self.libvlc_media):
self.dll.libvlc_media_release(self.libvlc_media)
self.libvlc_media = None
self.libvlc_media = self.dll.libvlc_media_new_location(self.libvlc_instance_, filePath.encode("utf-8"))
if(self.libvlc_media):
self.dll.libvlc_media_player_set_media(self.libvlc_media_player_, self.libvlc_media)
self.dll.libvlc_media_player_play(self.libvlc_media_player_)
def Stop(self):#停止播放
if(self.libvlc_media_player_):
self.dll.libvlc_media_player_stop(self.libvlc_media_player_)
if(self.libvlc_media):
self.dll.libvlc_media_release(self.libvlc_media)
self.libvlc_media = None

调用方法:
import myvlc

v=myvlc.myvlc()
self.v=v
v.SetRenderWindow(ctypes.c_void_p(int(self.pushButton_8.winId())))
v.PlayFile(r'F:\111.wmv')

1个回答

dabocaiqq
dabocaiqq   2017.01.14 23:13
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!