javauis/mmapi_qt/baseline/src/cmmadurationupdater.cpp
changeset 23 98ccebc37403
equal deleted inserted replaced
21:2a9601315dfc 23:98ccebc37403
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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:  Send update duration event if needed when player state changes
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDE FILES
       
    20 #include <logger.h>
       
    21 
       
    22 #include "cmmadurationupdater.h"
       
    23 
       
    24 CMMADurationUpdater* CMMADurationUpdater::NewL(CMMAPlayer& aPlayer)
       
    25 {
       
    26     CMMADurationUpdater* self = new(ELeave) CMMADurationUpdater(aPlayer);
       
    27     CleanupStack::PushL(self);
       
    28     self->ConstructL();
       
    29     CleanupStack::Pop(self);
       
    30     return self;
       
    31 }
       
    32 
       
    33 CMMADurationUpdater::CMMADurationUpdater(CMMAPlayer& aPlayer)
       
    34         : iPlayer(aPlayer), iDuration(KErrNotFound), iSecondStart(EFalse)
       
    35 {
       
    36 }
       
    37 
       
    38 void CMMADurationUpdater::ConstructL()
       
    39 {
       
    40     iPlayer.AddStateListenerL(this);
       
    41 }
       
    42 
       
    43 CMMADurationUpdater::~CMMADurationUpdater()
       
    44 {
       
    45     iPlayer.RemoveStateListener(this);
       
    46 }
       
    47 
       
    48 void CMMADurationUpdater::StateChanged(TInt aState)
       
    49 {
       
    50     TInt64 duration = 0;
       
    51     iPlayer.GetDuration(&duration);
       
    52 
       
    53     if ((duration >= KErrNotFound) && (duration != iDuration))
       
    54     {
       
    55         // Send DURATION_UPDATED
       
    56         iDuration = duration;
       
    57         iPlayer.PostLongEvent(CMMAPlayerEvent::EDurationUpdated, iDuration);
       
    58     }
       
    59     else if (duration == KErrNotFound && aState == CMMAPlayer::EStarted && !iSecondStart)
       
    60     {
       
    61         // for medias whose duration is unknown (e.g. streaming audio amr)
       
    62         // must post EDurationUpdated event with duration -1 in first start
       
    63         iPlayer.PostLongEvent(CMMAPlayerEvent::EDurationUpdated, iDuration);
       
    64         iSecondStart = ETrue;
       
    65     }
       
    66 
       
    67     if (aState == CMMAPlayer::ERealized)
       
    68     {
       
    69         iSecondStart = EFalse;
       
    70     }
       
    71 }
       
    72 
       
    73 //  END OF FILE