66
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Implementation of VideoPlaybackVolumeControl
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// Version : %version: 1 %
|
|
19 |
|
|
20 |
|
|
21 |
#include <QTimer>
|
|
22 |
#include <hbvolumesliderpopup.h>
|
|
23 |
|
|
24 |
#include "mpxvideo_debug.h"
|
|
25 |
#include "videoplaybackvolumecontrol.h"
|
|
26 |
#include "videoplaybackcontrolscontroller.h"
|
|
27 |
|
|
28 |
const int KVolumeDragEventTimeOut = 100000; //set volume maximum 10 times a sec during dragging
|
|
29 |
|
|
30 |
|
|
31 |
// -------------------------------------------------------------------------------------------------
|
|
32 |
// VideoPlaybackVolumeControl::VideoPlaybackVolumeControl()
|
|
33 |
// -------------------------------------------------------------------------------------------------
|
|
34 |
//
|
|
35 |
VideoPlaybackVolumeControl::VideoPlaybackVolumeControl( VideoPlaybackControlsController* controller )
|
|
36 |
: mController( controller )
|
|
37 |
, mVolumePopup( NULL )
|
|
38 |
, mDraggingHandlerTimer( NULL )
|
|
39 |
, mVolume( KPbPlaybackVolumeLevelMin )
|
|
40 |
, mVolumeNormalizer( 0 )
|
|
41 |
, mMutedByMuteIcon( false )
|
|
42 |
, mDragging( false )
|
|
43 |
{
|
|
44 |
MPX_ENTER_EXIT(_L("VideoPlaybackVolumeControl::VideoPlaybackVolumeControl"));
|
|
45 |
}
|
|
46 |
|
|
47 |
// -------------------------------------------------------------------------------------------------
|
|
48 |
// VideoPlaybackVolumeControl::~VideoPlaybackVolumeControl()
|
|
49 |
// -------------------------------------------------------------------------------------------------
|
|
50 |
//
|
|
51 |
VideoPlaybackVolumeControl::~VideoPlaybackVolumeControl()
|
|
52 |
{
|
|
53 |
MPX_DEBUG(_L("VideoPlaybackVolumeControl::~VideoPlaybackVolumeControl()"));
|
|
54 |
|
|
55 |
if ( mDraggingHandlerTimer )
|
|
56 |
{
|
|
57 |
disconnect( mDraggingHandlerTimer, SIGNAL( timeout() ), this, SLOT( handleDraggingTimerTimeOut() ) );
|
|
58 |
|
|
59 |
if ( mDraggingHandlerTimer->isActive() )
|
|
60 |
{
|
|
61 |
mDraggingHandlerTimer->stop();
|
|
62 |
}
|
|
63 |
|
|
64 |
delete mDraggingHandlerTimer;
|
|
65 |
mDraggingHandlerTimer = NULL;
|
|
66 |
}
|
|
67 |
|
|
68 |
if ( mVolumePopup )
|
|
69 |
{
|
|
70 |
disconnect( mVolumePopup, SIGNAL( valueChanged( int ) ), this, SLOT( handleSliderValueChanged( int ) ) );
|
|
71 |
disconnect( mVolumePopup, SIGNAL( iconClicked() ), this, SLOT( handleMuteIconClicked() ) );
|
|
72 |
disconnect( mVolumePopup, SIGNAL( sliderPressed() ), this, SLOT( handleSliderPressed() ) );
|
|
73 |
disconnect( mVolumePopup, SIGNAL( sliderReleased() ), this, SLOT( handleSliderReleased() ) );
|
|
74 |
|
|
75 |
delete mVolumePopup;
|
|
76 |
mVolumePopup = NULL;
|
|
77 |
}
|
|
78 |
}
|
|
79 |
|
|
80 |
// -------------------------------------------------------------------------------------------------
|
|
81 |
// VideoPlaybackVolumeControl::initialize()
|
|
82 |
// -------------------------------------------------------------------------------------------------
|
|
83 |
//
|
|
84 |
void VideoPlaybackVolumeControl::initialize()
|
|
85 |
{
|
|
86 |
MPX_ENTER_EXIT(_L("VideoPlaybackVolumeControl::initialize()"));
|
|
87 |
|
|
88 |
if ( ! mVolumePopup )
|
|
89 |
{
|
|
90 |
//
|
|
91 |
// Create volume popup control
|
|
92 |
//
|
|
93 |
mVolumePopup = new HbVolumeSliderPopup();
|
|
94 |
mVolumePopup->setVisible( false );
|
|
95 |
mVolumePopup->setTimeout( KControlsTimeOut );
|
|
96 |
mVolumePopup->setTickPosition( Hb::NoSliderTicks );
|
|
97 |
|
|
98 |
connect( mVolumePopup, SIGNAL( valueChanged( int ) ), this, SLOT( handleSliderValueChanged( int ) ), Qt::QueuedConnection );
|
|
99 |
connect( mVolumePopup, SIGNAL( iconClicked() ), this, SLOT( handleMuteIconClicked() ) );
|
|
100 |
connect( mVolumePopup, SIGNAL( sliderPressed() ), this, SLOT( handleSliderPressed() ) );
|
|
101 |
connect( mVolumePopup, SIGNAL( sliderReleased() ), this, SLOT( handleSliderReleased() ) );
|
|
102 |
|
|
103 |
if ( mController->fileDetails()->mAudioEnabled )
|
|
104 |
{
|
|
105 |
int volumeSteps = mController->volumeSteps();
|
|
106 |
|
|
107 |
mVolumePopup->setRange( 0, volumeSteps );
|
|
108 |
mVolumePopup->setSingleStep( 1 );
|
|
109 |
mVolumeNormalizer = ( KPbPlaybackVolumeLevelMax - KPbPlaybackVolumeLevelMin ) / volumeSteps;
|
|
110 |
mVolumePopup->setValue( mVolume / mVolumeNormalizer );
|
|
111 |
|
|
112 |
mDraggingHandlerTimer = new QTimer();
|
|
113 |
mDraggingHandlerTimer->setSingleShot( false );
|
|
114 |
mDraggingHandlerTimer->setInterval( KVolumeDragEventTimeOut );
|
|
115 |
connect( mDraggingHandlerTimer, SIGNAL( timeout() ), this, SLOT( handleDraggingTimerTimeOut() ) );
|
|
116 |
}
|
|
117 |
else
|
|
118 |
{
|
|
119 |
//
|
|
120 |
// Dimmed the volume control if it is video only
|
|
121 |
//
|
|
122 |
mVolumePopup->setValue( 0 );
|
|
123 |
mVolumePopup->setEnabled( false );
|
|
124 |
}
|
|
125 |
|
|
126 |
}
|
|
127 |
}
|
|
128 |
|
|
129 |
// -------------------------------------------------------------------------------------------------
|
|
130 |
// VideoPlaybackVolumeControl::volumeChanged()
|
|
131 |
// -------------------------------------------------------------------------------------------------
|
|
132 |
//
|
|
133 |
void VideoPlaybackVolumeControl::volumeChanged( int volume )
|
|
134 |
{
|
|
135 |
MPX_DEBUG(_L("VideoPlaybackVolumeControl::volumeChanged() volume = %d"), volume );
|
|
136 |
|
|
137 |
//
|
|
138 |
// If we get expected volume from video helix, we don't need to set the volume to volume slider.
|
|
139 |
// Or we can stay in infinite loop like this..1->2->3->4->1->2->3->4...
|
|
140 |
// Unlike 9.2, mVolumePopup updates UI first and then emit volumechanged signal,
|
|
141 |
// so there should be workaround to avoid infinite loop
|
|
142 |
// 1. mVolumePopup->setValue( 5 )
|
|
143 |
// 2. mVolumePopup emits valueChanged( 5 )
|
|
144 |
// 3. set the volume 5 to video helix
|
|
145 |
// 4. video helix sends voluemchanged with volume 5
|
|
146 |
//
|
|
147 |
if ( mExpectedVolList.length() && mExpectedVolList.first() == volume )
|
|
148 |
{
|
|
149 |
MPX_DEBUG(_L("VideoPlaybackVolumeControl::volumeChanged() mExpectedVolList.first() = %d"),
|
|
150 |
mExpectedVolList.first() );
|
|
151 |
|
|
152 |
mExpectedVolList.removeFirst();
|
|
153 |
}
|
|
154 |
else if ( ! mDragging )
|
|
155 |
{
|
|
156 |
mVolume = volume;
|
|
157 |
|
|
158 |
if ( mVolumePopup )
|
|
159 |
{
|
|
160 |
mVolumePopup->setValue( mVolume / mVolumeNormalizer );
|
|
161 |
setVisible( true );
|
|
162 |
}
|
|
163 |
}
|
|
164 |
}
|
|
165 |
|
|
166 |
// -------------------------------------------------------------------------------------------------
|
|
167 |
// VideoPlaybackVolumeControl::setVisible()
|
|
168 |
// -------------------------------------------------------------------------------------------------
|
|
169 |
//
|
|
170 |
void VideoPlaybackVolumeControl::setVisible( bool visible )
|
|
171 |
{
|
|
172 |
MPX_DEBUG(_L("VideoPlaybackVolumeControl::setVisible() visibility = %d"), visible );
|
|
173 |
|
|
174 |
//
|
|
175 |
// Late init. When we have to show the volume control, we create.
|
|
176 |
//
|
|
177 |
if ( ! mVolumePopup )
|
|
178 |
{
|
|
179 |
initialize();
|
|
180 |
}
|
|
181 |
|
|
182 |
mVolumePopup->setVisible( visible );
|
|
183 |
}
|
|
184 |
|
|
185 |
// -------------------------------------------------------------------------------------------------
|
|
186 |
// VideoPlaybackVolumeControl::isVisible()
|
|
187 |
// -------------------------------------------------------------------------------------------------
|
|
188 |
//
|
|
189 |
bool VideoPlaybackVolumeControl::isVisible()
|
|
190 |
{
|
|
191 |
bool visible = false;
|
|
192 |
|
|
193 |
if ( mVolumePopup )
|
|
194 |
{
|
|
195 |
visible = mVolumePopup->isVisible();
|
|
196 |
}
|
|
197 |
|
|
198 |
MPX_DEBUG(_L("VideoPlaybackVolumeControl::isVisible()"), visible );
|
|
199 |
|
|
200 |
return visible;
|
|
201 |
}
|
|
202 |
|
|
203 |
// -------------------------------------------------------------------------------------------------
|
|
204 |
// VideoPlaybackVolumeControl::handleSliderValueChanged()
|
|
205 |
// -------------------------------------------------------------------------------------------------
|
|
206 |
//
|
|
207 |
void VideoPlaybackVolumeControl::handleSliderValueChanged( int volume )
|
|
208 |
{
|
|
209 |
MPX_DEBUG(_L("VideoPlaybackVolumeControl::handleSliderValueChanged() vol = %d"), volume );
|
|
210 |
|
|
211 |
volume *= mVolumeNormalizer;
|
|
212 |
|
|
213 |
//
|
|
214 |
// If user is dragging, we won't send all the volumechanged value to video helix
|
|
215 |
// since it causes huge traffic and issues with asynchnous calls
|
|
216 |
// So we send commands 10 times a sec as we do in 9.2
|
|
217 |
//
|
|
218 |
if ( mDragging )
|
|
219 |
{
|
|
220 |
mDraggingVolume = volume;
|
|
221 |
}
|
|
222 |
else
|
|
223 |
{
|
|
224 |
setVolume( volume );
|
|
225 |
}
|
|
226 |
}
|
|
227 |
|
|
228 |
// -------------------------------------------------------------------------------------------------
|
|
229 |
// VideoPlaybackVolumeControl::handleMuteIconClicked()
|
|
230 |
// -------------------------------------------------------------------------------------------------
|
|
231 |
//
|
|
232 |
void VideoPlaybackVolumeControl::handleMuteIconClicked()
|
|
233 |
{
|
|
234 |
MPX_DEBUG(_L("VideoPlaybackVolumeControl::handleMuteIconClicked()"));
|
|
235 |
|
|
236 |
if ( mVolumePopup->value() )
|
|
237 |
{
|
|
238 |
mController->handleCommand( EMPXPbvCmdUnMute );
|
|
239 |
}
|
|
240 |
else
|
|
241 |
{
|
|
242 |
mMutedByMuteIcon = true;
|
|
243 |
mController->handleCommand( EMPXPbvCmdMute );
|
|
244 |
}
|
|
245 |
}
|
|
246 |
|
|
247 |
// -------------------------------------------------------------------------------------------------
|
|
248 |
// VideoPlaybackVolumeControl::handleSliderPressed()
|
|
249 |
// -------------------------------------------------------------------------------------------------
|
|
250 |
//
|
|
251 |
void VideoPlaybackVolumeControl::handleSliderPressed()
|
|
252 |
{
|
|
253 |
MPX_DEBUG(_L("VideoPlaybackVolumeControl::handleSliderPressed()"));
|
|
254 |
|
|
255 |
mDragging = true;
|
|
256 |
|
|
257 |
if ( mDraggingHandlerTimer && mDraggingHandlerTimer->isActive() )
|
|
258 |
{
|
|
259 |
mDraggingHandlerTimer->stop();
|
|
260 |
}
|
|
261 |
|
|
262 |
mDraggingHandlerTimer->start( 0 );
|
|
263 |
}
|
|
264 |
|
|
265 |
// -------------------------------------------------------------------------------------------------
|
|
266 |
// VideoPlaybackVolumeControl::handleSliderReleased()
|
|
267 |
// -------------------------------------------------------------------------------------------------
|
|
268 |
//
|
|
269 |
void VideoPlaybackVolumeControl::handleSliderReleased()
|
|
270 |
{
|
|
271 |
MPX_DEBUG(_L("VideoPlaybackVolumeControl::handleSliderReleased()"));
|
|
272 |
|
|
273 |
mDragging = false;
|
|
274 |
|
|
275 |
if ( mDraggingHandlerTimer )
|
|
276 |
{
|
|
277 |
mDraggingHandlerTimer->stop();
|
|
278 |
}
|
|
279 |
|
|
280 |
setVolume( mDraggingVolume );
|
|
281 |
}
|
|
282 |
|
|
283 |
// -------------------------------------------------------------------------------------------------
|
|
284 |
// VideoPlaybackVolumeControl::handleDraggingTimerTimeOut()
|
|
285 |
// -------------------------------------------------------------------------------------------------
|
|
286 |
//
|
|
287 |
void VideoPlaybackVolumeControl::handleDraggingTimerTimeOut()
|
|
288 |
{
|
|
289 |
MPX_DEBUG(_L("VideoPlaybackVolumeControl::handleDraggingTimerTimeOut() mDraggingVolume = %d")
|
|
290 |
,mDraggingVolume );
|
|
291 |
|
|
292 |
if ( mDragging )
|
|
293 |
{
|
|
294 |
setVolume( mDraggingVolume );
|
|
295 |
}
|
|
296 |
}
|
|
297 |
|
|
298 |
// -------------------------------------------------------------------------------------------------
|
|
299 |
// VideoPlaybackVolumeControl::setVolume()
|
|
300 |
// -------------------------------------------------------------------------------------------------
|
|
301 |
//
|
|
302 |
void VideoPlaybackVolumeControl::setVolume( int volume )
|
|
303 |
{
|
|
304 |
MPX_DEBUG(_L("VideoPlaybackVolumeControl::setVolume() mVolume = %d, volume = %d")
|
|
305 |
, mVolume, volume );
|
|
306 |
|
|
307 |
if ( mVolume != volume )
|
|
308 |
{
|
|
309 |
mVolume = volume;
|
|
310 |
|
|
311 |
if ( mMutedByMuteIcon && volume == 0 )
|
|
312 |
{
|
|
313 |
MPX_DEBUG(_L("VideoPlaybackVolumeControl::setVolume() don't need to update volume right after muted"));
|
|
314 |
|
|
315 |
//
|
|
316 |
// If this function gets called sincen user tap on mute icon to mute,
|
|
317 |
// Then add min value to the expectedlist. playback plugin will send min value to ui.
|
|
318 |
//
|
|
319 |
mExpectedVolList.append( KPbPlaybackVolumeLevelMin );
|
|
320 |
|
|
321 |
//
|
|
322 |
// Don't need to update volume '0' right after muted.
|
|
323 |
// If we set '0' to playbackplugin after muted,
|
|
324 |
// it won't go back to previous volume with unmuted through media key or remote
|
|
325 |
//
|
|
326 |
mMutedByMuteIcon = false;
|
|
327 |
}
|
|
328 |
else
|
|
329 |
{
|
|
330 |
MPX_DEBUG(_L("VideoPlaybackVolumeControl::setVolume() setvolume = %d"), mVolume );
|
|
331 |
|
|
332 |
mExpectedVolList.append( mVolume );
|
|
333 |
mController->handleCommand( EMPXPbvCmdSetVolume, mVolume );
|
|
334 |
}
|
|
335 |
}
|
|
336 |
}
|
|
337 |
|
|
338 |
//End of file
|