/******************************************************************************
Simple Player: this file is part of QtAV examples
Copyright (C) 2012-2014 Wang Bin <wbsecg1@gmail.com>
* This file is part of QtAV
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#include "playerwindow.h"
#include <QPushButton>
#include <QSlider>
#include <QLayout>
#include <QLabel>
#include <QMessageBox>
#include <QFileDialog>
#include <QDebug>
#include <QtAV/VideoRenderer.h>
using namespace QtAV;
PlayerWindow::PlayerWindow(QWidget *parent)
: QWidget(parent)
{
setWindowTitle("QtAV simple player example");
InitQtAV();
CreateUI();
}
void PlayerWindow::openMedia()
{
QString file = QFileDialog::getOpenFileName(0, "Open a video","","*.mp4 *.rmvb *.mkv *.avi");
if (file.isEmpty())
return;
m_player->play(file);
}
void PlayerWindow::seek(int pos)
{
if (!m_player->isPlaying())
return;
m_player->seek(pos*1000LL); // to msecs
}
void PlayerWindow::playPause()
{
if (!m_player->isPlaying()) {
m_player->play();
return;
}
m_player->pause(!m_player->isPaused());
}
void PlayerWindow::stop()
{
m_player->stop();
m_slider->setValue(0);
m_TotalDurationLab->setText("00:00");
m_CurrentDurationLab->setText("00:00");
}
void PlayerWindow::imageCaptured(QImage image)
{
QString savepath = QFileDialog::getSaveFileName(this,"Save Picture","captured","(*.png);; (*.jpg);; (*.jpge);; (*.bmp)");
if(!savepath.isEmpty())
image.save(savepath);
}
void PlayerWindow::InitQtAV()
{
//AV初始化
m_player = new AVPlayer(this);
m_vo = new VideoOutput(this);
if (!m_vo->widget()) {
QMessageBox::warning(0, "QtAV error", "Can not create video renderer");
return;
}
m_player->setRenderer(m_vo);
}
void PlayerWindow::CreateUI()
{
//控制按钮
m_openBtn = new QPushButton("Open");
m_playBtn = new QPushButton("Play/Pause");
m_stopBtn = new QPushButton("Stop");
m_captureBtn = new QPushButton("Capture");
QHBoxLayout* hlayout = new QHBoxLayout;
hlayout->addWidget(m_openBtn);
hlayout->addWidget(m_playBtn);
hlayout->addWidget(m_stopBtn);
hlayout->addWidget(m_captureBtn);
//时间进度条
m_slider = new QSlider();
m_slider->setOrientation(Qt::Horizontal);
m_TotalDurationLab = new QLabel("00:00");
m_CurrentDurationLab = new QLabel("00:00");
m_TotalDurationLab->setFixedHeight(25);
QHBoxLayout* hlayout1 = new QHBoxLayout;
hlayout1->addWidget(m_CurrentDurationLab);
hlayout1->addSpacing(3);
hlayout1->addWidget(m_slider);
hlayout1->addSpacing(3);
hlayout1->addWidget(m_TotalDurationLab);
QVBoxLayout* mainlayout = new QVBoxLayout(this);
mainlayout->addWidget(m_vo->widget());
mainlayout->addLayout(hlayout1);
mainlayout->addLayout(hlayout);
connect(m_slider, SIGNAL(sliderMoved(int)), SLOT(seek(int)));
connect(m_player, SIGNAL(positionChanged(qint64)), SLOT(updateSlider()));
connect(m_player, SIGNAL(started()), SLOT(updateSlider()));
connect(m_player, SIGNAL(loaded()), SLOT(loadFinish()));
connect(m_openBtn, SIGNAL(clicked()), SLOT(openMedia()));
connect(m_playBtn, SIGNAL(clicked()), SLOT(playPause()));
connect(m_stopBtn, SIGNAL(clicked()), SLOT(stop()));
connect(m_captureBtn, SIGNAL(clicked()),m_player->videoCapture(), SLOT(request()));
connect(m_player->videoCapture(), SIGNAL(imageCaptured(QImage)), SLOT(imageCaptured(QImage)));
}
QString PlayerWindow::SwitchTimes(const int &total)
{
QString hhs,mms,sss;
int hh = total/3600;
int mm = (total-hh*3600)/60;
int ss = (total-hh*3600)%60;
if(hh < 10)
hhs = QString("0%1").arg(hh);
else
hhs = QString("%1").arg(hh);
if(mm < 10)
mms = QString("0%1").arg(mm);
else
mms = QString("%1").arg(mm);
if(ss < 10)
sss = QString("0%1").arg(ss);
else
sss = QString("%1").arg(ss);
if(hh == 0)
return QString("%1:%2").arg(mms).arg(sss);
else
return QString("%1:%2:%3").arg(hhs).arg(mms).arg(sss);
}
void PlayerWindow::updateSlider()
{
m_slider->setRange(0, int(m_player->duration()/1000LL));
m_slider->setValue(int(m_player->position()/1000LL));
m_CurrentDurationLab->setText(SwitchTimes(m_player->position()/1000LL));
}
void PlayerWindow::loadFinish()
{
m_TotalDurationLab->setText(SwitchTimes(m_player->duration()/1000LL));
}
没有合适的资源?快使用搜索试试~ 我知道了~
QtAv player 视频播放器
共96个文件
h:75个
dll:15个
cpp:3个
1星 需积分: 50 26 下载量 187 浏览量
2018-01-08
11:06:59
上传
评论 1
收藏 11.2MB RAR 举报
温馨提示
基于qtav库实现视频播放的一个简单使用例子,可以截图,qtav源码编译的release和debug都在里面了,直接编译就可以运行了。
资源推荐
资源详情
资源评论
收起资源包目录
QtAVPlayer.rar (96个子文件)
QtAVPlayer
widget.h 195B
QtAVPlayer.pro 456B
include
QtAV
AudioResamplerTypes.h 1KB
QtAV_Global.h 3KB
SurfaceInterop.h 2KB
QtAV.h 2KB
version.h 2KB
OpenGLRendererBase.h 3KB
AVClock.h 6KB
Filter.h 5KB
VideoShader.h 6KB
QPainterRenderer.h 2KB
AudioOutputTypes.h 2KB
AVError.h 3KB
AudioOutput.h 9KB
VideoFrame.h 5KB
AVInput.h 3KB
VideoDecoder.h 3KB
OpenGLVideo.h 4KB
Statistics.h 4KB
Subtitle.h 8KB
private
Filter_p.h 2KB
AVDecoder_p.h 2KB
VideoDecoder_p.h 1KB
singleton.h 3KB
AVInput_p.h 1KB
mkid.h 7KB
SubtitleProcessor.h 3KB
QPainterRenderer_p.h 2KB
AVCompat.h 15KB
AVOutput_p.h 2KB
AudioOutput_p.h 5KB
AudioResampler_p.h 2KB
Frame_p.h 2KB
prepost.h 4KB
VideoRenderer_p.h 5KB
VideoShader_p.h 5KB
PlayerSubtitle.h 2KB
factory.h 6KB
OpenGLRendererBase_p.h 2KB
AudioFrame.h 2KB
VideoRendererTypes.h 1KB
FilterContext.h 5KB
LibAVFilter.h 3KB
AVDecoder.h 4KB
Frame.h 4KB
CommonTypes.h 2KB
VideoFormat.h 8KB
OpenGLWindowRenderer.h 2KB
SubtitleFilter.h 4KB
VideoOutput.h 5KB
VideoDecoderTypes.h 2KB
dptr.h 6KB
ColorTransform.h 4KB
VideoCapture.h 5KB
VideoFrameExtractor.h 4KB
QtAV 18B
AudioResampler.h 3KB
VideoRenderer.h 10KB
FactoryDefine.h 7KB
AudioDecoder.h 2KB
AVPlayer.h 15KB
AudioFormat.h 5KB
AVDemuxer.h 7KB
AVOutput.h 3KB
Packet.h 3KB
QtAVWidgets
version.h 2KB
OpenGLWidgetRenderer.h 2KB
GLWidgetRenderer2.h 2KB
GraphicsItemRenderer.h 3KB
VideoPreviewWidget.h 2KB
QtAVWidgets.h 1KB
WidgetRenderer.h 2KB
global.h 2KB
QOpenGLWidget.h 2KB
GLWidgetRenderer.h 3KB
QtAVWidgets 25B
main.cpp 302B
playerwindow.h 2KB
lib
avdevice-56.dll 127KB
swscale-3.dll 475KB
QtAVWidgets1.dll 123KB
avformat-56.dll 1.41MB
swresample-1.dll 110KB
avfilter-5.dll 943KB
QmlAV.dll 172KB
QtAV1.dll 992KB
avutil-54.dll 438KB
common1.dll 129KB
Debug
QtAVd1.dll 23.74MB
QtAVWidgetsd1.dll 4.2MB
commond1.dll 1.5MB
avcodec-56.dll 7.9MB
libportaudio-2.dll 409KB
widget.cpp 114B
playerwindow.cpp 5KB
共 96 条
- 1
资源评论
- mma_BlueSkys2018-01-19不建议下载 响当当的烂 !
决战小树林
- 粉丝: 123
- 资源: 37
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功