author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 21:06:50 +0300 | |
branch | RCL_3 |
changeset 71 | d5e927d5853b |
parent 66 | 2455ef1f5bbc |
permissions | -rw-r--r-- |
66 | 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 is base class for all players. |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
#ifndef CMMAPLAYER_H |
|
20 |
#define CMMAPLAYER_H |
|
21 |
||
22 |
// INCLUDES |
|
23 |
#include "cmmacontrol.h" |
|
24 |
#include "cmmasourcestream.h" |
|
25 |
#include "cmmaplayerevent.h" |
|
26 |
#include "mmmasourcestreamlistener.h" |
|
27 |
#include "mmmaplayerstatelistener.h" |
|
28 |
#include "mmmacallstateobserver.h" |
|
29 |
||
30 |
// FORWARD DECLARATIONS |
|
31 |
class CMMADurationUpdater; |
|
32 |
class CMMACallStateMonitor; |
|
33 |
||
34 |
// CONTANTS |
|
35 |
||
36 |
// Not enough stream to realize to player |
|
37 |
const TInt KErrNotEnoughStreams = -7002; |
|
38 |
||
39 |
/** |
|
40 |
* Used in set loop count to indicate forever loop. |
|
41 |
*/ |
|
42 |
const TInt KJavaRepeatForever = -1; |
|
43 |
||
44 |
/** |
|
45 |
* Returned to Java if duration or mediatime is unknown. |
|
46 |
*/ |
|
47 |
const TInt KTimeUnknown = -1; |
|
48 |
||
49 |
// CLASS DECLARATION |
|
50 |
/** |
|
51 |
* This class is base class for all players. |
|
52 |
* |
|
53 |
* |
|
54 |
*/ |
|
55 |
||
56 |
class CMMAPlayer : public CBase, |
|
71
d5e927d5853b
Revision: v2.2.11
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
57 |
public MMMASourceStreamListener, public MMMACallStateObserver |
66 | 58 |
|
59 |
{ |
|
60 |
public: |
|
61 |
/** |
|
62 |
* Player state. Same that in Java side. |
|
63 |
*/ |
|
64 |
enum TPlayerState |
|
65 |
{ |
|
66 |
EClosed = 0, |
|
67 |
EUnrealized = 100, |
|
68 |
ERealized = 200, |
|
69 |
EPrefetched = 300, |
|
70 |
EStarted = 400 |
|
71 |
}; |
|
72 |
||
73 |
public: |
|
74 |
/** |
|
75 |
* Deletes all owned members. |
|
76 |
*/ |
|
77 |
IMPORT_C virtual ~CMMAPlayer(); |
|
78 |
protected: |
|
79 |
/** |
|
80 |
* Initializes member variables to defaults. |
|
81 |
*/ |
|
82 |
IMPORT_C CMMAPlayer(); |
|
83 |
||
84 |
/** |
|
85 |
* Second phase construct. |
|
86 |
*/ |
|
87 |
void ConstructL(); |
|
88 |
||
89 |
public: // static methods |
|
90 |
/** |
|
91 |
* Creates and adds source stream to the player. New stream will be |
|
92 |
* owned by this player. |
|
93 |
* |
|
94 |
* @param aJniEnv Used to create source stream. |
|
95 |
* @param aPlayer Player to use. |
|
96 |
* @param aEventSource Used to create source stream. |
|
97 |
* @param aReader Java side stream object. |
|
98 |
* @param aSourceStream New stream's pointer will be set to this. |
|
99 |
*/ |
|
100 |
static void StaticAddSourceStreamL(JNIEnv* aJniEnv, |
|
101 |
CMMAPlayer* aPlayer, |
|
102 |
CMMAEventSource* aEventSource, |
|
103 |
jobject aReader, |
|
104 |
CMMASourceStream** aSourceStream); |
|
105 |
||
106 |
/** |
|
107 |
* Sets Java listener object that will be used to post player events |
|
108 |
* and control specific events. |
|
109 |
* |
|
110 |
* @param aPlayer Player to use. |
|
111 |
* @param aListenerObject Java side listener object. |
|
112 |
* @param aJni Used to get method ids. |
|
113 |
* @param aPoster Used to post events. |
|
114 |
*/ |
|
115 |
static void StaticSetPlayerListenerObjectL(CMMAPlayer* aPlayer, |
|
116 |
jobject aListenerObject, |
|
117 |
JNIEnv* aJni, |
|
118 |
MMMAEventPoster* aPoster); |
|
119 |
||
120 |
/** |
|
121 |
* Initializes action completed callbacks. |
|
122 |
* |
|
123 |
* @param aPlayer Player to use. |
|
124 |
* @param aPlayerObject Java side Player object. |
|
125 |
* @param aJni Used to get method id. |
|
126 |
*/ |
|
127 |
static void StaticInitPlayerL(CMMAPlayer* aPlayer, |
|
128 |
jobject aPlayerObject, |
|
129 |
JNIEnv* aJni); |
|
130 |
||
131 |
/** |
|
132 |
* Static getter for control objects. |
|
133 |
* |
|
134 |
* @param aPlayer Player to use. |
|
135 |
* @param aIndex Control's index. |
|
136 |
*/ |
|
137 |
IMPORT_C static CMMAControl* StaticControl(CMMAPlayer* aPlayer, |
|
138 |
TInt aIndex); |
|
139 |
||
140 |
public: // New methods |
|
141 |
||
142 |
/** |
|
143 |
* Realizes the player. Implementations do not necessarily add |
|
144 |
* functionality in this method. If successful player is in |
|
145 |
* ERealized state. |
|
146 |
*/ |
|
147 |
virtual void RealizeL(); |
|
148 |
||
149 |
/** |
|
150 |
* Prefetches data. Usually data from source stream will be read. When |
|
151 |
* prefetch completes action completed event will be delivered. If |
|
152 |
* successful player is in EPrefetched state. |
|
153 |
*/ |
|
154 |
virtual void PrefetchL() = 0; |
|
155 |
||
156 |
/** |
|
157 |
* Start playing. Started event will be posted. If there is no error |
|
158 |
* player will be in EStarted state. |
|
159 |
*/ |
|
160 |
virtual void StartL(TBool aPostEvent) = 0; |
|
161 |
||
162 |
/** |
|
163 |
* Stops playing. After this player may be restarted with StartL method. |
|
164 |
* After this player is in EPrefetched state. |
|
165 |
* |
|
166 |
* @param aPostEvent Indicates if java be informed. |
|
167 |
*/ |
|
168 |
virtual void StopL(TBool aPostEvent) = 0; |
|
169 |
||
170 |
/** |
|
171 |
* Releases resources. Player state can be changed. |
|
172 |
*/ |
|
173 |
virtual void DeallocateL() = 0; |
|
174 |
||
175 |
/** |
|
176 |
* Close the Player and release its resources. After this player is in |
|
177 |
* EClosed state and cannot be used anymore. |
|
178 |
*/ |
|
179 |
IMPORT_C virtual void CloseL(); |
|
180 |
||
181 |
/** |
|
182 |
* Gets duration. |
|
183 |
* |
|
184 |
* @param aDuration Duration or KTimeUnknown if not specified. |
|
185 |
*/ |
|
186 |
IMPORT_C virtual void GetDuration(TInt64* aDuration); |
|
187 |
||
188 |
/** |
|
189 |
* Sets media time. |
|
190 |
* |
|
191 |
* @param aTime Time to set. When method returns parameter contains |
|
192 |
* actual media time set. |
|
193 |
*/ |
|
194 |
virtual void SetMediaTimeL(TInt64* aTime); |
|
195 |
||
196 |
/** |
|
197 |
* Gets media time. |
|
198 |
* |
|
199 |
* @param aMediaTime When method returns parameter contains the media |
|
200 |
* time. |
|
201 |
*/ |
|
202 |
virtual void GetMediaTime(TInt64* aMediaTime); |
|
203 |
||
204 |
/** |
|
205 |
* Sets loop count. |
|
206 |
* |
|
207 |
* @param aCount Indicates the number of times the content will be |
|
208 |
* played. KJavaRepeatForever indicates looping |
|
209 |
* indefintely. |
|
210 |
*/ |
|
211 |
IMPORT_C virtual void SetLoopCount(TInt aCount); |
|
212 |
||
213 |
/** |
|
214 |
* Get the content type of the media that's being played back by this |
|
215 |
* Player. |
|
216 |
* @return The content type being played back by this Player. NULL if |
|
217 |
* content type is not available. |
|
218 |
*/ |
|
219 |
HBufC* ContentType() const; |
|
220 |
||
221 |
public: // from MMMACallStateObserver |
|
71
d5e927d5853b
Revision: v2.2.11
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
222 |
IMPORT_C void HandleCallStateEventL(TUid aUid, TInt aKey); |
66 | 223 |
|
224 |
public: // new methods |
|
225 |
/** |
|
226 |
* Sets Java listener object that will be used to post player events |
|
227 |
* and control specific events. |
|
228 |
* |
|
229 |
* @param aListenerObject Java side listener object. |
|
230 |
* @param aJni Used to get method ids. |
|
231 |
* @param aPoster Used to post events. |
|
232 |
*/ |
|
233 |
IMPORT_C virtual void SetPlayerListenerObjectL(jobject aListenerObject, |
|
234 |
JNIEnv* aJni, |
|
235 |
MMMAEventPoster* aPoster); |
|
236 |
||
237 |
/** |
|
238 |
* Returns total count of the controls owned by this player. |
|
239 |
* |
|
240 |
* @return Count of the controls. |
|
241 |
*/ |
|
242 |
IMPORT_C TInt ControlCount(); |
|
243 |
||
244 |
/** |
|
245 |
* Gets control. Ownership is not tranferred. |
|
246 |
* |
|
247 |
* @param aIndex Control index. |
|
248 |
*/ |
|
249 |
IMPORT_C CMMAControl* Control(TInt aIndex); |
|
250 |
||
251 |
/** |
|
252 |
* Adds new control. Ownership is transferred to this class. |
|
253 |
* |
|
254 |
* @param aControl New control. |
|
255 |
*/ |
|
256 |
IMPORT_C virtual void AddControlL(CMMAControl* aControl); |
|
257 |
||
258 |
/** |
|
259 |
* Adds listener. All listeners will informed when player state changes. |
|
260 |
* |
|
261 |
* @param aListener New listener. |
|
262 |
*/ |
|
263 |
IMPORT_C void AddStateListenerL(MMMAPlayerStateListener* aListener); |
|
264 |
||
265 |
/** |
|
266 |
* Removes a player state listener. |
|
267 |
* |
|
268 |
* @param aListener Listener to be removed. |
|
269 |
*/ |
|
270 |
IMPORT_C void RemoveStateListener(MMMAPlayerStateListener* aListener); |
|
271 |
||
272 |
/** |
|
273 |
* @return Player's state. |
|
274 |
*/ |
|
275 |
inline TInt State(); |
|
276 |
||
277 |
/** |
|
278 |
* Returns player's type. Player types are defined in derived player |
|
279 |
* headers. |
|
280 |
* @return Player type. |
|
281 |
*/ |
|
282 |
virtual const TDesC& Type(); |
|
283 |
||
284 |
/** |
|
285 |
* Sets player's content type, which can be queried with ContentType |
|
286 |
* method. Ownership is transfered. |
|
287 |
* @param aContentType Player's content type. |
|
288 |
*/ |
|
289 |
void SetContentType(HBufC* aContentType); |
|
290 |
||
291 |
/** |
|
292 |
* Reset all source streams. |
|
293 |
*/ |
|
294 |
void ResetSourceStreams(); |
|
295 |
||
296 |
/** |
|
297 |
* Refresh all the controls. |
|
298 |
*/ |
|
299 |
void RefreshControls(); |
|
300 |
/** |
|
301 |
* delete all the controls. |
|
302 |
*/ |
|
303 |
void DeleteControls(); |
|
304 |
||
305 |
public: // methods for informing java player listeners |
|
306 |
||
307 |
/** |
|
308 |
* Post event which event data will be Long java object. |
|
309 |
* |
|
310 |
* @param aEventType Event's type specified in CMMAPlayerEvent. |
|
311 |
* @param aLongEventData Event data context. |
|
312 |
*/ |
|
313 |
void PostLongEvent(CMMAPlayerEvent::TEventType aEventType, |
|
314 |
const TInt64& aLongEventData); |
|
315 |
||
316 |
/** |
|
317 |
* Post event which event data will be string. |
|
318 |
* |
|
319 |
* @param aEventType Event's type specified in CMMAPlayerEvent. |
|
320 |
* @param aStringEventData Event data context. |
|
321 |
*/ |
|
322 |
IMPORT_C void PostStringEvent(CMMAPlayerEvent::TEventType aEventType, |
|
323 |
const TDesC& aStringEventData); |
|
324 |
||
325 |
/** |
|
326 |
* Post event which event data will be a java object. |
|
327 |
* |
|
328 |
* @param aEventType Event's type specified in CMMAPlayerEvent. |
|
329 |
* @param aEventData Java object. |
|
330 |
*/ |
|
331 |
IMPORT_C void PostObjectEvent(CMMAPlayerEvent::TEventType aEventType, |
|
332 |
const jobject aEventData); |
|
333 |
||
334 |
/** |
|
335 |
* Completes action and allows Java side to continue. |
|
336 |
* |
|
337 |
* @param aError of the action or KErrNone. |
|
338 |
*/ |
|
339 |
IMPORT_C void PostActionCompleted(TInt aError); |
|
340 |
||
341 |
protected: // new methods |
|
342 |
/** |
|
343 |
* @see StaticAddSourceStreamL |
|
344 |
*/ |
|
345 |
IMPORT_C virtual CMMASourceStream* AddSourceStreamL(JNIEnv* aJniEnv, |
|
346 |
CMMAEventSource* aEventSource, |
|
347 |
jobject aReader); |
|
348 |
||
349 |
/** |
|
350 |
* Changes player's state and informs all MMMAPlayerStateListeners. |
|
351 |
* |
|
352 |
* @param aState New state. |
|
353 |
*/ |
|
354 |
IMPORT_C void ChangeState(TPlayerState aState); |
|
355 |
||
356 |
public: // from MMMASourceStreamListener |
|
357 |
virtual void ReadCompletedL(TInt aStatus, const TDesC8& aData); |
|
358 |
||
359 |
protected: // Memeber data |
|
360 |
/** |
|
361 |
* Array of controls. All controls are owned by this class. |
|
362 |
*/ |
|
363 |
RPointerArray< CMMAControl > iControls; |
|
364 |
||
365 |
/** |
|
366 |
* Array of streams. All streams are owned by this class. |
|
367 |
*/ |
|
368 |
RPointerArray< CMMASourceStream > iSourceStreams; |
|
369 |
||
370 |
||
371 |
/** |
|
372 |
* Array of listeners. Not owned. |
|
373 |
*/ |
|
374 |
RPointerArray< MMMAPlayerStateListener > iStateListeners; |
|
375 |
||
376 |
/** |
|
377 |
* Used to inform java side of completion. |
|
378 |
* Owned. |
|
379 |
*/ |
|
380 |
CMMAEvent* iActionCompletedEvent; |
|
381 |
||
382 |
/** |
|
383 |
* Player state listener object. |
|
384 |
*/ |
|
385 |
jobject iListenerObject; |
|
386 |
||
387 |
/** |
|
388 |
* java method postEvent(String,Object) |
|
389 |
*/ |
|
390 |
jmethodID iPostEvent; |
|
391 |
/** |
|
392 |
* java method postObjectEvent(int,Object) |
|
393 |
*/ |
|
394 |
jmethodID iPostObjectEvent; |
|
395 |
||
396 |
/** |
|
397 |
* java method postLongEvent(int,long) |
|
398 |
*/ |
|
399 |
jmethodID iPostLongEvent; |
|
400 |
||
401 |
/** |
|
402 |
* java method postStringEvent(int,String) |
|
403 |
*/ |
|
404 |
jmethodID iPostStringEvent; |
|
405 |
||
406 |
/** |
|
407 |
* java method postControlEvent(int,String) |
|
408 |
*/ |
|
409 |
jmethodID iPostControlEvent; |
|
410 |
||
411 |
/** |
|
412 |
* Not owned. |
|
413 |
*/ |
|
414 |
MMMAEventPoster* iEventPoster; |
|
415 |
||
416 |
/** |
|
417 |
* Total number of wanted loops. |
|
418 |
*/ |
|
419 |
TInt iRepeatNumberOfTimes; |
|
420 |
||
421 |
/** |
|
422 |
* Indicates if looping indefintely. |
|
423 |
*/ |
|
424 |
TBool iRepeatForever; |
|
425 |
||
426 |
/** |
|
427 |
* Current loop count. |
|
428 |
*/ |
|
429 |
TInt iRepeatCount; |
|
430 |
||
431 |
/** |
|
432 |
* Content duration in microseconds. |
|
433 |
*/ |
|
434 |
TInt64 iDuration; |
|
435 |
||
436 |
/** |
|
437 |
* Current state of the player. |
|
438 |
*/ |
|
439 |
TPlayerState iState; |
|
440 |
||
441 |
/** |
|
442 |
* Event for notificating Java that memory allocation has failed. |
|
443 |
* Owned. |
|
444 |
*/ |
|
445 |
CMMAPlayerEvent* iOOMErrorEvent; |
|
446 |
||
447 |
/** |
|
448 |
* The content type being played back by this Player. |
|
449 |
* Owned. May be NULL until type is available. |
|
450 |
*/ |
|
451 |
HBufC* iContentType; |
|
452 |
||
453 |
/** |
|
454 |
* Player state listener that sends duration update event to Java |
|
455 |
* if duration has changed when player state changes. |
|
456 |
*/ |
|
457 |
CMMADurationUpdater* iDurationUpdater; |
|
458 |
||
71
d5e927d5853b
Revision: v2.2.11
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
459 |
/** |
66 | 460 |
* Used to get the callback for Call State Events. |
461 |
*/ |
|
462 |
CMMACallStateMonitor* iStateObserver; |
|
463 |
||
464 |
/** |
|
465 |
* Used to determine if the Player is in Paused state |
|
466 |
* due to call or done by user. |
|
467 |
*/ |
|
468 |
TBool isPausedByCall; |
|
469 |
}; |
|
470 |
||
471 |
||
472 |
inline TInt CMMAPlayer::State() |
|
473 |
{ |
|
474 |
return iState; |
|
475 |
} |
|
476 |
||
477 |
#endif // CMMAPLAYER_H |