mpengine/src/mpmpxembeddedplaybackhelper.cpp
changeset 61 3cd404d31176
equal deleted inserted replaced
58:ed94e1e8390e 61:3cd404d31176
       
     1 /*
       
     2 * Copyright (c) 2009 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: Embedded playback helper.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <mpxplaybackutility.h>
       
    19 #include <mpxcollectionutility.h>
       
    20 #include <mpxcollectionmessage.h>
       
    21 #include <mpxmessagegeneraldefs.h>
       
    22 #include <mpxcollectionplugin.hrh>
       
    23 #include <mpxcollectionplaylist.h>
       
    24 #include <mpxcollectionuihelper.h>
       
    25 #include <mpxcollectionhelperfactory.h>
       
    26 
       
    27 #include "mpmpxembeddedplaybackhelper.h"
       
    28 #include "mptrace.h"
       
    29 
       
    30 
       
    31 /*!
       
    32     \class CMpMpxEmbeddedPlaybackHelper
       
    33     \brief Helper class to play isolated media, 
       
    34 
       
    35     This class is used by mpmpxplaybackframeworkwrapper_p to play isolated content specified by an uri,
       
    36     when MusicPlayer is launched in embedded mode.
       
    37 */
       
    38 
       
    39 /*!
       
    40  \internal
       
    41  Two-phased constructor.
       
    42  */
       
    43 CMpMpxEmbeddedPlaybackHelper* CMpMpxEmbeddedPlaybackHelper::NewL( 
       
    44     TUid aHostUid,
       
    45     MMPXPlaybackUtility* aPlaybackUtility,
       
    46     MMpMpxEmbeddedPlaybackHelperObserver* aObserver )
       
    47 {
       
    48     CMpMpxEmbeddedPlaybackHelper* self =
       
    49             new ( ELeave ) CMpMpxEmbeddedPlaybackHelper( aHostUid, aPlaybackUtility, aObserver );
       
    50     CleanupStack::PushL( self );
       
    51     self->ConstructL();
       
    52     CleanupStack::Pop( self );
       
    53     return self;
       
    54 }
       
    55 
       
    56 /*!
       
    57  \internal
       
    58  Destructor
       
    59  */
       
    60 CMpMpxEmbeddedPlaybackHelper::~CMpMpxEmbeddedPlaybackHelper()
       
    61 {
       
    62     TX_ENTRY
       
    63     if ( iCollectionUtility ) {
       
    64         iCollectionUtility->Collection().CancelRequest();
       
    65         iCollectionUtility->Close();
       
    66     }
       
    67     if ( iCollectionUiHelper ) {
       
    68         iCollectionUiHelper->Close();
       
    69     }
       
    70     TX_EXIT
       
    71 }
       
    72 
       
    73 /*!
       
    74  \internal
       
    75   */
       
    76 void CMpMpxEmbeddedPlaybackHelper::playL( const TDesC& aFilename )
       
    77 {
       
    78     TX_LOG
       
    79     iCollectionUiHelper->OpenL( iHostUid, aFilename, this, EMPXCollectionPluginMusic );
       
    80 }
       
    81 
       
    82 /*!
       
    83  \internal
       
    84  */
       
    85 void CMpMpxEmbeddedPlaybackHelper::HandleOpenL( 
       
    86     const CMPXMedia& aEntries,
       
    87     TInt aIndex,
       
    88     TBool aComplete,
       
    89     TInt aError )
       
    90 {
       
    91     Q_UNUSED( aEntries );
       
    92     Q_UNUSED( aIndex );
       
    93     Q_UNUSED( aComplete );
       
    94     Q_UNUSED( aError );
       
    95 }
       
    96 
       
    97 /*!
       
    98  \internal
       
    99  */
       
   100 void CMpMpxEmbeddedPlaybackHelper::HandleOpenL( 
       
   101     const CMPXCollectionPlaylist& aPlaylist,
       
   102     TInt aError )
       
   103 {
       
   104     TX_ENTRY_ARGS( "aError=" << aError );
       
   105     if ( aError == KErrNone ) {
       
   106         iPlaybackUtility->InitL( aPlaylist, ETrue );
       
   107     }
       
   108     else {
       
   109         iObserver->HandleEmbeddedPlaybackError( aError );
       
   110     }
       
   111     TX_EXIT
       
   112 }
       
   113 
       
   114 /*!
       
   115  \internal
       
   116  */
       
   117 void CMpMpxEmbeddedPlaybackHelper::HandleCollectionMessage( 
       
   118     CMPXMessage* aMsg,
       
   119     TInt aErr )
       
   120 {
       
   121     TX_ENTRY_ARGS( "aErr=" << aErr );
       
   122     TInt error = aErr;
       
   123     if ( error == KErrNone && aMsg ) {
       
   124         TRAP( error, DoHandleCollectionMessageL( *aMsg ) );
       
   125     }
       
   126 
       
   127     if ( error != KErrNone ) {
       
   128         iObserver->HandleEmbeddedPlaybackError( error );
       
   129     }
       
   130     TX_EXIT
       
   131 }
       
   132 
       
   133 /*!
       
   134  \internal
       
   135  */
       
   136 void CMpMpxEmbeddedPlaybackHelper::HandleCollectionMediaL( 
       
   137     const CMPXMedia& aMedia,
       
   138     TInt aError )
       
   139 {
       
   140     Q_UNUSED( aMedia );
       
   141     Q_UNUSED( aError );
       
   142 }
       
   143 
       
   144 /*!
       
   145  \internal
       
   146  */
       
   147 void CMpMpxEmbeddedPlaybackHelper::HandleEmbeddedOpenL( 
       
   148     TInt aErr,
       
   149     TMPXGeneralCategory aCategory )
       
   150 {
       
   151     TX_ENTRY_ARGS( "aErr=" << aErr );
       
   152     Q_UNUSED( aCategory );
       
   153     if ( aErr != KErrNone ) {
       
   154         iObserver->HandleEmbeddedPlaybackError( aErr );
       
   155     }
       
   156 }
       
   157 
       
   158 /*!
       
   159  \internal
       
   160  c++ Contructor
       
   161  */
       
   162 CMpMpxEmbeddedPlaybackHelper::CMpMpxEmbeddedPlaybackHelper(
       
   163         TUid aHostUid,
       
   164         MMPXPlaybackUtility* aPlaybackUtility,
       
   165         MMpMpxEmbeddedPlaybackHelperObserver* aObserver )
       
   166     : iPlaybackUtility( aPlaybackUtility ),
       
   167       iObserver( aObserver ),
       
   168       iHostUid( aHostUid )
       
   169 {
       
   170 }
       
   171 
       
   172 /*!
       
   173  \internal
       
   174  Leaving constructor
       
   175  */
       
   176 void CMpMpxEmbeddedPlaybackHelper::ConstructL()
       
   177 {
       
   178     iCollectionUtility = MMPXCollectionUtility::NewL( this, iHostUid );
       
   179     iCollectionUiHelper = CMPXCollectionHelperFactory::NewCollectionUiHelperL( iHostUid );
       
   180 }
       
   181 
       
   182 /*!
       
   183  \internal
       
   184  */
       
   185 void CMpMpxEmbeddedPlaybackHelper::DoHandleCollectionMessageL( 
       
   186     const CMPXMessage& aMsg )
       
   187 {
       
   188     TX_ENTRY
       
   189     TMPXMessageId id( aMsg.ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) );
       
   190     if ( KMPXMessageGeneral == id ) {
       
   191         TInt event( aMsg.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) );
       
   192         TInt type( aMsg.ValueTObjectL<TInt>( KMPXMessageGeneralType ) );
       
   193         TInt data( aMsg.ValueTObjectL<TInt>( KMPXMessageGeneralData ) );
       
   194         TX_LOG_ARGS( "event=" << event << ", type=" << type << ", data=" << data );
       
   195 
       
   196          if ( event == TMPXCollectionMessage::EPathChanged &&
       
   197               type == EMcPathChangedByOpen &&
       
   198               data == EMcItemOpened ) {
       
   199             // This will result in HandleOpenL with CMPXCollectionPlaylist
       
   200             iCollectionUtility->Collection().OpenL();
       
   201         }
       
   202     }
       
   203     TX_EXIT
       
   204 }
       
   205