Python VLC MediaPlayer - 获取当前媒体的长度
在本文中,我们将了解如何在Python vlc 模块中获取 MediaPlayer 对象的当前媒体长度。 VLC媒体播放器是VideoLAN项目开发的一款免费开源的便携式跨平台媒体播放软件和流媒体服务器。 MediPlyer 对象是 vlc 模块中用于播放视频的基本对象。我们可以借助MediaPlayer
方法创建一个 MediaPlayer 对象。长度基本上是当前媒体的长度。
In order to do this we will use get_length
method with the MediaPlayer object
Syntax : media_player.get_length()
Argument : It takes no argument
Return : It returns integer (milleseconds)
下面是实现
# importing vlc module
import vlc
# importing time module
import time
# creating vlc media player object
media_player = vlc.MediaPlayer()
# media object
media = vlc.Media("death_note.mkv")
# setting media to the media player
media_player.set_media(media)
# start playing video
media_player.play()
# wait so the video can be played for 5 seconds
# irrespective for length of video
time.sleep(5)
# getting length of the current media
value = media_player.get_length()
# printing value
print("Length of the media : ")
print(value)
输出 :
Length of the media :
1377385
另一个例子
下面是实现
# importing vlc module
import vlc
# importing time module
import time
# creating vlc media player object
media_player = vlc.MediaPlayer()
# media object
media = vlc.Media("1mp4.mkv")
# setting media to the media player
media_player.set_media(media)
# start playing video
media_player.play()
# wait so the video can be played for 5 seconds
# irrespective for length of video
time.sleep(5)
# getting length of the current media
value = media_player.get_length()
# printing value
print("Length of the media : ")
print(value)
输出 :
Length of the media :
5009