2
我想知道是否可以使用vlc.py打開(播放)音樂播放列表 (.m3u文件)?我搜索了一個答案,但無法找到它。我設法播放一個簡單的mp3文件,甚至是一個mp3流,但我沒有任何運氣與播放列表。你能幫我嗎,給我一些示例代碼?我希望能夠通過我的python程序中的軌道(Next和Previous)。 Thans提前Python VLC綁定 - 播放播放列表
我想知道是否可以使用vlc.py打開(播放)音樂播放列表 (.m3u文件)?我搜索了一個答案,但無法找到它。我設法播放一個簡單的mp3文件,甚至是一個mp3流,但我沒有任何運氣與播放列表。你能幫我嗎,給我一些示例代碼?我希望能夠通過我的python程序中的軌道(Next和Previous)。 Thans提前Python VLC綁定 - 播放播放列表
這是一個「非常」粗略模擬了一些代碼,我寫了別的東西,適應您的問題。
它應該允許您使用vlc.py播放流式音頻,m3u音頻播放列表和mp3文件。
正如我所說,它是非常粗略的代碼,但它應該指向你在正確的方向。
希望它有幫助。
import requests
import vlc
from time import sleep
urls = [
'http://network.absoluteradio.co.uk/core/audio/aacplus/live.pls?service=acbb',
'file:///home/rolf/test.m3u',
'file:///home/rolf/happy.mp3',
'http://statslive.infomaniak.ch/playlist/energy90s/energy90s-high.mp3/playlist.pls',
'http://streaming.radio.rtl2.fr/rtl2-1-44-128',
]
playlists = set(['pls','m3u'])
Instance = vlc.Instance()
for url in urls:
ext = (url.rpartition(".")[2])[:3]
test_pass = False
try:
if url[:4] == 'file':
test_pass = True
else:
r = requests.get(url, stream=True)
test_pass = r.ok
except Exception as e:
print('failed to get stream: {e}'.format(e=e))
test_pass = False
else:
if test_pass:
print('Sampling for 15 seconds')
player = Instance.media_player_new()
Media = Instance.media_new(url)
Media_list = Instance.media_list_new([url])
Media.get_mrl()
player.set_media(Media)
if ext in playlists:
list_player = Instance.media_list_player_new()
list_player.set_media_list(Media_list)
if list_player.play() == -1:
print ("Error playing playlist")
else:
if player.play() == -1:
print ("Error playing Stream")
sleep(15)
if ext in playlists:
list_player.stop()
else:
player.stop()
else:
print('error getting the audio')
你將不得不編碼自己的播放列表系統或找到一個已經可用的。 – Bioto 2015-02-10 20:09:18
你是什麼意思我自己的系統? VLC播放器(帶GUI)可以播放.m3u文件並進入下一首曲目,之前的曲目...我想知道如何使用vlc.py模塊完成... – 2015-02-10 20:13:20
@NatkoKraševac你有沒有得到這個工作? – 2016-01-30 14:16:33