• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Python VLC 绑定-播放播放列表

用户头像
it1352
帮助1

问题说明

我想知道是否可以打开(播放)音乐播放列表(.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

正确答案

#1

这是我为其他东西编写的一些代码的非常"粗略模型,适用于您的问题.
它应该允许您使用 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
系列文章
更多 icon
同类精品
更多 icon
继续加载