Python VLC 绑定-播放播放列表
问题说明
我想知道是否可以打开(播放)音乐播放列表(.m3u 文件)与 vlc.py 一起使用?我搜索了答案,但找不到.我设法播放了一个简单的 mp3 文件,甚至是 mp3 流,但我对播放列表没有任何运气.你能帮我,给我一些示例代码吗?我希望能够在我的 python 程序中浏览曲目(下一个和上一个).比提前
I was wondering if it is possible to open(play) a music playlist ( .m3u file) with the use of vlc.py ? I searched for an answer but could not find it. I managed to play a simple mp3 file, even a mp3 stream, but I dont have any luck with the playlists. Can you help me, give me some example code? I want to be able to go through tracks( Next and Previous) within my python program. Thans in advance
正确答案
这是我为其他东西编写的一些代码的非常"粗略模型,适用于您的问题.
它应该允许您使用 vlc.py 播放流音频、m3u 音频播放列表和 mp3 文件.
正如我所说,这是非常粗略的代码,但它应该为您指明正确的方向.
希望能帮助到你.
Here is a "very" rough mock up of some code that I wrote for something else, adapted to your question.
It should allow you, using vlc.py, to play streamed audio, an m3u audio playlist and an mp3 file.
As I said it is very rough code but it should point you in the right direction.
Hope it helps.
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')
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcgabec
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20