Skip to content

Commit

Permalink
feat(video): update new video file
Browse files Browse the repository at this point in the history
Change-Id: I141220c37b866d7797e5d0b32d89819427395067
  • Loading branch information
justforlxz authored and haruyukilxz committed May 23, 2018
1 parent 2cd5b87 commit 17eadc7
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 10 deletions.
4 changes: 4 additions & 0 deletions dde-introduction.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,9 @@
<file>resources/dde-introduction.svg</file>
<file>resources/pause_normal.svg</file>
<file>resources/play_normal.svg</file>
<file>resources/15.5.1demo_en-US.mp4</file>
<file>resources/15.5.1demo_en-US@2x.mp4</file>
<file>resources/15.5.1demo_zh-CN.mp4</file>
<file>resources/15.5.1demo_zh-CN@2x.mp4</file>
</qresource>
</RCC>
Binary file added resources/15.5.1demo_en-US.mp4
Binary file not shown.
Binary file added resources/15.5.1demo_en-US@2x.mp4
Binary file not shown.
Binary file added resources/15.5.1demo_zh-CN.mp4
Binary file not shown.
Binary file added resources/15.5.1demo_zh-CN@2x.mp4
Binary file not shown.
35 changes: 25 additions & 10 deletions src/modules/videowidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#include <QBitmap>
#include <QPainter>
#include <QGraphicsOpacityEffect>
#include <QMediaPlaylist>
#include <QIcon>
#include <QLocale>

VideoWidget::VideoWidget(QWidget *parent)
: ModuleInterface(parent)
Expand Down Expand Up @@ -78,18 +81,26 @@ VideoWidget::VideoWidget(QWidget *parent)
m_control->setFixedSize(48, 48);
m_control->raise();

m_player->setMedia(QUrl("http://10.0.13.109/dde-%E6%AC%A2%E8%BF%8E%E6%BC%94%E7%A4%BA%E8%A7%86%E9%A2%91.mp4"));
QMediaPlaylist *list = new QMediaPlaylist(this);
qreal ratio = 1.0;

QLocale locale;
const QString &file = QString(":/resources/15.5.1demo_%1.mp4").arg(locale.language() == QLocale::Chinese ? "zh-CN" : "en-US");

list->addMedia(QUrl(QString("qrc%1").arg(qt_findAtNxFile(file, devicePixelRatioF(), &ratio))));
list->setPlaybackMode(QMediaPlaylist::Loop);

m_player->setMedia(list);

m_video->setSource(m_player);
m_video->setAspectRatioMode(Qt::KeepAspectRatioByExpanding);
m_video->setSourceVideoPixelRatio(devicePixelRatioF());

m_player->setPosition(1);
m_player->pause();

updateControlButton();

connect(m_control, &DImageButton::clicked, this, &VideoWidget::onControlButtonClicked, Qt::QueuedConnection);
connect(m_player, &QMediaPlayer::durationChanged, this, &VideoWidget::durationChanged, Qt::QueuedConnection);

connect(m_player, &QMediaPlayer::stateChanged, this, &VideoWidget::updateControlButton, Qt::QueuedConnection);
}

Expand All @@ -113,6 +124,7 @@ void VideoWidget::updateSmallIcon()
void VideoWidget::updateControlButton()
{
const QPoint &p = rect().center() - m_control->rect().center();

switch (m_player->state()) {
case QMediaPlayer::PlayingState: {
m_control->setNormalPic(":/resources/pause_normal.svg");
Expand All @@ -129,19 +141,16 @@ void VideoWidget::updateControlButton()
m_control->setHoverPic(":/resources/play_hover.svg");
m_control->setPressPic(":/resources/play_press.svg");
if (m_btnAni->startValue().toPoint() == p) {
m_hideEffect->setOpacity(1);
m_control->show();
m_leaveTimer->stop();
m_btnAni->stop();
m_btnAni->setStartValue(m_control->pos());
m_btnAni->setEndValue(p);
m_btnAni->start();
}
}
break;
case QMediaPlayer::StoppedState: {
m_player->play();
m_player->setPosition(1);
m_player->pause();
}
break;
default:
break;
}
Expand Down Expand Up @@ -194,3 +203,9 @@ void VideoWidget::updateClip()
path.addRoundedRect(rect(), 5, 5);
m_clip->setClipPath(path);
}

void VideoWidget::durationChanged()
{
m_player->pause();
updateControlButton();
}
1 change: 1 addition & 0 deletions src/modules/videowidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class VideoWidget : public ModuleInterface {

private:
void updateClip();
void durationChanged();

private:
DVideoWidget *m_video;
Expand Down

0 comments on commit 17eadc7

Please sign in to comment.