Python VLC MediaList - 从特定索引中删除媒体
在本文中,我们将了解如何通过Python vlc 模块中的 MediaList 对象中的索引删除特定媒体。 VLC媒体播放器是VideoLAN项目开发的一款免费开源的便携式跨平台媒体播放软件和流媒体服务器。 MediaList 对象包含多个媒体,换句话说,它具有可以与 MediaListPlayer 对象一起使用来播放这些多个媒体对象的媒体列表。插入意味着我们可以在给定的索引处添加媒体,它可以通过insert_media
方法插入,我们可以通过add_media
方法将媒体添加到媒体列表中。
In order to do this we will use remove_media
method with the MediaList object
Syntax : media_list.remove_media(index)
Argument : It takes index as argument
Return : It returns 0 on success, -1 if the media list is read-only
下面是实现
# importing vlc module
import vlc
# importing time module
import time
# creating a media player object
media_player = vlc.MediaListPlayer()
# creating Instance class object
player = vlc.Instance()
# creating a media list object
media_list = vlc.MediaList()
# creating a new media
media = player.media_new("death_note.mkv")
# adding media to media list
media_list.add_media(media)
# creating a new media
media = player.media_new("1.mp4")
# inserting media to media list at index 0
media_list.insert_media(media, 0)
# removing media at index 0
media_list.remove_index(0)
# setting media list to the media player
media_player.set_media_list(media_list)
# start playing video
media_player.play()
# 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 a media player object
media_player = vlc.MediaListPlayer()
# creating Instance class object
player = vlc.Instance()
# creating a media list object
media_list = vlc.MediaList()
# creating a new media
media = player.media_new("1.mp4")
# adding media to media list
media_list.add_media(media)
# creating a new media
media = player.media_new("death_note.mkv")
# inserting media to media list at index 0
media_list.insert_media(media, 0)
# removing media at index 0
media_list.remove_index(0)
# setting media list to the media player
media_player.set_media_list(media_list)
# start playing video
media_player.play()
# wait so the video can be played for 5 seconds
# irrespective for length of video
time.sleep(5)
输出 :