zeroconf/zeroconfsharing/musicprovider.cpp
changeset 21 ff5174af067c
equal deleted inserted replaced
14:da856f45b798 21:ff5174af067c
       
     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: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include "musicprovider.h"
       
    19 #include <mpxplaybackframeworkdefs.h>
       
    20 #include <mpxplaybackmessage.h>
       
    21 #include <mpxmedia.h>
       
    22 #include <mpxmediageneraldefs.h>
       
    23 #include <mpxmediamusicdefs.h>
       
    24 #include <mpxmessagegeneraldefs.h>
       
    25 #include <mpxplaybackmessagedefs.h>
       
    26 #include "zeroconfsharing.h"
       
    27 //#include "zeroconfconsole.h"
       
    28 
       
    29 const TInt KMax =1024;
       
    30 
       
    31 CMusicProvider* CMusicProvider::NewL(MNowPlayObserver* aOb)
       
    32     {
       
    33     CMusicProvider* me = new(ELeave) CMusicProvider(aOb);
       
    34     CleanupStack::PushL(me);
       
    35     me->ConstructL();
       
    36     CleanupStack::Pop(me);
       
    37     return me;
       
    38     }
       
    39 
       
    40 void CMusicProvider::ConstructL()
       
    41     {
       
    42     iPlaybackUtility = MMPXPlaybackUtility::NewL(KPbModeActivePlayer, this);
       
    43     }
       
    44 
       
    45 CMusicProvider::~CMusicProvider()
       
    46     {
       
    47     if ( iPlaybackUtility )
       
    48         {
       
    49         iPlaybackUtility->Close();
       
    50         }
       
    51     iPreviousTrack.Close();
       
    52  //   iBuf.Close();
       
    53     }
       
    54     
       
    55 CMusicProvider::CMusicProvider(MNowPlayObserver* aOb):iPlaybackUtility(NULL)
       
    56     {
       
    57     iObserver = aOb;
       
    58 //    iBuf.CreateL(KMax);
       
    59     }
       
    60     
       
    61 
       
    62 void CMusicProvider::HandlePropertyL(TMPXPlaybackProperty /*aProperty*/,
       
    63                              TInt /*aValue*/, 
       
    64                              TInt /*aError*/)
       
    65     {
       
    66     // do nothing
       
    67     }
       
    68 
       
    69 void CMusicProvider::HandleSubPlayerNamesL(TUid /*aPlayer*/, 
       
    70                                    const MDesCArray* /*aSubPlayers*/,
       
    71                                    TBool /*aComplete*/,
       
    72                                    TInt /*aError*/
       
    73                                    )
       
    74     {
       
    75     // do nothing
       
    76     }
       
    77 
       
    78 
       
    79 void CMusicProvider::HandlePlaybackMessage( CMPXMessage* aMessage, TInt aError )
       
    80     {
       
    81     if ( aError == KErrNone && aMessage )
       
    82         {
       
    83         TRAP_IGNORE( DoHandlePlaybackMessageL( *aMessage ) );
       
    84         }
       
    85     }
       
    86 
       
    87 void CMusicProvider::DoHandlePlaybackMessageL( const CMPXMessage& aMessage )
       
    88     {
       
    89     TMPXMessageId id( aMessage.ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) );
       
    90     if ( KMPXMessageGeneral == id )
       
    91         {
       
    92         TInt event( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) );
       
    93         switch ( event )
       
    94                {
       
    95                case TMPXPlaybackMessage::EMediaChanged:
       
    96                  {
       
    97                  RequestMediaL();
       
    98                  break;
       
    99                  }
       
   100                default:
       
   101                  {
       
   102                  break;
       
   103                  }
       
   104                }
       
   105         }
       
   106     }
       
   107 
       
   108 void CMusicProvider::RequestMediaL()
       
   109     {   
       
   110     MMPXSource* s = iPlaybackUtility->Source();
       
   111     if ( s )
       
   112         {
       
   113         RArray<TMPXAttribute> attrs;
       
   114         CleanupClosePushL(attrs);
       
   115         attrs.Append( KMPXMediaGeneralTitle );
       
   116         s->MediaL( attrs.Array(), *this );
       
   117         CleanupStack::PopAndDestroy(&attrs);
       
   118         }
       
   119     }
       
   120 
       
   121 void CMusicProvider::HandleMediaL(const CMPXMedia& aProperties,
       
   122                           TInt aError)
       
   123     {
       
   124     if ( KErrNone == aError )
       
   125         {
       
   126         if(aProperties.IsSupported(KMPXMediaGeneralTitle))
       
   127             {
       
   128             RBuf title;
       
   129             title.CreateL(aProperties.ValueText(KMPXMediaGeneralTitle));
       
   130 
       
   131             if(title.Compare(iPreviousTrack)!=0)
       
   132                 {
       
   133                 iPreviousTrack.Close();
       
   134                 iPreviousTrack.CreateL(title);
       
   135                 iObserver->NowPlaying(title);   
       
   136                 }
       
   137             
       
   138             title.Close();
       
   139             }
       
   140         }
       
   141     }