1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
/*
* Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "HTML5VideoPlugin.h"
#include <QtPlugin>
HTML5FullScreenVideoHandler::HTML5FullScreenVideoHandler()
: m_videoWidget(0)
, m_mediaPlayer(0)
, m_fullScreen(false)
, m_savedOrientation(CAknAppUi::EAppUiOrientationUnspecified)
{
}
void HTML5FullScreenVideoHandler::enterFullScreen(QMediaPlayer *player)
{
if (!player)
return;
m_videoWidget = new HTML5VideoWidget();
if (!m_videoWidget)
return;
m_videoWidget->setDuration(player->duration() / 1000);
CAknAppUi* appUi = dynamic_cast<CAknAppUi*>(CEikonEnv::Static()->AppUi());
if (appUi) {
m_savedOrientation = appUi->Orientation();
appUi->SetOrientationL(CAknAppUi::EAppUiOrientationLandscape);
}
m_mediaPlayer = player;
connect(m_mediaPlayer, SIGNAL(positionChanged(qint64)), m_videoWidget, SLOT(onPositionChanged(qint64)));
connect(m_mediaPlayer, SIGNAL(durationChanged(qint64)), m_videoWidget, SLOT(setDuration(qint64)));
connect(m_mediaPlayer, SIGNAL(stateChanged(QMediaPlayer::State)), this, SLOT(onPlayerStateChanged(QMediaPlayer::State)));
connect(m_mediaPlayer, SIGNAL(error(QMediaPlayer::Error)), this, SLOT(onPlayerError(QMediaPlayer::Error)));
connect(m_mediaPlayer, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this, SLOT(onMediaStatusChanged(QMediaPlayer::MediaStatus)));
connect(m_videoWidget, SIGNAL(positionChangedByUser(qint64)), m_mediaPlayer, SLOT(setPosition(qint64)));
connect(m_videoWidget, SIGNAL(closeClicked()), this, SIGNAL(fullScreenClosed()));
connect(m_videoWidget, SIGNAL(muted(bool)), m_mediaPlayer, SLOT(setMuted(bool)));
connect(m_videoWidget, SIGNAL(volumeChanged(int)), m_mediaPlayer, SLOT(setVolume(int)));
connect(m_videoWidget, SIGNAL(pauseClicked()), m_mediaPlayer, SLOT(pause()));
connect(m_videoWidget, SIGNAL(playClicked()), m_mediaPlayer, SLOT(play()));
m_mediaPlayer->setVideoOutput(m_videoWidget);
m_videoWidget->setVolume(m_mediaPlayer->volume());
m_videoWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
m_videoWidget->showFullScreen();
m_fullScreen = true;
// Handle current Media Status and Media Player error.
onMediaStatusChanged(m_mediaPlayer->mediaStatus());
onPlayerError(m_mediaPlayer->error());
}
void HTML5FullScreenVideoHandler::exitFullScreen()
{
m_videoWidget->hide();
m_mediaPlayer->disconnect(m_videoWidget);
m_mediaPlayer->disconnect(this);
delete m_videoWidget;
m_videoWidget = 0;
if (m_mediaPlayer->state() == QMediaPlayer::PlayingState)
m_mediaPlayer->pause();
m_fullScreen = false;
CAknAppUi* appUi = dynamic_cast<CAknAppUi*>(CEikonEnv::Static()->AppUi());
if (appUi)
appUi->SetOrientationL(m_savedOrientation);
}
void HTML5FullScreenVideoHandler::onPlayerError(QMediaPlayer::Error error)
{
switch (error) {
case QMediaPlayer::NoError:
break;
default:
m_videoWidget->onPlayerError();
}
}
void HTML5FullScreenVideoHandler::onPlayerStateChanged(QMediaPlayer::State state)
{
if (state == QMediaPlayer::StoppedState)
m_videoWidget->onPlayerStopped();
}
void HTML5FullScreenVideoHandler::onMediaStatusChanged(QMediaPlayer::MediaStatus status)
{
switch (status) {
case QMediaPlayer::EndOfMedia:
m_videoWidget->onEndOfMedia();
break;
case QMediaPlayer::StalledMedia:
case QMediaPlayer::LoadingMedia:
case QMediaPlayer::BufferingMedia:
m_videoWidget->onBufferingMedia();
break;
case QMediaPlayer::LoadedMedia:
case QMediaPlayer::BufferedMedia:
m_videoWidget->onBufferedMedia();
break;
default:
break;
}
return;
}
bool HTML5VideoPlugin::supportsExtension(Extension extension) const
{
switch (extension) {
case FullScreenVideoPlayer:
return true;
default:
return false;
}
}
QObject* HTML5VideoPlugin::createExtension(Extension extension) const
{
HTML5FullScreenVideoHandler* videoHandler = 0;
switch (extension) {
case FullScreenVideoPlayer:
videoHandler = new HTML5FullScreenVideoHandler;
break;
default:
break;
}
return videoHandler;
}
|