在codeBlock中开发vlc的实例

 

准备工作:

安装IDE环境:code::Blocks 13.12 

下载地址:http://www.codeblocks.org/downloads/binaries#windows

具体安装过程参照:http://jingyan.baidu.com/article/414eccf612a3c16b421f0a58.html

下载并解压Vlc库:vlc-2.2.0 

下载地址:http://download.videolan.org/pub/videolan/vlc/

下载一段需要播放的视频。

 

开发步骤:

(1)创建一个控制台应用程序

 





(2)打开project视图中的main.cpp


将文件内容修改为,

#include <stdio.h>

#include <tchar.h>

#include <time.h>

#include <windows.h>

 

#include <vlc/vlc.h>

#pragma comment(lib,"libvlc.lib")

#pragma comment(lib,"libvlccore.lib")

 

int main(int argc, char* argv[])

{

         libvlc_instance_t*     vlc_ins    = NULL;

         libvlc_media_player_t* vlc_player = NULL;

         libvlc_media_t*        vlc_media  = NULL;

 

         constchar * vlc_args[] =

         {

                   "-I",

                   "dummy",

                   "--ignore-config",

                   "--extraintf=logger",

                   "--verbose=2",

         };

 

         //创建一个VLC实例

         vlc_ins= libvlc_new(sizeof(vlc_args)/sizeof(vlc_args[0]), vlc_args);

         if(vlc_ins!= NULL)

         {

                   //创建一个VLC播放器

                   vlc_player= libvlc_media_player_new(vlc_ins);

                   if(vlc_player!= NULL)

                   {

                            //通过文件路径创建一个媒体实例,这里是我的测试文件

                            vlc_media = libvlc_media_new_path(vlc_ins,"E:\\relatedResource\\vr\\dome.mp4");//注意这里要修改为自己需要播放的视频资源路径

                            if(vlc_media!= NULL)

                            {

                                     //解析媒体实例

                                     libvlc_media_parse(vlc_media);

                                     //获取媒体文件的播放长度,  返回 ms

                                     libvlc_time_tduration = libvlc_media_get_duration(vlc_media);

 

                                     //此处是获取媒体包含多个的视频和音频轨以及其他类型的轨道信息

                                     libvlc_media_track_info_t*media_tracks = NULL;

                                     inttrackCount = libvlc_media_get_tracks_info(vlc_media, &media_tracks);

                                     //这里是释放内存,但我测试的时候会有问题,还没仔细研究是为何

                                     //free(media_tracks);  // crash?

 

                                     //把打开的媒体文件设置给播放器

                                     libvlc_media_player_set_media(vlc_player,vlc_media);

 

                                     //因为是windows系统,所以需要设置一个HWND给播放器作为窗口,这里就直接使用桌面窗口,这里仅是测试

                                     libvlc_media_player_set_hwnd(vlc_player,::GetDesktopWindow());

                                     //开始播放视频

                                     libvlc_media_player_play(vlc_player);

 

                                     //这里仅是为了打印一些信息出来,20秒后退出

                                     time_tlast_time = time(NULL);

                                     while((time(NULL)< (last_time + 20)))

                                     {

                                              Sleep(10);

                                               //获取当前播放位置

                                               libvlc_time_tplay_time = libvlc_media_player_get_time(vlc_player);

                                               printf("playingtime : %lld ms\r", (__int64)(play_time));

 

                                               //获取媒体的状态

                                               //libvlc_state_t media_state = libvlc_media_get_state(vlc_media);

                                               //printf("\nmedia state : %d\n", (int)(media_state));

                                     }

                                     //停止

                                     libvlc_media_player_stop(vlc_player);

                                     //释放

                                     libvlc_media_release(vlc_media);

                            }

                            //释放

                            libvlc_media_player_release(vlc_player);

                   }

                   //释放

                   libvlc_release(vlc_ins);

         }

         return0;

}

(3)点击工具栏中的编译按钮

下方的build messages窗口显示错误信息:

||=== Build: Debug in myVlc (compiler: GNUGCC Compiler) ===|

E:\codeBlockWorkspace\myVlc\main.cpp|6|fatalerror: vlc/vlc.h: No such file or directory|

||=== Build failed: 1 error(s), 0warning(s) (0 minute(s), 0 second(s)) ===|


(4)打开project build option窗口


在弹出的窗口中选择search directories选项卡,单击add按钮


添加如下路径:【具体视自己所下载的vlc版本及解压路径而定】

D:\vlc-2.2.0\sdk\include

D:\vlc-2.2.0\sdk\lib


单击ok按钮确定之后,再次编译,发现编译能通过,但是仍然有很多错误提示,


这是连接错误。

(5)再次打开project build option窗口,选择linker setttings选项卡


单击add按钮,添加D:\vlc-2.2.0\sdk\lib路径下的.lib文件,



单击ok确定之后,再次编译,发现刚刚的连接错误没有了,又出现了错误信息如下,

||=== Build: Debug in myVlc (compiler: GNUGCC Compiler) ===|

ld.exe||cannot find libvlc.lib|

ld.exe||cannot find libvlccore.lib|

||=== Build failed: 2 error(s), 0warning(s) (0 minute(s), 0 second(s)) ===|


(6)将vlc解压【安装】路径中的libvlc.dll、libvlc.lib、libvlccore.dll、libvlccore.lib及plugins文件夹都拷贝到工程目录下。


(7)再次编译,则不再报错。


(8)单击工具栏上的运行按钮

能正确播放视频。至此完成!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小帆别吃糖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值