开发者

Use libvlc to stream mp3 to network

How can I use libvlc to take an MP3 fi开发者_开发技巧le (or really any audio file) and stream it to the network so I can connect with iTunes or something and listen like internet radio?

C API example is preferred, though any language is fine.


libvlc_vlm_add_broadcast accepts an sout string, so this seems to do the trick:

#include <vlc/libvlc.h>
#include <unistd.h>
#include <stdbool.h>
#include <stddef.h>

int main(int argc, char **argv) {
    libvlc_instance_t *vlc;
    const char *url;
    const char *sout = "#transcode{acodec=mp3,ab=128,channels=2," \
                       "samplerate=44100}:http{dst=:8090/go.mp3}";
    const char *media_name = "Foo";

    if (argc != 2) {
        return 1;
    }
    url = argv[1];

    vlc = libvlc_new(0, NULL);
    libvlc_vlm_add_broadcast(vlc, media_name, url, sout, 0, NULL, true, false);
    libvlc_vlm_play_media(vlc, media_name);

    sleep(60); /* Let it play for a minute */

    libvlc_vlm_stop_media(vlc, media_name);
    libvlc_vlm_release(vlc);
    return 0;
}


the documentation is clear enough for this, you create a media (vlc_media_new as I recall), associating an instance of the libvlc to it. Then you create a player from media (vlc_player_from_media or something like that) and then you start playing.

I can't help you for the streaming part because I'm currently trying to figure it out too, but I'll give you a hand as soon as I realize how to get the job done :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜