📜  Python VLC MediaPlayer – 获取静音状态

📅  最后修改于: 2022-05-13 01:55:25.532000             🧑  作者: Mango

Python VLC MediaPlayer – 获取静音状态

在本文中,我们将了解如何在Python vlc 模块中获取 MediaPlayer 对象的静音状态。 VLC媒体播放器是VideoLAN项目开发的一款免费开源的便携式跨平台媒体播放软件和流媒体服务器。 MediPlyer 对象是 vlc 模块中用于播放视频的基本对象。如果状态为真则静音,否则取消静音 @warning 此函数并不总是有效。如果没有活动的音频播放流,则静音状态可能不可用。如果使用数字直通(S/PDIF、HDMI…),则静音可能不适用。还有一些音频输出插件根本不支持静音。 @note 要强制静音播放,请禁用所有音轨。这比静音更有效和可靠。可以借助audio_set_mute方法进行设置。

下面是实现

# 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)
  
  
# making mute status True
media_player.audio_set_mute(True)
  
# setting video scale
media_player.video_set_scale(0.6)
  
# 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 mute status
value = media_player.audio_get_mute()
  
# printing value
print("Audio Mute Status: ")
print(value)

输出 :

Audio Mute Status: 
0

另一个例子
下面是实现

# 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)
  
  
# setting video scale
media_player.video_set_scale(0.6)
  
# 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 mute status
value = media_player.audio_get_mute()
  
# printing value
print("Audio Mute Status: ")
print(value)

输出 :

Audio Mute Status: 
0