gpt4 book ai didi

python - 无法使用 vlc python 绑定(bind)播放文件

转载 作者:行者123 更新时间:2023-11-28 22:37:33 24 4
gpt4 key购买 nike

import vlc
import sys
def player():
song_list=['C:/Users/Public/Music/SampleMusic/Sleep.mp3',
'C:/Users/Public/Music/SampleMusic/Away.mp3']
instance=vlc.Instance()
for song in song_list:
player=instance.media_player_new()
media=instance.media_new(song)
media.get_mrl()
player.set_media(media)
player.play()
if 'stop' in raw_input('Command'):
player.stop()
sys.exit()

我的代码尝试使用 liblvlc python 绑定(bind)播放列表中的歌曲,当我只播放一首歌曲时,一切正常,但当我尝试循环遍历歌曲列表时,没有播放任何内容

最佳答案

你需要把它放到一个循环中,等待每首歌曲播放完毕。
一个简单的方法如下:

import vlc
import time
song_list=['/path_to_song1/my.mp3','/path_to_song2/other.mp3']
instance=vlc.Instance()
for song in song_list:
player=instance.media_player_new()
media=instance.media_new(song)
print song
media.get_mrl()
player.set_media(media)
player.play()
playing = set([1,2,3,4])
time.sleep(1) #Give time to get going
duration = player.get_length() / 1000
mm, ss = divmod(duration, 60)
print "Playing", song, "Length:", "%02d:%02d" % (mm,ss)
while True:
state = player.get_state()
if state not in playing:
break
continue

关于python - 无法使用 vlc python 绑定(bind)播放文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36448843/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com