Qt呼叫VLC寫的視訊播放器原始碼
阿新 • • 發佈:2019-01-26
先上效果圖:由於是工作上的專案,只能把之前研究VLC的程式碼開源出來,後面修改的商業專案就不共享了。
下載地址:(下載後開啟vlc-qt\demo\demo-player\demo-player.pro即可編譯,不過需要4.8.4版本的QtSdk)
千腦下載:vlc-qt.rar
百度網盤我已委託@夜影幫忙上傳,待會不上!
百度網盤:
部分程式碼:
#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);
}