|
1 /* |
|
2 * Copyright (c) 2006 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 the License "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: Base Controller class for handling browser requests to play |
|
15 * audio or video |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <bautils.h> |
|
22 #include <f32file.h> |
|
23 #include <utf.h> |
|
24 #include <e32cmn.h> |
|
25 #include <aknquerydialog.h> // Volume list query dialog |
|
26 #include <aknlists.h> |
|
27 #include <CTSYDomainPSKeys.h> |
|
28 |
|
29 #include <BrowserUiSDKCRKeys.h> |
|
30 #include <BrowserAudioVideoPlugin.rsg> |
|
31 |
|
32 #include "BavpController.h" |
|
33 #include "BavpClipInfo.h" |
|
34 #include "BavpView.h" |
|
35 #include "BavpLogger.h" |
|
36 |
|
37 #if defined(BRDO_ASX_FF) |
|
38 #include "AsxParser.h" |
|
39 #endif //BRDO_ASX_FF |
|
40 |
|
41 #include "eikon.hrh" |
|
42 |
|
43 |
|
44 // CONSTANTS |
|
45 const TInt KBavpMaxLinkFileSize = 5120; // 5kB |
|
46 const TInt KRectPadding = 2; |
|
47 |
|
48 // Define our static BavpController array |
|
49 RPointerArray<CBavpController> CBavpController::iBavpControllerArray; |
|
50 |
|
51 |
|
52 // ============================ MEMBER FUNCTIONS =============================== |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CBavpController::CBavpController |
|
56 // C++ default constructor can NOT contain any code, that |
|
57 // might leave. |
|
58 // ----------------------------------------------------------------------------- |
|
59 CBavpController::CBavpController( MBavpView* aView, |
|
60 TUint aAccessPtId ) |
|
61 : CActive( EPriorityStandard ), |
|
62 iCurrentState( EBavpNone ), |
|
63 iPreCallState( EBavpNone ), |
|
64 iLastCommand( EBavpCmdUnknown ), |
|
65 iLoopCount( 1 ), |
|
66 iInitLoopCount( 1 ), |
|
67 iInfiniteLoopFlag( EFalse ), |
|
68 iAccessPtId( aAccessPtId ), |
|
69 iBavpView( aView ), |
|
70 iOriginalFileName ( NULL ), |
|
71 iMimeType ( NULL ) |
|
72 { |
|
73 CActiveScheduler::Add( this ); |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CBavpController::~CBavpController() |
|
78 // Destructor |
|
79 // ----------------------------------------------------------------------------- |
|
80 CBavpController::~CBavpController() |
|
81 { |
|
82 Log( EFalse, _L("CBavpController::~CBavpController this="), (TInt)this ); |
|
83 |
|
84 if ( iClipInfo ) |
|
85 { |
|
86 delete iClipInfo; |
|
87 } |
|
88 |
|
89 iIncomingCalls.Close(); |
|
90 |
|
91 // Cancel active object and deleting removes from the ActiveScheduler |
|
92 Cancel(); |
|
93 |
|
94 if ( iBavpVolumeHandler ) |
|
95 { |
|
96 delete iBavpVolumeHandler; |
|
97 } |
|
98 |
|
99 // No need to check, if not active, Cancel() does nothing |
|
100 if ( iPositionUpdater ) |
|
101 { |
|
102 iPositionUpdater->Cancel(); |
|
103 delete iPositionUpdater; |
|
104 } |
|
105 |
|
106 if ( iHwKeyEvents ) |
|
107 { |
|
108 delete iHwKeyEvents; |
|
109 } |
|
110 |
|
111 if ( iOriginalFileName ) |
|
112 { |
|
113 delete iOriginalFileName; |
|
114 } |
|
115 |
|
116 if ( iMimeType ) |
|
117 { |
|
118 delete iMimeType; |
|
119 } |
|
120 |
|
121 // Remove this instance from the array |
|
122 TInt index = iBavpControllerArray.Find( this ); |
|
123 if ( index != KErrNotFound ) |
|
124 { |
|
125 iBavpControllerArray.Remove( index ); |
|
126 } |
|
127 if ( iBavpControllerArray.Count() == 0 ) |
|
128 { |
|
129 iBavpControllerArray.Close(); |
|
130 } |
|
131 } |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // CBavpController::HandleBrowserNotification |
|
135 // Default implementation, override as needed. |
|
136 // Handles notification from the Browser concerning the Browser's focus state |
|
137 // (Browser is in-focus, out-focus, foreground, or the background application) |
|
138 // and if this plugin is in-focus or out-focus. If the Browser is out-focus, |
|
139 // this plugin (all plugins) are out-focus. This is not used currently, |
|
140 // because we do not react to the Browser changing focus. We historically would |
|
141 // stop playing audio when the browser's focus changed (including when option |
|
142 // menu is popped up, ie menu top of stack). |
|
143 // ----------------------------------------------------------------------------- |
|
144 void CBavpController::HandleBrowserNotification( TBool aFocus ) |
|
145 { |
|
146 Log( EFalse, _L("CBavpController::HandleBrowserNotification: aBrowserFocus="), |
|
147 aFocus ); |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CBavpController::HandleError |
|
152 // Default implementation, override as needed. |
|
153 // This default error handling implementation just displays the broken (bad) |
|
154 // content animation and sets state to EBavpBadContent. |
|
155 // ----------------------------------------------------------------------------- |
|
156 void CBavpController::HandleError( TInt aError ) |
|
157 { |
|
158 Log( EFalse, _L("CBavpController::HandleError(): aError="), aError ); |
|
159 |
|
160 if ( aError != KErrNone ) |
|
161 { |
|
162 // Any error, display we have bad content |
|
163 iCurrentState = EBavpBadContent; |
|
164 iBavpView->UpdateView(); |
|
165 } |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CBavpController::HandleKeysL |
|
170 // Default implementation, override as needed. |
|
171 // Handles user key presses when the Plugin is Activated. |
|
172 // ----------------------------------------------------------------------------- |
|
173 TKeyResponse CBavpController::HandleKeysL( const TKeyEvent& aKeyEvent, |
|
174 TEventCode /*aType*/ ) |
|
175 { |
|
176 Log( EFalse, _L("CBavpController::HandleKeysL()") ); |
|
177 |
|
178 TKeyResponse keyResponse = EKeyWasNotConsumed; |
|
179 |
|
180 switch ( aKeyEvent.iCode ) |
|
181 { |
|
182 // Cancel key (RSK) was pressed |
|
183 case EKeyDevice1: |
|
184 // Return the focus to the Browser, remove it from Bavp |
|
185 iBavpView->CoeControl().SetFocus( EFalse ); |
|
186 keyResponse = EKeyWasConsumed; |
|
187 break; |
|
188 |
|
189 // Arrow keys was pressed |
|
190 case EKeyUpArrow: // North |
|
191 |
|
192 case EKeyRightUpArrow: // Northeast |
|
193 case EStdKeyDevice11: // Extra KeyEvent supports diagonal event simulator wedge |
|
194 |
|
195 case EKeyRightArrow: // East |
|
196 |
|
197 case EKeyRightDownArrow: // Southeast |
|
198 case EStdKeyDevice12: // Extra KeyEvent supports diagonal event simulator wedge |
|
199 |
|
200 case EKeyDownArrow: // South |
|
201 |
|
202 case EKeyLeftDownArrow: // Southwest |
|
203 case EStdKeyDevice13: // Extra KeyEvent supports diagonal event simulator wedge |
|
204 |
|
205 case EKeyLeftArrow: // West |
|
206 |
|
207 case EKeyLeftUpArrow: // Northwest |
|
208 case EStdKeyDevice10: // Extra KeyEvent supports diagonal event simulator wedge |
|
209 |
|
210 // Do nothing with these keys, there is no navigating inside Bavp. |
|
211 keyResponse = EKeyWasConsumed; |
|
212 break; |
|
213 |
|
214 default: |
|
215 // Do nothing, let the rest of the key events pass back not consumed |
|
216 break; |
|
217 } // end of switch |
|
218 |
|
219 return keyResponse; |
|
220 } |
|
221 |
|
222 // ----------------------------------------------------------------------------- |
|
223 // CBavpController::HandleCommandL |
|
224 // Default implementation, override as needed. |
|
225 // Handles the commands from the Option Menu defined in TBavpCommandIds |
|
226 // ----------------------------------------------------------------------------- |
|
227 void CBavpController::HandleCommandL( TBavpCommandIds aCommand ) |
|
228 { |
|
229 Log( EFalse, _L("CBavpController::HandleCommandL(): aCommand="), (TInt)aCommand ); |
|
230 |
|
231 switch ( aCommand ) |
|
232 { |
|
233 case EBavpCmdPlay: |
|
234 iLastCommand = EBavpCmdPlay; |
|
235 PlayL(); |
|
236 break; |
|
237 |
|
238 case EBavpCmdStop: |
|
239 iLastCommand = EBavpCmdStop; |
|
240 Stop(); |
|
241 break; |
|
242 |
|
243 case EBavpCmdPause: |
|
244 iLastCommand = EBavpCmdPause; |
|
245 PauseL(); |
|
246 break; |
|
247 |
|
248 case EBavpCmdFastForward: |
|
249 iLastCommand = EBavpCmdFastForward; |
|
250 FastForwardL(); |
|
251 break; |
|
252 |
|
253 case EBavpCmdRewind: |
|
254 iLastCommand = EBavpCmdRewind; |
|
255 RewindL(); |
|
256 break; |
|
257 |
|
258 case EBavpCmdChangeVolume: |
|
259 iLastCommand = EBavpCmdChangeVolume; |
|
260 CreateVolumeListDlgL(); |
|
261 break; |
|
262 |
|
263 case EBavpCmdMuteVolume: |
|
264 iLastCommand = EBavpCmdMuteVolume; |
|
265 iBavpVolumeHandler->HandleNotifyInt( KBrowserMediaVolumeControl, |
|
266 KCRVolumeMute ); |
|
267 break; |
|
268 |
|
269 default: |
|
270 iLastCommand = EBavpCmdUnknown; |
|
271 break; |
|
272 } |
|
273 } |
|
274 |
|
275 // ----------------------------------------------------------------------------- |
|
276 // CBavpController::BavpGainedFocus |
|
277 // Default implementation, override as needed. |
|
278 // Called by CBavpView to CBavpPlugin whenever Bavp Plugin has focus and soft key |
|
279 // cancel is hit. When this happens the Browser calls NotifyL with 1. |
|
280 // ----------------------------------------------------------------------------- |
|
281 void CBavpController::BavpFocusChanged( TBool aFocus ) |
|
282 { |
|
283 iBavpHasFocus = aFocus; |
|
284 } |
|
285 |
|
286 // ----------------------------------------------------------------------------- |
|
287 // CBavpController::SetVolumeFromAttribute |
|
288 // Provides CBavpController with the volume attribute from the tags on the |
|
289 // HTTP page, i.e. <object volume="high"... |
|
290 // ----------------------------------------------------------------------------- |
|
291 void CBavpController::SetVolumeFromAttribute( TInt aAttributeVolume ) |
|
292 { |
|
293 // Use the lower volume: |
|
294 // 1) Current volume (iCurrentVolume) |
|
295 // 2) Volume setting on web page (aAttributeVolume) |
|
296 if ( aAttributeVolume < iCurrentVolume ) |
|
297 { |
|
298 iCurrentVolume = aAttributeVolume; |
|
299 iBavpVolumeHandler->HandleNotifyInt( KBrowserMediaVolumeControl, |
|
300 iCurrentVolume ); |
|
301 } |
|
302 } |
|
303 |
|
304 // ----------------------------------------------------------------------------- |
|
305 // CBavpController::SetLoopFromAttribute |
|
306 // Provides CBavpController with the loop attribute from the tags on the |
|
307 // HTTP page, i.e. <object loop="infinite"... or <object loop="4"... |
|
308 // ----------------------------------------------------------------------------- |
|
309 void CBavpController::SetLoopFromAttribute( TInt aLoopValue, TBool aInfiniteFlag ) |
|
310 { |
|
311 // Save the loop count, already checked for valid range |
|
312 iLoopCount = aLoopValue; |
|
313 |
|
314 // Save the initial loop count, in case we get an error while looping |
|
315 // through the content |
|
316 iInitLoopCount = iLoopCount; |
|
317 |
|
318 // If the loop value is set to "infinite" looping. We currently use |
|
319 // a max loop of 50 for infinite |
|
320 iInfiniteLoopFlag = aInfiniteFlag; |
|
321 } |
|
322 |
|
323 // ----------------------------------------------------------------------------- |
|
324 // CBavpControllerAudioo::RefreshRectCoordinates |
|
325 // Refresh the coordinates of rect for display |
|
326 // ----------------------------------------------------------------------------- |
|
327 void CBavpController::RefreshRectCoordinates() |
|
328 { |
|
329 Log( EFalse, _L("CBavpController::RefreshRectCoordinates()") ); |
|
330 } |
|
331 |
|
332 // ----------------------------------------------------------------------------- |
|
333 // CBavpController::ParseRamFileL |
|
334 // Read the ram file and parse the the url, put into iClipInfo->iUrl |
|
335 // ----------------------------------------------------------------------------- |
|
336 void CBavpController::ParseRamFileL() |
|
337 { |
|
338 Log( EFalse, _L("CBavpController::ParseRamFileL() ") ); |
|
339 |
|
340 RFs rFs; |
|
341 RFile ramFile; |
|
342 |
|
343 // Connect to file server: |
|
344 User::LeaveIfError( rFs.Connect() ); |
|
345 CleanupClosePushL( rFs ); |
|
346 |
|
347 if ( !BaflUtils::FileExists( rFs, *iClipInfo->iFileName ) ) |
|
348 { |
|
349 User::Leave( KErrNotFound ); |
|
350 } |
|
351 |
|
352 User::LeaveIfError( ramFile.Open( rFs, *iClipInfo->iFileName, EFileShareAny ) ); |
|
353 CleanupClosePushL( ramFile ); |
|
354 |
|
355 TInt size; |
|
356 User::LeaveIfError( ramFile. Size( size ) ); |
|
357 if ( size > KBavpMaxLinkFileSize ) |
|
358 { |
|
359 User::Leave( KErrNotFound ); |
|
360 } |
|
361 |
|
362 HBufC8* urlBuf = HBufC8::NewLC( size ); |
|
363 TPtr8 ptr = urlBuf->Des(); |
|
364 |
|
365 // Read file to urlBuf |
|
366 User::LeaveIfError( ramFile.Read( ptr ) ); |
|
367 |
|
368 // Set the iClipInfo->iUrl |
|
369 if ( iClipInfo->iUrl ) |
|
370 { |
|
371 delete iClipInfo->iUrl; |
|
372 iClipInfo->iUrl = NULL; |
|
373 } |
|
374 iClipInfo->iUrl = HBufC::NewL( urlBuf->Length() ); |
|
375 |
|
376 TPtr urlDes = iClipInfo->iUrl->Des(); |
|
377 |
|
378 // Read to the end of the line that should be a link |
|
379 TInt lineChange = urlBuf->LocateF( EKeyLineFeed ); |
|
380 if ( lineChange == KErrNotFound ) |
|
381 { |
|
382 // No line change was found --> last line had no line change |
|
383 // Copy last line to (unicode) aLink |
|
384 CnvUtfConverter::ConvertToUnicodeFromUtf8( urlDes, *urlBuf ); |
|
385 } |
|
386 else |
|
387 { |
|
388 // Set the descriptor to the end of the line |
|
389 if ( (lineChange > 0) && (urlBuf->Des()[lineChange - 1] == EKeyEnter) ) |
|
390 { |
|
391 lineChange--; |
|
392 } |
|
393 |
|
394 // Copy line to (unicode) url |
|
395 CnvUtfConverter::ConvertToUnicodeFromUtf8( urlDes, urlBuf->Left( lineChange ) ); |
|
396 } |
|
397 |
|
398 CleanupStack::PopAndDestroy( 3 ); // ramFile, urlBuf, rFs |
|
399 } |
|
400 |
|
401 |
|
402 #if defined(BRDO_ASX_FF) |
|
403 // ----------------------------------------------------------------------------- |
|
404 // CBavpController::ParseAsxFileL |
|
405 // Read the asx file and parse the the url, put into iClipInfo->iUrl |
|
406 // Only retrieve the first URL found |
|
407 // ----------------------------------------------------------------------------- |
|
408 void CBavpController::ParseAsxFileL() |
|
409 { |
|
410 Log( EFalse, _L("CBavpController::ParseAsxFileL() ") ); |
|
411 |
|
412 TUint urls = 0; |
|
413 TPtrC8 url; |
|
414 |
|
415 if ( iClipInfo->iUrl ) |
|
416 { |
|
417 delete iClipInfo->iUrl; |
|
418 iClipInfo->iUrl = NULL; |
|
419 } |
|
420 |
|
421 CAsxParser* asxParser = CAsxParser::NewL(*iClipInfo->iFileName); |
|
422 |
|
423 CleanupStack::PushL( asxParser ); |
|
424 |
|
425 if ( asxParser ) |
|
426 { |
|
427 asxParser->GetUrlCount(urls); |
|
428 if ( urls > 0 ) |
|
429 asxParser->GetUrl(1,url); |
|
430 } |
|
431 |
|
432 iClipInfo->iUrl = HBufC::NewL( url.Length() ); |
|
433 TPtr urlDes = iClipInfo->iUrl->Des(); |
|
434 CnvUtfConverter::ConvertToUnicodeFromUtf8( urlDes, url); |
|
435 |
|
436 CleanupStack::PopAndDestroy(); // asxparser |
|
437 } |
|
438 #endif // BRDO_ASX_FF |
|
439 |
|
440 |
|
441 // CBavpController::GetClipRect |
|
442 // Retrieve the rect position. Ex. not intersect with title pane and status pane |
|
443 // ----------------------------------------------------------------------------- |
|
444 TRect CBavpController::GetClipRect( TRect aRect ) |
|
445 { |
|
446 TRect clipRect ( aRect ); |
|
447 Log( EFalse, _L("GetClipRect") ); |
|
448 |
|
449 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, iNormalScreenRect ); |
|
450 |
|
451 // Calculate not to cover the bottom or the top of the rect. |
|
452 if ( clipRect.iTl.iX < iNormalScreenRect.iTl.iX ) |
|
453 { |
|
454 clipRect.iTl.iX = iNormalScreenRect.iTl.iX; |
|
455 } |
|
456 |
|
457 if ( clipRect.iTl.iY < iNormalScreenRect.iTl.iY ) |
|
458 { |
|
459 clipRect.iTl.iY = iNormalScreenRect.iTl.iY; |
|
460 } |
|
461 |
|
462 if ( clipRect.iBr.iY > iNormalScreenRect.iBr.iY ) |
|
463 { |
|
464 clipRect.iBr.iY = iNormalScreenRect.iBr.iY; |
|
465 } |
|
466 |
|
467 if ( clipRect.iBr.iX > iNormalScreenRect.iBr.iX ) |
|
468 { |
|
469 clipRect.iBr.iX = iNormalScreenRect.iBr.iX - KRectPadding; |
|
470 } |
|
471 |
|
472 return clipRect; |
|
473 } |
|
474 |
|
475 // ----------------------------------------------------------------------------- |
|
476 // CBavpController::CreateVolumeListDlg |
|
477 // Create the volume list query dialog |
|
478 // ----------------------------------------------------------------------------- |
|
479 void CBavpController::CreateVolumeListDlgL() |
|
480 { |
|
481 CEikTextListBox* list = new(ELeave) CAknSinglePopupMenuStyleListBox; |
|
482 CleanupStack::PushL( list ); |
|
483 |
|
484 // Create popup list and PUSH it. |
|
485 CAknPopupList* popupList = CAknPopupList::NewL( list, |
|
486 R_AVKON_SOFTKEYS_OK_CANCEL, |
|
487 AknPopupLayouts::EMenuWindow); |
|
488 CleanupStack::PushL( popupList ); |
|
489 |
|
490 // Initialize listbox. |
|
491 list->ConstructL( popupList, CEikListBox::ELeftDownInViewRect ); |
|
492 list->CreateScrollBarFrameL( ETrue ); |
|
493 list->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, |
|
494 CEikScrollBarFrame::EAuto ); |
|
495 |
|
496 // Make list items and PUSH it |
|
497 CDesCArrayFlat* items = |
|
498 CCoeEnv::Static()->ReadDesCArrayResourceL( R_AKNTAPOPLIST_MENU_VOLUME_ITEMS ); |
|
499 |
|
500 // Set list items. |
|
501 CTextListBoxModel* model = list->Model(); |
|
502 model->SetItemTextArray( items ); |
|
503 model->SetOwnershipType( ELbmOwnsItemArray ); |
|
504 |
|
505 // Using the current volume set to determine the index of the volume value |
|
506 // to highlight in the list |
|
507 TInt volumeIndex( 0 ); |
|
508 if ( iCurrentVolume == KCRVolume0 ) |
|
509 { |
|
510 volumeIndex = 0; |
|
511 } |
|
512 else if ( iCurrentVolume == KCRVolume2 ) |
|
513 { |
|
514 volumeIndex = 1; |
|
515 } |
|
516 else if ( iCurrentVolume == KCRVolume5 ) |
|
517 { |
|
518 volumeIndex = 2; |
|
519 } |
|
520 else if ( iCurrentVolume == KCRVolume8 ) |
|
521 { |
|
522 volumeIndex = 3; |
|
523 } |
|
524 else if ( iCurrentVolume == KCRVolume10 ) |
|
525 { |
|
526 volumeIndex = 4; |
|
527 } |
|
528 |
|
529 // Highlight the current item in the list box |
|
530 list->SetCurrentItemIndexAndDraw( volumeIndex ); |
|
531 |
|
532 HBufC* title = CCoeEnv::Static()->AllocReadResourceLC( R_TEXT_VIDEO_PLUGIN_MEDIA_VOLUME); |
|
533 popupList->SetTitleL( *title ); |
|
534 CleanupStack::PopAndDestroy(); // title |
|
535 |
|
536 // Show popup list and then show return value. |
|
537 TInt popupOk = popupList->ExecuteLD(); |
|
538 CleanupStack::Pop(); // popuplist |
|
539 |
|
540 // Handle the returned value from the volume list dialog |
|
541 if ( popupOk ) |
|
542 { |
|
543 // Check if there is change for the volume select |
|
544 if ( volumeIndex != list->CurrentItemIndex() ) |
|
545 { |
|
546 // Set the current index to volume index |
|
547 volumeIndex = list->CurrentItemIndex(); |
|
548 |
|
549 // To match the list box data to the values defined in |
|
550 // the Central repository: (mute)0,2,5,8,10(maximum) |
|
551 if ( volumeIndex == 0 ) |
|
552 { |
|
553 iCurrentVolume = KCRVolume0; |
|
554 } |
|
555 else if ( volumeIndex == 1 ) |
|
556 { |
|
557 iCurrentVolume = KCRVolume2; |
|
558 } |
|
559 else if ( volumeIndex == 2 ) |
|
560 { |
|
561 iCurrentVolume = KCRVolume5; |
|
562 } |
|
563 else if ( volumeIndex == 3 ) |
|
564 { |
|
565 iCurrentVolume = KCRVolume8; |
|
566 } |
|
567 else if ( volumeIndex == 4 ) |
|
568 { |
|
569 iCurrentVolume = KCRVolume10; |
|
570 } |
|
571 |
|
572 Log( EFalse, _L("Return Volume from Player="), iCurrentVolume ); |
|
573 |
|
574 // Tell the volume handler about our new volume the user selected |
|
575 iBavpVolumeHandler->HandleNotifyInt( KBrowserMediaVolumeControl, |
|
576 iCurrentVolume ); |
|
577 } |
|
578 } |
|
579 |
|
580 CleanupStack::PopAndDestroy(); // list |
|
581 } |
|
582 |
|
583 // ----------------------------------------------------------------------------- |
|
584 // CBavpController::IsVideoOrAudioCall |
|
585 // Check if there is an incoming call |
|
586 // ----------------------------------------------------------------------------- |
|
587 TBool CBavpController::IsVideoOrAudioCall() |
|
588 { |
|
589 Log( EFalse, _L("CBavpController::IsVideoOrAudioCall() entered") ); |
|
590 |
|
591 // Pause if there is video call |
|
592 TInt callType; |
|
593 |
|
594 RProperty::Get( KPSUidCtsyCallInformation, |
|
595 KCTsyCallType, |
|
596 callType ); // Ignore errors |
|
597 |
|
598 return ( callType == EPSCTsyCallTypeH324Multimedia || |
|
599 callType == EPSCTsyCallTypeCSVoice ); |
|
600 } |
|
601 |
|
602 // ----------------------------------------------------------------------------- |
|
603 // CBavpController::BaseConstructL |
|
604 // Symbian 2nd phase constructor can leave. |
|
605 // ----------------------------------------------------------------------------- |
|
606 void CBavpController::BaseConstructL( TBavpMediaType aMediaType, |
|
607 const TDesC& aFileName ) |
|
608 { |
|
609 Log( EFalse, _L("CBavpController::BaseConstructL enter") ); |
|
610 |
|
611 // Create Clipinfo |
|
612 iClipInfo = new (ELeave) CBavpClipInfo(); |
|
613 iClipInfo->iMediaType = aMediaType; |
|
614 iClipInfo->iFileName = aFileName.AllocL(); |
|
615 iClipInfo->iUrl = aFileName.AllocL(); |
|
616 |
|
617 // Watch for incoming calls |
|
618 User::LeaveIfError( iIncomingCalls.Attach( KPSUidCtsyCallInformation, |
|
619 KCTsyCallState ) ); |
|
620 iIncomingCalls.Subscribe( iStatus ); |
|
621 |
|
622 // Set the AO active. so we will watch for incoming calls, see RunL() |
|
623 SetActive(); |
|
624 |
|
625 // Create Volume Handler to get the initial volume from settings CR, and |
|
626 // watch the CR for volume changes (browser or system) |
|
627 iBavpVolumeHandler = CBavpVolumeHandler::NewL( this ); |
|
628 |
|
629 // Create the timer for jumping (skipping) to new position |
|
630 iPositionUpdater = CPeriodic::NewL( CActive::EPriorityStandard ); |
|
631 |
|
632 //Get normal display screen rect - not including title pane and toolbar pane |
|
633 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, iNormalScreenRect ); |
|
634 // If the phone has side volume keys, create an observer for the hardware |
|
635 // volume key events |
|
636 if ( HAS_HW_VOLUME_KEYS ) |
|
637 { |
|
638 TRAP_IGNORE(iHwKeyEvents = CBavpHwKeyEvents::NewL( *this ) ); |
|
639 } |
|
640 |
|
641 // Add this BavpController instance to the array |
|
642 iBavpControllerArray.Append( this ); |
|
643 |
|
644 Log( EFalse, _L("CBavpController::BaseConstructL exited") ); |
|
645 } |
|
646 |
|
647 // ----------------------------------------------------------------------------- |
|
648 // CBavpControllerVideo::RunL |
|
649 // If incoming call arrives, handle the audio or video player content. |
|
650 // If incoming call ends, resume the audio or video player |
|
651 // ----------------------------------------------------------------------------- |
|
652 void CBavpController::RunL() |
|
653 { |
|
654 Log( EFalse, _L("CBavpController::RunL() entered") ); |
|
655 |
|
656 // Do we have an incoming audio or video call |
|
657 if ( IsVideoOrAudioCall() ) |
|
658 { |
|
659 // If we are playing content, pause if seekable or stop if streaming |
|
660 if ( iCurrentState == EBavpPlaying ) |
|
661 { |
|
662 // Set precall state, so we will resume playing the content, |
|
663 // after the call is done |
|
664 iPreCallState = EBavpPlaying; |
|
665 |
|
666 if ( iClipInfo->iSeekable ) |
|
667 { |
|
668 // Seekable content, pause, if there is an incoming call |
|
669 PauseL(); |
|
670 } |
|
671 else |
|
672 { |
|
673 HandleInComingCallL(); |
|
674 // Streaming content, stop, if there is an incoming call |
|
675 Stop(); |
|
676 } |
|
677 } |
|
678 // If we are seeking content, pause it (these states only for seekable) |
|
679 else if ( iCurrentState == EBavpFastForwarding || |
|
680 iCurrentState == EBavpRewinding ) |
|
681 { |
|
682 // Set precall state, so we will not resume playing the content, |
|
683 // after the call is done |
|
684 iPreCallState = EBavpPaused; |
|
685 |
|
686 // Stop the position updater |
|
687 if ( iPositionUpdater->IsActive() ) |
|
688 { |
|
689 iPositionUpdater->Cancel(); |
|
690 } |
|
691 // Seekable content, pause, if there is an incoming call |
|
692 PauseL(); |
|
693 } |
|
694 } |
|
695 else |
|
696 { |
|
697 // If the prev status was playing and has been paused by a phone call |
|
698 // or a video call. Try to get the player to the previous state and |
|
699 // invoke play function. |
|
700 if ( iPreCallState == EBavpPlaying ) |
|
701 { |
|
702 iPreCallState = EBavpNone; |
|
703 PlayL(); |
|
704 } |
|
705 } |
|
706 |
|
707 // Listen for the incoming call property changes |
|
708 iIncomingCalls.Subscribe( iStatus ); |
|
709 |
|
710 SetActive(); |
|
711 } |
|
712 |
|
713 // ----------------------------------------------------------------------------- |
|
714 // CBavpController::UpdateVolume |
|
715 // From MBavpVolumeObserver |
|
716 // Provides CBavpController with the media volume from the VolumeHandler |
|
717 // ----------------------------------------------------------------------------- |
|
718 void CBavpController::UpdateVolume( TInt aVolume ) |
|
719 { |
|
720 iCurrentVolume = aVolume; |
|
721 |
|
722 // Notify Player of volume change |
|
723 SetPlayerVolume( iCurrentVolume ); |
|
724 } |
|
725 |
|
726 // ----------------------------------------------------------------------------- |
|
727 // CBavpController::BavpHwKeyVolumeChange |
|
728 // Handles the change in the Volume that is needed as per the Hardware Volume |
|
729 // key events. Remember, all volume levels in CBavpController are CR based, |
|
730 // values 0(mute) - 10(max). Use KCRVolumeX values. |
|
731 // ----------------------------------------------------------------------------- |
|
732 void CBavpController::BavpHwKeyVolumeChange( TInt aVolumeChange ) |
|
733 { |
|
734 TInt newVolume = iCurrentVolume; |
|
735 newVolume += aVolumeChange; |
|
736 |
|
737 Log( EFalse, _L("CBavpController::BavpHwKeyVolumeChange newVolume="), newVolume ); |
|
738 |
|
739 // Ensure the volume is within range |
|
740 if ( newVolume < KCRVolume0 ) |
|
741 { |
|
742 newVolume = KCRVolume0; |
|
743 } |
|
744 else if ( newVolume > KCRVolumeMax ) |
|
745 { |
|
746 newVolume = KCRVolumeMax; |
|
747 } |
|
748 |
|
749 // Piggyback on this call to set the new volume from |
|
750 iBavpVolumeHandler->HandleNotifyInt( KBrowserMediaVolumeControl, newVolume ); |
|
751 } |
|
752 |
|
753 // ----------------------------------------------------------------------------- |
|
754 // CBavpController::IsAnotherControllerPlaying |
|
755 // Returns ETrue, on the first controller it finds in playing state |
|
756 // ----------------------------------------------------------------------------- |
|
757 TBool CBavpController::IsAnotherControllerPlaying() |
|
758 { |
|
759 if ( iBavpControllerArray.Count() > 1 ) |
|
760 { |
|
761 for ( TInt i( 0 ); i < iBavpControllerArray.Count(); i++ ) |
|
762 { |
|
763 CBavpController* bavpController = iBavpControllerArray[ i ]; |
|
764 if ( ( this != bavpController ) && |
|
765 ( bavpController->iCurrentState == EBavpPlaying ) ) |
|
766 { |
|
767 return ETrue; |
|
768 } |
|
769 } |
|
770 } |
|
771 return EFalse; |
|
772 } |
|
773 |
|
774 // ----------------------------------------------------------------------------- |
|
775 // CBavpController::PauseOtherControllersPlaying |
|
776 // This will attempt to pause all of the other controllers (expect this one), if |
|
777 // the media can't be paused (ie live stream), it will be stopped. |
|
778 // ----------------------------------------------------------------------------- |
|
779 void CBavpController::PauseOtherControllersPlaying() |
|
780 { |
|
781 if ( iBavpControllerArray.Count() > 1 ) |
|
782 { |
|
783 for ( TInt i( 0 ); i < iBavpControllerArray.Count(); i++ ) |
|
784 { |
|
785 CBavpController* bavpController = iBavpControllerArray[ i ]; |
|
786 if ( this != bavpController ) |
|
787 { |
|
788 TRAP_IGNORE( bavpController->PauseL() ); |
|
789 iBavpView->UpdateView(); |
|
790 } |
|
791 } |
|
792 } |
|
793 } |
|
794 |
|
795 // -------------------------------------------------------------------------- |
|
796 // CBavpControllerVideo::HandleMultiInstanceError |
|
797 // Handle error codes. |
|
798 // NOTES: |
|
799 // MMF errors start at -12000, see /epoc32/include/mmf/common/MMFErrors.h |
|
800 // MMF also returns -1 (KErrNotFound) and few other system-wide errors |
|
801 // ----------------------------------------------------------------------------- |
|
802 void CBavpController::HandleMultiInstanceError() |
|
803 { |
|
804 // Handle multiple media object case |
|
805 if ( iBavpControllerArray.Count() > 1 && IsAnotherControllerPlaying() ) |
|
806 { |
|
807 if ( iLastCommand == EBavpCmdUnknown ) |
|
808 { |
|
809 // Another controller is playing, and this controller was |
|
810 // initializing, so our error is because we can only play one |
|
811 // media object at a time. Stop this media and let |
|
812 // the first one initialized continue to play. |
|
813 //TRAP_IGNORE( PauseL() ); |
|
814 Stop(); |
|
815 iBavpView->UpdateView(); |
|
816 } |
|
817 else if ( iLastCommand == EBavpCmdPlay ) |
|
818 { |
|
819 // Another controller is playing, and the user wants to play |
|
820 // another media object. Pause (or stop) all of the others and |
|
821 // play this one. |
|
822 PauseOtherControllersPlaying(); |
|
823 TRAP_IGNORE( PlayL() ); |
|
824 } |
|
825 } |
|
826 } |
|
827 |
|
828 // ----------------------------------------------------------------------------- |
|
829 // CBavpController::SetOriginalFileName |
|
830 // Sets the file name. Used for scripting functionality |
|
831 // ----------------------------------------------------------------------------- |
|
832 void CBavpController::SetOriginalFileName( const TDesC* originalFile ) |
|
833 { |
|
834 if ( originalFile ) |
|
835 { |
|
836 iOriginalFileName = originalFile->Alloc(); |
|
837 } |
|
838 } |
|
839 |
|
840 // ----------------------------------------------------------------------------- |
|
841 // CBavpController::SetMimeType |
|
842 // Sets the mime type. Used for scripting functionality |
|
843 // ----------------------------------------------------------------------------- |
|
844 void CBavpController::SetMimeType( const TDesC8* mimetype ) |
|
845 { |
|
846 if ( mimetype ) |
|
847 { |
|
848 iMimeType = mimetype->Alloc(); |
|
849 } |
|
850 } |
|
851 |
|
852 // ----------------------------------------------------------------------------- |
|
853 // CBavpController::BavpHwKeyCommand |
|
854 // Handles transport commands (play, pause, ...) from dedicated hardware keys. |
|
855 // ----------------------------------------------------------------------------- |
|
856 /* |
|
857 void CBavpController::BavpHwKeyCommand( TBavpCommandIds aCommand ) |
|
858 { |
|
859 // Do some basic checks for the hardware keys |
|
860 if ( aCommand == EBavpCmdPlay && iCurrentState == EBavpPlaying ) |
|
861 { |
|
862 // We recieved a play command while playing, therefore make it pause |
|
863 aCommand = EBavpCmdPause; |
|
864 } |
|
865 |
|
866 HandleCommandL( aCommand ); |
|
867 } |
|
868 */ |
|
869 // End of File |