Python VLC 绑定(bind)-播放播放列表

标签 python mp3 vlc playlist audio-player

我想知道是否可以打开(播放)音乐播放列表 ( .m3u 文件)使用 vlc.py ?我搜索了答案,但找不到。我设法播放了一个简单的 mp3 文件,甚至是 mp3 流,但我对播放列表没有任何运气。你能帮我,给我一些示例代码吗?我希望能够在我的 python 程序中浏览轨道(下一个和上一个)。比提前

最佳答案

这是我为其他东西编写的一些代码的“非常”粗略模型,适用于您的问题。
它应该允许您使用 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')

关于Python VLC 绑定(bind)-播放播放列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28440708/

相关文章:

python - 强制始终为两个 python 类属性之一赋值?

python - 我正在尝试将我的 Django 应用程序与 Mysql 数据库连接,但是当我尝试迁移负载时,终端中开始弹出错误。

javascript - 将 Web Audio API decodeAudioData 与外部二进制数据一起使用

python - 如何使用 Python 在 Windows 7 上监控 VLC 媒体播放器?

compiler-errors - 错误交叉编译vlc Linux(Ubuntu 12.04)64以赢得64

python - 在 Cartopy 中创建陆地/海洋面具?

python - 我们如何杀死 python 中 subprocess.call() 函数产生的进程?

c++ - 如何在 C/C++ 中获取用于流式传输的 mp3 音频数据包

c# - 在 MemoryStream 中拆分 mp3 音频的正确方法是什么?

vlc - 我可以在 vlc 中制作停靠的播放列表而不是主宰窗口吗?