Python VLC 实例 – 播放特定的媒体/广播
在本文中,我们将了解如何从Python vlc 模块中的 Instance 类播放特定媒体。 VLC媒体播放器是VideoLAN项目开发的一款免费开源的便携式跨平台媒体播放软件和流媒体服务器。 Instance 充当 VLC 库的主要对象,使用 Instance 对象我们可以创建媒体播放器、列表播放器或 VLC 中可用的任何其他播放器。实例类是 VLC 中用于创建各种对象的基类。一个实例可以有多个视频,尽管我们也可以播放特定媒体,但它们会一个接一个地播放。
In order to do this we will use vlm_play_media
method with the Instance object
Syntax : instance.vlm_play_media(name)
Argument : It takes media/broadcast name as argument
Return : It returns 0 on success, -1 on error
下面是实现
# importing vlc module
import vlc
# importing time module
import time
# creating Instance class object
player = vlc.Instance()
# creating a new media list
media_list = player.media_list_new()
# creating a media player object
media_player = player.media_list_player_new()
# creating a new media
media = player.media_new("death_note.mkv")
# adding media to media list
media_list.add_media(media)
# setting media list to the mediaplayer
media_player.set_media_list(media_list)
# playing the media
player.vlm_play_media("death_note")
# wait so the video can be played for 5 seconds
# irrespective for length of video
time.sleep(5)
输出 :
另一个例子
下面是实现
# importing vlc module
import vlc
# importing time module
import time
# creating Instance class object
player = vlc.Instance()
# creating a new media list
media_list = player.media_list_new()
# creating a media player object
media_player = player.media_list_player_new()
# creating a new media
media = player.media_new("1.mp4")
# adding media to media list
media_list.add_media(media)
# setting media list to the mediaplayer
media_player.set_media_list(media_list)
# playing the media
player.vlm_play_media("1")
# wait so the video can be played for 5 seconds
# irrespective for length of video
time.sleep(5)
输出 :