python调用vlc显示视频实例
2017-01-06 10:50
441 查看
将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')
我弄这个,实际上是为了推广,我在北京。有意者请加我微信,我的微商微信: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')
相关文章推荐
- python调用摄像头显示图像的实例
- 【PythonDjango后台实例 第五章】Bootstrap3 在HTML页面中显示调用本地时间并动态显示
- MFC调用VLC接口在IPC控件显示视频,然后鼠标在视频上绘图解决方法
- MFC调用VLC显示视频时被其他窗口覆盖视频区域变成灰色
- PYTHON 与C相互交互调用实例解析
- Python显示函数调用堆栈
- python 类方法__call__拦截调用实例介绍
- C#接口的隐式和显示调用,区别和实例
- PYTHON 与C相互交互调用实例解析
- c++ 调用 python 实例 涉及 类 多参数 列表作为参数
- 实例教程十四:视频刻录(调用前置摄像头)
- C#接口的隐式和显示调用,区别和实例
- 简单的API函数调用实例(隐藏/显示任务栏)
- 百度地图API调用实例之地址标注与位置显示
- 关于python调用zabbix api接口的自动化实例 [结合saltstack] 推荐
- C#接口的隐式和显示调用,区别和实例
- python实例26[将log同时写入文件和显示到UI的控件中]
- 毕设-03.04 vlc视频输出显示流程代码分析(一)
- python视频教程包含全部代码实例,,需要的单播给我.
- 实例教程十四:视频刻录(调用前置摄像头)