使用 libVLC media_list 而不是 media_player 播放歌曲目录 [英] Using libVLC media_list instead of a media_player to play a directory of songs

查看:25
本文介绍了使用 libVLC media_list 而不是 media_player 播放歌曲目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 libVLC v2 C 绑定来播放所有歌曲 (mp3/m4a/ogg)s 在给定路径的目录中.

I'm trying to use libVLC v2 C bindings in order to play all the songs (mp3/m4a/ogg)s inside a directory given its path.

我目前只使用 libvlc_media_player 模块,使用 libvlc_media_player_set_media 之类的方法从给定路径设置歌曲.

I'm currently only using the module libvlc_media_player, with methods like libvlc_media_player_set_media to set a song from a given path.

我看到有一个 模块libvlc_media_list,带有 libvlc_media_list_set_media.

I see there is a module called libvlc_media_list, with libvlc_media_list_set_media.

什么是 libvlc_media_list 以及如何设置它的路径到目录(里面有几个音频文件)?libvlc_media_list_player 需要一个 libvlc_media_player,但我不知道在哪里设置媒体(路径).

What is a libvlc_media_list and how do I set it with a path to a directory (with several audio files inside)? The libvlc_media_list_player takes a libvlc_media_player, but I do not know where to set the media (path).

推荐答案

media_list 用于播放播放列表(.pls .m3u 等)而不是单个文件.
不确定 c 但在 python 中:

media_list is used to play play lists(.pls .m3u etc) as opposed to individual files.
Not sure about c but in python:

Media_list = Instance.media_list_new([url])
list_player = Instance.media_list_player_new()
list_player.set_media_list(Media_list)
list_player.play()

相反:

player = Instance.media_player_new()
Media = Instance.media_new(url)
Media.get_mrl()
player.set_media(Media)
player.play()

对于单个文件.
我希望你能从上面挑骨头.
出于您的目的,您似乎需要使用单个文件选项,使用 url 列表,同时循环遍历列表.

for an individual file.
I hope that you can pick the bones out of the above.
For your purposes, it looks like you need to use the individual file option, using a url list, whilst looping over the list.

再次(道歉)在 python 中:

Again (apologies) in python:

import vlc
import time
my_list = ['vp1.mp3','happy.mp3']
instance = vlc.Instance()
player = instance.media_player_new()
playing = set([1,2,3,4])
for i in my_list:
    player.set_mrl(i)
    player.play()
    play=True
    while play == True:
        time.sleep(1)
        play_state = player.get_state()
        if play_state in playing:
            continue
        else:
            play = False

这篇关于使用 libVLC media_list 而不是 media_player 播放歌曲目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆