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