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绑定播放列表中的歌曲当我只播放一首歌时,一切正常,但是当我尝试循环播放歌曲列表时,没有播放
答案 0 :(得分:4)
你需要将它放入循环中,等待每首歌曲完成播放 一个简单的方法如下:
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