Using libVLC media_list instead of a media_player to play a directory of songs

我与影子孤独终老i 提交于 2019-12-12 04:15:15

问题


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.

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.

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

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).


回答1:


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()

as opposed to:

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

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.

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


来源:https://stackoverflow.com/questions/44229378/using-libvlc-media-list-instead-of-a-media-player-to-play-a-directory-of-songs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!