1 /* |
|
2 * Copyright (c) 2002-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: This class implements RateControl for HTTP stream audio player. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <logger.h> |
|
21 #include <e32base.h> |
|
22 |
|
23 #include "cmmaaudiostreamratecontrol.h" |
|
24 |
|
25 namespace |
|
26 { |
|
27 const TInt KErrorMessageSize = 32; |
|
28 _LIT(KErrDefaultError, "Symbian OS Error: %d"); |
|
29 } |
|
30 |
|
31 CMMAAudioStreamRateControl* CMMAAudioStreamRateControl::NewL(CMMAAudioStreamPlayer* aPlayer) |
|
32 { |
|
33 CMMAAudioStreamRateControl* self = new(ELeave) CMMAAudioStreamRateControl(aPlayer); |
|
34 CleanupStack::PushL(self); |
|
35 self->ConstructL(); |
|
36 CleanupStack::Pop(self); |
|
37 return self; |
|
38 } |
|
39 |
|
40 CMMAAudioStreamRateControl::~CMMAAudioStreamRateControl() |
|
41 { |
|
42 LOG( EJavaMMAPI, EInfo, "MMA:CMMAAudioStreamRateControl::~CMMAAudioStreamRateControl"); |
|
43 if (iPlayer) |
|
44 { |
|
45 iPlayer->RemoveStateListener(this); |
|
46 } |
|
47 } |
|
48 |
|
49 CMMAAudioStreamRateControl::CMMAAudioStreamRateControl(CMMAAudioStreamPlayer* aPlayer) : |
|
50 iPlayer(aPlayer), iCurrentRate(KMMADefaultRate) |
|
51 { |
|
52 LOG( EJavaMMAPI, EInfo, "MMA:CMMAAudioStreamRateControl::CMMAAudioStreamRateControl"); |
|
53 } |
|
54 |
|
55 void CMMAAudioStreamRateControl::ConstructL() |
|
56 { |
|
57 iPlayer->AddStateListenerL(this); |
|
58 } |
|
59 |
|
60 void CMMAAudioStreamRateControl::StateChanged(TInt aState) |
|
61 { |
|
62 LOG( EJavaMMAPI, EInfo, "MMA:CMMAAudioStreamRateControl::StateChanged"); |
|
63 if (aState == CMMAPlayer::EStarted && iCurrentRate == KMMAMinRate) |
|
64 { |
|
65 // do not post event to Java or change player state |
|
66 TInt err = iPlayer->Pause(); |
|
67 if (err != KErrNone) |
|
68 { |
|
69 ELOG1( EJavaMMAPI, "CMMAAudioStreamRateControl::StateChanged: Pause error %d", err); |
|
70 TBuf<KErrorMessageSize> errorMessage; |
|
71 errorMessage.Format(KErrDefaultError, err); |
|
72 iPlayer->PostStringEvent(CMMAPlayerEvent::EError, errorMessage); |
|
73 } |
|
74 } |
|
75 } |
|
76 |
|
77 TInt CMMAAudioStreamRateControl::SetRateL(TInt aRate) |
|
78 { |
|
79 LOG( EJavaMMAPI, EInfo, "MMA:CMMAAudioStreamRateControl::SetRateL"); |
|
80 TInt newRate; |
|
81 if (aRate <= KMMAMinRate) |
|
82 { |
|
83 newRate = KMMAMinRate; |
|
84 } |
|
85 else |
|
86 { |
|
87 newRate = KMMADefaultRate; |
|
88 } |
|
89 |
|
90 if ((iPlayer->State() == CMMAPlayer::EStarted) && |
|
91 (newRate != iCurrentRate)) |
|
92 { |
|
93 if (newRate == KMMAMinRate) |
|
94 { |
|
95 // do not post event to Java or change player state |
|
96 User::LeaveIfError(iPlayer->Pause()); |
|
97 } |
|
98 else |
|
99 { |
|
100 // do not post event to Java or change player state |
|
101 iPlayer->StartL(); |
|
102 } |
|
103 } |
|
104 iCurrentRate = newRate; |
|
105 return iCurrentRate; |
|
106 } |
|
107 |
|
108 TInt CMMAAudioStreamRateControl::RateL() |
|
109 { |
|
110 return iCurrentRate; |
|
111 } |
|
112 |
|
113 |
|
114 // END OF FILE |
|