一个简单的C程序中使用libvlc播放MP3 [英] A simple C program to play mp3 using libvlc
问题描述
我是一个普通的C / C ++程序员。最近我参加了一个项目,使一个媒体播放器,智能播放列表。因此,它会像Zune的SmartDj。我已经决定使用libvlc播放。我从来没有codeD一款开源软件永远。所以,我什么都不知道的git和所有。请帮我写至少一个C程序播放一个MP3文件。
I am an average c/c++ programmer. Recently i took a project to make a media player with a smart playlist. So it will work like zune's SmartDj. I have decided to use libvlc for playing. i have never coded an open source software ever. So i know nothing about git and all. Please help me to write at least a c program to play a mp3 file.
我应该在哪里开始呢?
和如何从MP3中提取歌曲的艺术家和其他信息文件本身?
and how to extract song's artists and other information from the mp3 file itself ?
问候。
推荐答案
请确保您已经安装了以下软件包(否则安装):
be sure that you have installed the following packages (else install it):
$ apt-get install libvlccore-dev libvlc-dev
test.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;
}
如何链接和编译:
$ gcc $(pkg-config --cflags libvlc) -c test.c -o test.o
$ gcc test.o -o test $(pkg-config --libs libvlc)
这篇关于一个简单的C程序中使用libvlc播放MP3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!