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