javauis/amms_qt/module/src/cammsplayerstatelistener.cpp
branchRCL_3
changeset 24 0fd27995241b
equal deleted inserted replaced
20:f9bb0fca356a 24:0fd27995241b
       
     1 /*
       
     2 * Copyright (c) 2005 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 for player state listener.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "cammsplayerstatelistener.h"
       
    21 #include "cammscontrolgroup.h"
       
    22 #include <cmmaplayer.h>
       
    23 #include <cmmaplayerevent.h>
       
    24 
       
    25 // CONSTANTS
       
    26 const TInt KErrorMessageSize = 32;
       
    27 _LIT(KErrDefaultError, "AMMS error: %d");
       
    28 
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CAMMSPlayerStateListener::NewLC
       
    34 // Two-phased constructor.
       
    35 // (other items were commented in a header).
       
    36 // -----------------------------------------------------------------------------
       
    37 CAMMSPlayerStateListener* CAMMSPlayerStateListener::NewLC(
       
    38     CMMAPlayer* aPlayer,
       
    39     CAMMSControlGroup* aControlGroup)
       
    40 {
       
    41     CAMMSPlayerStateListener* self =
       
    42         new(ELeave) CAMMSPlayerStateListener(aPlayer,
       
    43                                              aControlGroup);
       
    44     CleanupStack::PushL(self);
       
    45 
       
    46     self->ConstructL();
       
    47 
       
    48     return self;
       
    49 }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CAMMSPlayerStateListener::~CAMMSPlayerStateListener
       
    53 // Destructor.
       
    54 // (other items were commented in a header).
       
    55 // -----------------------------------------------------------------------------
       
    56 CAMMSPlayerStateListener::~CAMMSPlayerStateListener()
       
    57 {
       
    58     if (iPlayer)
       
    59     {
       
    60         iPlayer->RemoveStateListener(this);
       
    61     }
       
    62 }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CAMMSPlayerStateListener::ConstructL
       
    66 // 2nd phase constructor.
       
    67 // (other items were commented in a header).
       
    68 // -----------------------------------------------------------------------------
       
    69 void CAMMSPlayerStateListener::ConstructL()
       
    70 {
       
    71     __ASSERT_DEBUG(iPlayer && iControlGroup, User::Invariant());
       
    72 
       
    73     iPlayer->AddStateListenerL(this);
       
    74 }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CAMMSPlayerStateListener::CAMMSPlayerStateListener
       
    78 // C++ constructor.
       
    79 // (other items were commented in a header).
       
    80 // -----------------------------------------------------------------------------
       
    81 CAMMSPlayerStateListener::CAMMSPlayerStateListener(
       
    82     CMMAPlayer* aPlayer,
       
    83     CAMMSControlGroup* aControlGroup)
       
    84         : iPlayer(aPlayer),
       
    85         iControlGroup(aControlGroup)
       
    86 {
       
    87 }
       
    88 
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CAMMSPlayerStateListener::Player
       
    92 // Returns the player listened by this listener.
       
    93 // (other items were commented in a header).
       
    94 // -----------------------------------------------------------------------------
       
    95 CMMAPlayer* CAMMSPlayerStateListener::Player()
       
    96 {
       
    97     return iPlayer;
       
    98 }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CAMMSPlayerStateListener::StateChanged
       
   102 // Called when player state is changed.
       
   103 // (other items were commented in a header).
       
   104 // -----------------------------------------------------------------------------
       
   105 void CAMMSPlayerStateListener::StateChanged(TInt aState)
       
   106 {
       
   107     TRAPD(err, iControlGroup->PlayerStateChangedL(iPlayer, aState));
       
   108 
       
   109     if (err != KErrNone)
       
   110     {
       
   111         TBuf<KErrorMessageSize> errorMessage;
       
   112         errorMessage.Format(KErrDefaultError, err);
       
   113         iPlayer->PostStringEvent(CMMAPlayerEvent::EError, errorMessage);
       
   114     }
       
   115 }
       
   116 
       
   117 //  End of File