javauis/mmapi_akn/baseline/javasrc.emc/com/nokia/microedition/media/ManagerImpl.java
equal
deleted
inserted
replaced
31 import com.nokia.mj.impl.rt.legacy.NativeError; |
31 import com.nokia.mj.impl.rt.legacy.NativeError; |
32 import com.nokia.microedition.media.protocol.ProtocolFactory; |
32 import com.nokia.microedition.media.protocol.ProtocolFactory; |
33 import com.nokia.microedition.media.tone.PlayToneImpl; |
33 import com.nokia.microedition.media.tone.PlayToneImpl; |
34 import com.nokia.microedition.volumekeys.ForegroundListener; |
34 import com.nokia.microedition.volumekeys.ForegroundListener; |
35 import com.nokia.mj.impl.rt.support.Finalizer; |
35 import com.nokia.mj.impl.rt.support.Finalizer; |
|
36 import com.nokia.mj.impl.utils.Logger; |
36 |
37 |
37 /** |
38 /** |
38 * ManagerImpl implements the functionality specified in |
39 * ManagerImpl implements the functionality specified in |
39 * javax.microedition.media.Manager class. |
40 * javax.microedition.media.Manager class. |
40 * This class is a singleton and instance can be got with getInstance method. |
41 * This class is a singleton and instance can be got with getInstance method. |
54 private final MIDEventServer iEventServer; |
55 private final MIDEventServer iEventServer; |
55 private final Vector iPlugIns = new Vector(); |
56 private final Vector iPlugIns = new Vector(); |
56 private final ProtocolFactory iProtocolFactory = new ProtocolFactory(); |
57 private final ProtocolFactory iProtocolFactory = new ProtocolFactory(); |
57 private final ForegroundListener iForegroundListener; |
58 private final ForegroundListener iForegroundListener; |
58 |
59 |
|
60 private boolean iClosed = false; |
59 private Finalizer mFinalizer = new Finalizer() |
61 private Finalizer mFinalizer = new Finalizer() |
60 { |
62 { |
61 public void finalizeImpl() |
63 public void finalizeImpl() |
62 { |
64 { |
63 doFinalize(); |
65 doFinalize(); |
164 public void addPlugIn(PlugIn aPlugIn) |
166 public void addPlugIn(PlugIn aPlugIn) |
165 { |
167 { |
166 iPlugIns.addElement(aPlugIn); |
168 iPlugIns.addElement(aPlugIn); |
167 } |
169 } |
168 |
170 |
|
171 private void checkClose() throws MediaException |
|
172 { |
|
173 if (iClosed) |
|
174 { |
|
175 MediaException me = new MediaException("MIDlet closed."); |
|
176 Logger.LOG(Logger.EJavaMMAPI, Logger.EInfo, |
|
177 "Trying to create player when MIDlet is destroyed ", me); |
|
178 throw me; |
|
179 } |
|
180 } |
|
181 |
169 private void doFinalize() |
182 private void doFinalize() |
170 { |
183 { |
171 if (mFinalizer != null) |
184 if (mFinalizer != null) |
172 { |
185 { |
173 registeredFinalize(); |
186 registeredFinalize(); |
178 /** |
191 /** |
179 * This will be called when object is finalized. |
192 * This will be called when object is finalized. |
180 */ |
193 */ |
181 synchronized final void registeredFinalize() |
194 synchronized final void registeredFinalize() |
182 { |
195 { |
|
196 iClosed = true; |
183 _dispose(sEventSourceHandle); |
197 _dispose(sEventSourceHandle); |
184 sEventSourceHandle = 0; |
198 sEventSourceHandle = 0; |
185 } |
199 } |
186 |
200 |
187 /** |
201 /** |
189 * This will release convenient native resources. All native resource |
203 * This will release convenient native resources. All native resource |
190 * will be deleted in registeredFinalize() method. |
204 * will be deleted in registeredFinalize() method. |
191 */ |
205 */ |
192 synchronized final void release() |
206 synchronized final void release() |
193 { |
207 { |
|
208 iClosed = true; |
194 _release(sEventSourceHandle); |
209 _release(sEventSourceHandle); |
195 } |
210 } |
196 |
211 |
197 /** |
212 /** |
198 * Create String array from Vector and remove String duplicates. |
213 * Create String array from Vector and remove String duplicates. |
346 } |
361 } |
347 |
362 |
348 /** |
363 /** |
349 * From PlugIn. |
364 * From PlugIn. |
350 */ |
365 */ |
351 public InternalPlayer createPlayer(DataSource aSource) |
366 public synchronized InternalPlayer createPlayer(DataSource aSource) |
352 throws MediaException, IOException |
367 throws MediaException, IOException |
353 { |
368 { |
|
369 checkClose(); |
354 InternalPlayer player = null; |
370 InternalPlayer player = null; |
355 if (aSource.getContentType() != null) |
371 if (aSource.getContentType() != null) |
356 { |
372 { |
357 // Create player from content type |
373 // Create player from content type |
358 if (isValidContentType(aSource.getContentType())) |
374 if (isValidContentType(aSource.getContentType())) |
422 * @exception IOException Thrown if there was a problem connecting |
438 * @exception IOException Thrown if there was a problem connecting |
423 * with the source pointed to by the <code>locator</code>. |
439 * with the source pointed to by the <code>locator</code>. |
424 * @exception SecurityException Thrown if the caller does not |
440 * @exception SecurityException Thrown if the caller does not |
425 * have security permission to create the <code>Player</code>. |
441 * have security permission to create the <code>Player</code>. |
426 */ |
442 */ |
427 public Player createPlayer(String aLocator) |
443 public synchronized Player createPlayer(String aLocator) |
428 throws IOException, MediaException |
444 throws IOException, MediaException |
429 { |
445 { |
|
446 checkClose(); |
430 if (aLocator == null) |
447 if (aLocator == null) |
431 { |
448 { |
432 throw new IllegalArgumentException("Locator is null."); |
449 throw new IllegalArgumentException("Locator is null."); |
433 } |
450 } |
434 InternalPlayer player = iProtocolFactory.createPlayer( |
451 InternalPlayer player = iProtocolFactory.createPlayer( |
517 * @exception IOException Thrown if there was a problem reading data |
534 * @exception IOException Thrown if there was a problem reading data |
518 * from the <code>InputStream</code>. |
535 * from the <code>InputStream</code>. |
519 * @exception SecurityException Thrown if the caller does not |
536 * @exception SecurityException Thrown if the caller does not |
520 * have security permission to create the <code>Player</code>. |
537 * have security permission to create the <code>Player</code>. |
521 */ |
538 */ |
522 public Player createPlayer(InputStream aStream, String aType) |
539 public synchronized Player createPlayer(InputStream aStream, String aType) |
523 throws IOException, MediaException |
540 throws IOException, MediaException |
524 { |
541 { |
|
542 checkClose(); |
525 if (aStream == null) |
543 if (aStream == null) |
526 { |
544 { |
527 throw new IllegalArgumentException("InputStream is null."); |
545 throw new IllegalArgumentException("InputStream is null."); |
528 } |
546 } |
529 |
547 |