|
1 /* |
|
2 * Copyright (c) 2005-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 is a tuner player |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CAMMSTunerPlayer.h" |
|
22 #include "CAMMSTunerControl.h" |
|
23 |
|
24 #include <tuner.h> |
|
25 #include <logger.h> |
|
26 |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS =============================== |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CAMMSTunerPlayer::CAMMSTunerPlayer |
|
32 // C++ default constructor can NOT contain any code, that |
|
33 // might leave. |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CAMMSTunerPlayer::CAMMSTunerPlayer() |
|
37 { |
|
38 } |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CAMMSTunerPlayer::NewL |
|
42 // Two-phased constructor. |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 CAMMSTunerPlayer* CAMMSTunerPlayer::NewL(CAMMSTunerControl* aTunerControl) |
|
46 { |
|
47 CAMMSTunerPlayer* self = new(ELeave) CAMMSTunerPlayer; |
|
48 |
|
49 CleanupStack::PushL(self); |
|
50 self->ConstructL(aTunerControl); |
|
51 CleanupStack::Pop(); |
|
52 |
|
53 return self; |
|
54 } |
|
55 |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CAMMSTunerPlayer::ConstructL |
|
59 // Symbian 2nd phase constructor can leave. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 void CAMMSTunerPlayer::ConstructL(CAMMSTunerControl* aTunerControl) |
|
63 { |
|
64 LOG( EJavaAMMS, EInfo, "CAMMSTunerPlayer::ConstructL +"); |
|
65 iTunerControl = aTunerControl; |
|
66 iTunerPlayerUtility = iTunerControl->TunerUtility()->TunerPlayerUtilityL(*this); |
|
67 iActiveSchedulerWait = new(ELeave) CActiveSchedulerWait(); |
|
68 iIsInitialized = EFalse; |
|
69 |
|
70 LOG( EJavaAMMS, EInfo, "CAMMSTunerPlayer::ConstructL -"); |
|
71 } |
|
72 |
|
73 // Destructor |
|
74 CAMMSTunerPlayer::~CAMMSTunerPlayer() |
|
75 { |
|
76 LOG( EJavaAMMS, EInfo, "CAMMSTunerPlayer::~CAMMSTunerPlayer +"); |
|
77 delete iTunerPlayerUtility; |
|
78 delete iActiveSchedulerWait; |
|
79 LOG( EJavaAMMS, EInfo, "CAMMSTunerPlayer::~CAMMSTunerPlayer -"); |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CAMMSTunerPlayer::PrefetchL() |
|
84 // ?implementation_description |
|
85 // (other items were commented in a header). |
|
86 // ----------------------------------------------------------------------------- |
|
87 void CAMMSTunerPlayer::PrefetchL() |
|
88 { |
|
89 LOG( EJavaAMMS, EInfo, "CAMMSTunerPlayer::PrefetchL +"); |
|
90 //this must be called before play, stop, mute etc... |
|
91 iTunerPlayerUtility->InitializeL(EMdaPriorityNormal, |
|
92 EMdaPriorityPreferenceTimeAndQuality); |
|
93 if (!iActiveSchedulerWait->IsStarted()) |
|
94 { |
|
95 iActiveSchedulerWait->Start(); // CSI: 10 Active object state already checked. # |
|
96 } |
|
97 |
|
98 LOG( EJavaAMMS, EInfo, "CAMMSTunerPlayer::PrefetchL -"); |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CAMMSTunerPlayer::StartL() |
|
103 // ?implementation_description |
|
104 // (other items were commented in a header). |
|
105 // ----------------------------------------------------------------------------- |
|
106 void CAMMSTunerPlayer::StartL() |
|
107 { |
|
108 LOG( EJavaAMMS, EInfo, "CAMMSTunerPlayer::StartL +"); |
|
109 if (iIsInitialized) |
|
110 { |
|
111 // inform java side |
|
112 ChangeState(EStarted); |
|
113 iTunerPlayerUtility->Play(); |
|
114 // set time when started |
|
115 iStartTime = CurrentTime(); |
|
116 |
|
117 TInt64 time; |
|
118 GetMediaTime(&time); |
|
119 PostLongEvent(CMMAPlayerEvent::EStarted, time); |
|
120 } |
|
121 else |
|
122 { |
|
123 User::Leave(KErrNotReady); |
|
124 } |
|
125 LOG( EJavaAMMS, EInfo, "CAMMSTunerPlayer::StartL -"); |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CAMMSTunerPlayer::StopL() |
|
130 // ?implementation_description |
|
131 // (other items were commented in a header). |
|
132 // ----------------------------------------------------------------------------- |
|
133 void CAMMSTunerPlayer::StopL(TBool /*aPostEvent*/) |
|
134 { |
|
135 LOG( EJavaAMMS, EInfo, "CAMMSTunerPlayer::StopL +"); |
|
136 if (iIsInitialized) |
|
137 { |
|
138 ChangeState(EPrefetched); |
|
139 |
|
140 iTunerPlayerUtility->Stop(); |
|
141 |
|
142 TInt64 time; |
|
143 GetMediaTime(&time); |
|
144 iStartTime = KErrNotFound; |
|
145 PostLongEvent(CMMAPlayerEvent::EStopped, time); |
|
146 } |
|
147 else |
|
148 { |
|
149 User::Leave(KErrNotReady); |
|
150 } |
|
151 |
|
152 LOG( EJavaAMMS, EInfo, "CAMMSTunerPlayer::StopL -"); |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // CAMMSTunerPlayer::DeallocateL() |
|
157 // ?implementation_description |
|
158 // (other items were commented in a header). |
|
159 // ----------------------------------------------------------------------------- |
|
160 void CAMMSTunerPlayer::DeallocateL() |
|
161 { |
|
162 |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CAMMSTunerPlayer::GetMediaTime() |
|
167 // ?implementation_description |
|
168 // (other items were commented in a header). |
|
169 // ----------------------------------------------------------------------------- |
|
170 void CAMMSTunerPlayer::GetMediaTime(TInt64* aMediaTime) |
|
171 { |
|
172 if (iState == EStarted) |
|
173 { |
|
174 // add play time to media time |
|
175 iMediaTime += CurrentTime() - iStartTime; |
|
176 // set new start time |
|
177 iStartTime = CurrentTime(); |
|
178 } |
|
179 |
|
180 // set value to parameter |
|
181 (*aMediaTime) = iMediaTime; |
|
182 } |
|
183 |
|
184 // ----------------------------------------------------------------------------- |
|
185 // CAMMSTunerPlayer::MTapoInitializeComplete |
|
186 // Initialize complete event. This event is asynchronous and is received after |
|
187 // a call to CMMTunerAudioPlayerUtility::InitializeL(). |
|
188 // ----------------------------------------------------------------------------- |
|
189 void CAMMSTunerPlayer::MTapoInitializeComplete(TInt aError) |
|
190 { |
|
191 ELOG1( EJavaAMMS, "CAMMSTunerPlayer::MTapoInitializeComplete aError = %d", aError); |
|
192 if (iActiveSchedulerWait->IsStarted()) |
|
193 { |
|
194 LOG( EJavaAMMS, EInfo, "CAMMSTunerControl::MToTuneComplete AsyncStop"); |
|
195 iActiveSchedulerWait->AsyncStop(); |
|
196 } |
|
197 if (aError == KErrNone) |
|
198 { |
|
199 iIsInitialized = ETrue; |
|
200 ChangeState(EPrefetched); |
|
201 // Inform Java side. |
|
202 PostActionCompleted(KErrNone); |
|
203 } |
|
204 else |
|
205 { |
|
206 ELOG1( EJavaAMMS, "CAMMSTunerPlayer::MTapoInitializeComplete aError = %d", aError); |
|
207 PostLongEvent(CMMAPlayerEvent::EError, aError); |
|
208 //User::Leave( aError ); |
|
209 } |
|
210 } |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CAMMSTunerPlayer::MTapoPlayEvent |
|
214 // Passes an asychronous event to the tuner client. |
|
215 // (other items were commented in a header). |
|
216 // ----------------------------------------------------------------------------- |
|
217 void CAMMSTunerPlayer::MTapoPlayEvent( |
|
218 MMMTunerAudioPlayerObserver::TEventType /*aEvent*/, |
|
219 TInt /*aError*/, TAny* /*aAdditionalInfo*/) |
|
220 { |
|
221 LOG( EJavaAMMS, EInfo, "CAMMSTunerPlayer::MTapoPlayEvent +"); |
|
222 } |
|
223 |
|
224 // ----------------------------------------------------------------------------- |
|
225 // CAMMSTunerPlayer::CurrentTime() |
|
226 // ?implementation_description |
|
227 // (other items were commented in a header). |
|
228 // ----------------------------------------------------------------------------- |
|
229 TInt64 CAMMSTunerPlayer::CurrentTime() |
|
230 { |
|
231 TTime time; |
|
232 time.HomeTime(); |
|
233 return time.Int64(); |
|
234 } |
|
235 |
|
236 // End of File |