简体   繁体   English

一个使用 libvlc 播放 mp3 的简单 C 程序

[英]A simple C program to play mp3 using libvlc

I am an average C/C++ programmer.我是一个普通的 C/C++ 程序员。 Recently I took a project to make a media player with a smart playlist that will work like Zune's SmartDj.最近我做了一个项目,制作一个带有智能播放列表的媒体播放器,它可以像 Zune 的 SmartDj 一样工作。 I have decided to use libvlc for playing.我决定使用 libvlc 进行播放。

I have never coded an open source software before, so I know nothing about git and all.我以前从未编写过开源软件,所以我对 git 一无所知。 Can you please help me to write at least a C program to play a mp3 file?你能帮我至少写一个 C 程序来播放 mp3 文件吗?

Where should I get started?我应该从哪里开始? How do you extract a song's artist and other information from the mp3 file itself?您如何从 mp3 文件本身中提取歌曲的艺术家和其他信息?

regards.问候。

be sure that you have installed the following packages (else install it):确保您已经安装了以下软件包(否则安装它):

$ apt-get install libvlccore-dev libvlc-dev

test.c:测试.c:

#include <stdio.h>
#include <stdlib.h>

#include <vlc/vlc.h>

int main(int argc, char **argv)
{
    libvlc_instance_t *inst;
    libvlc_media_player_t *mp;
    libvlc_media_t *m;

    // load the vlc engine
    inst = libvlc_new(0, NULL);

    // create a new item
    m = libvlc_media_new_path(inst, "path to MP3 file");

    // create a media play playing environment
    mp = libvlc_media_player_new_from_media(m);

    // no need to keep the media now
    libvlc_media_release(m);

    // play the media_player
    libvlc_media_player_play(mp);

    sleep(10);

    // stop playing
    libvlc_media_player_stop(mp);

    // free the media_player
    libvlc_media_player_release(mp);

    libvlc_release(inst);


    return 0;
}

how to link and compile:如何链接和编译:

$ gcc $(pkg-config --cflags libvlc) -c test.c -o test.o

$ gcc test.o -o test $(pkg-config --libs libvlc)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM