本文首发地址:http://www.bcwhy.com/thread-18482-1-1.html Qt调用VLC写的视频播放器源码
最近做了个视频播放器,能播放目前绝大多数格式,也能播放流媒体文件,界面是用Qt做的,这个项目能在mac linux windows等平台编译运行,采用的是C++语言和C++的GUI库Qt调用开源项目VLC提供出来的SDK,VLC是一个开源的视频播放器,比较牛,没听过的朋友可以百度一下。
先上效果图:
下载地址:(下载后打开vlc-qt\demo\demo-player\demo-player.pro即可编译,不过需要4.8.4版本的QtSdk)
百度网盘:http://pan.baidu.com/share/link?shareid=446507&uk=1714263552
部分代码:
#include <QtGui/QFileDialog>
#include <QtGui/QInputDialog>
#include <vlc-qt/Common.h>
#include <vlc-qt/Instance.h>
#include <vlc-qt/Media.h>
#include <vlc-qt/MediaPlayer.h>
#include "DemoPlayer.h"
#include "ui_DemoPlayer.h"
DemoPlayer::DemoPlayer(QWidget *parent)
: QMainWindow(parent),
ui(new Ui::DemoPlayer),
_media(0)
{
ui->setupUi(this);
_instance = new VlcInstance(VlcCommon::args(), this);
_player = new VlcMediaPlayer(_instance);
_player->setVideoWidget(ui->video);
ui->video->setMediaPlayer(_player);
ui->volume->setMediaPlayer(_player);
ui->volume->setVolume(100);
ui->seek->setMediaPlayer(_player);
connect(ui->actionOpenLocal, SIGNAL(triggered()), this, SLOT(openLocal()));
connect(ui->actionOpenUrl, SIGNAL(triggered()), this, SLOT(openUrl()));
connect(ui->actionPause, SIGNAL(triggered()), _player, SLOT(pause()));
connect(ui->actionStop, SIGNAL(triggered()), _player, SLOT(stop()));
connect(ui->pause, SIGNAL(clicked()), _player, SLOT(pause()));
connect(ui->stop, SIGNAL(clicked()), _player, SLOT(stop()));
}
DemoPlayer::~DemoPlayer()
{
delete _player;
delete _media;
delete _instance;
delete ui;
}
void DemoPlayer::openLocal()
{
QString file =
QFileDialog::getOpenFileName(this, tr("Open file"),
QDir::homePath(),
tr("Multimedia files(*)"));
if (file.isEmpty())
return;
_media = new VlcMedia(file, true, _instance);
_player->open(_media);
}
void DemoPlayer::openUrl()
{
QString url =
QInputDialog::getText(this, tr("Open Url"), tr("Enter the URL you want to play"));
if (url.isEmpty())
return;
_media = new VlcMedia(url, _instance);
_player->open(_media);
}