diff options
Diffstat (limited to 'media')
-rw-r--r-- | media/java/android/media/AudioTimestamp.java | 3 | ||||
-rw-r--r-- | media/java/android/media/AudioTrack.java | 5 | ||||
-rw-r--r-- | media/java/android/media/MediaPlayer.java | 51 |
3 files changed, 43 insertions, 16 deletions
diff --git a/media/java/android/media/AudioTimestamp.java b/media/java/android/media/AudioTimestamp.java index 437a0c6..965ba85 100644 --- a/media/java/android/media/AudioTimestamp.java +++ b/media/java/android/media/AudioTimestamp.java @@ -26,9 +26,6 @@ package android.media; * is available to the system, but cannot account for any delay unknown to the implementation. * * @see AudioTrack#getTimestamp - * @see AudioTrack.TimestampListener - * - * @hide */ public final class AudioTimestamp { diff --git a/media/java/android/media/AudioTrack.java b/media/java/android/media/AudioTrack.java index 88539f28..788257d 100644 --- a/media/java/android/media/AudioTrack.java +++ b/media/java/android/media/AudioTrack.java @@ -735,8 +735,7 @@ public class AudioTrack /** * Poll for a timestamp on demand. * - * Use if {@link TimestampListener} is not delivered often enough for your needs, - * or if you need to get the most recent timestamp outside of the event callback handler. + * Use if you need to get the most recent timestamp outside of the event callback handler. * Calling this method too often may be inefficient; * if you need a high-resolution mapping between frame position and presentation time, * consider implementing that at application level, based on low-resolution timestamps. @@ -756,8 +755,6 @@ public class AudioTrack * with the estimated time when that frame was presented or is committed to * be presented. * In the case that no timestamp is available, any supplied instance is left unaltered. - * - * @hide */ public AudioTimestamp getTimestamp(AudioTimestamp timestamp) { diff --git a/media/java/android/media/MediaPlayer.java b/media/java/android/media/MediaPlayer.java index d286be4..ce1896a 100644 --- a/media/java/android/media/MediaPlayer.java +++ b/media/java/android/media/MediaPlayer.java @@ -1351,8 +1351,10 @@ public class MediaPlayer implements SubtitleController.Listener mOnInfoListener = null; mOnVideoSizeChangedListener = null; mOnTimedTextListener = null; - mTimeProvider.close(); - mTimeProvider = null; + if (mTimeProvider != null) { + mTimeProvider.close(); + mTimeProvider = null; + } mOnSubtitleDataListener = null; _release(); } @@ -1380,11 +1382,17 @@ public class MediaPlayer implements SubtitleController.Listener if (mSubtitleController != null) { mSubtitleController.reset(); } + if (mTimeProvider != null) { + mTimeProvider.close(); + mTimeProvider = null; + } stayAwake(false); _reset(); // make sure none of the listeners get called anymore - mEventHandler.removeCallbacksAndMessages(null); + if (mEventHandler != null) { + mEventHandler.removeCallbacksAndMessages(null); + } disableProxyListener(); } @@ -2121,6 +2129,9 @@ public class MediaPlayer implements SubtitleController.Listener /** @hide */ public MediaTimeProvider getMediaTimeProvider() { + if (mTimeProvider == null) { + mTimeProvider = new TimeProvider(this); + } return mTimeProvider; } @@ -2761,6 +2772,7 @@ public class MediaPlayer implements SubtitleController.Listener private static final int REFRESH_AND_NOTIFY_TIME = 1; private static final int NOTIFY_STOP = 2; private static final int NOTIFY_SEEK = 3; + private HandlerThread mHandlerThread; /** @hide */ public boolean DEBUG = false; @@ -2773,7 +2785,18 @@ public class MediaPlayer implements SubtitleController.Listener // we assume starting position mRefresh = true; } - mEventHandler = new EventHandler(); + + Looper looper; + if ((looper = Looper.myLooper()) == null && + (looper = Looper.getMainLooper()) == null) { + // Create our own looper here in case MP was created without one + mHandlerThread = new HandlerThread("MediaPlayerMTPEventThread", + Process.THREAD_PRIORITY_FOREGROUND); + mHandlerThread.start(); + looper = mHandlerThread.getLooper(); + } + mEventHandler = new EventHandler(looper); + mListeners = new MediaTimeProvider.OnMediaTimeListener[0]; mTimes = new long[0]; mLastTimeUs = 0; @@ -2790,6 +2813,17 @@ public class MediaPlayer implements SubtitleController.Listener /** @hide */ public void close() { mEventHandler.removeMessages(NOTIFY); + if (mHandlerThread != null) { + mHandlerThread.quitSafely(); + mHandlerThread = null; + } + } + + /** @hide */ + protected void finalize() { + if (mHandlerThread != null) { + mHandlerThread.quitSafely(); + } } /** @hide */ @@ -3055,6 +3089,10 @@ public class MediaPlayer implements SubtitleController.Listener } private class EventHandler extends Handler { + public EventHandler(Looper looper) { + super(looper); + } + @Override public void handleMessage(Message msg) { if (msg.what == NOTIFY) { @@ -3075,10 +3113,5 @@ public class MediaPlayer implements SubtitleController.Listener } } } - - /** @hide */ - public Handler getHandler() { - return mEventHandler; - } } } |