summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeng-Hui Zhu <ztenghui@google.com>2012-05-24 14:53:28 -0700
committerTeng-Hui Zhu <ztenghui@google.com>2012-05-24 15:24:29 -0700
commit6f62ef32e2dd4e7935f5a2d201ad5f3b78b4a203 (patch)
tree36ced8ec9a505ef4eea74e97a4fcbd2320f18725
parent0eaeb69d1c4849da8ab1df70b84e90837193df67 (diff)
downloadframeworks_base-6f62ef32e2dd4e7935f5a2d201ad5f3b78b4a203.zip
frameworks_base-6f62ef32e2dd4e7935f5a2d201ad5f3b78b4a203.tar.gz
frameworks_base-6f62ef32e2dd4e7935f5a2d201ad5f3b78b4a203.tar.bz2
Better support for HTML5 audio loop.
Loop is trigger by a seek to 0 when ended on native side but there is no play call. So on java side, we detect this and call into native side to trigger a play after completion. This fixed the UI problem and keep in sync with the native mode. Beyond that, we don't need to reload for looping and we don't have the seek to play artifacts. bug:5461143 webkit change: https://android-git.corp.google.com/g/#/c/193750/ Change-Id: I779f3e1fbc789832a1a99d1f17823db6b57b35df
-rw-r--r--core/java/android/webkit/HTML5Audio.java28
1 files changed, 15 insertions, 13 deletions
diff --git a/core/java/android/webkit/HTML5Audio.java b/core/java/android/webkit/HTML5Audio.java
index 689884f..fc5df2d 100644
--- a/core/java/android/webkit/HTML5Audio.java
+++ b/core/java/android/webkit/HTML5Audio.java
@@ -67,6 +67,8 @@ class HTML5Audio extends Handler
private String mUrl;
private boolean mAskToPlay = false;
+ private boolean mLoopEnabled = false;
+ private boolean mProcessingOnEnd = false;
private Context mContext;
// Timer thread -> UI thread
@@ -143,7 +145,13 @@ class HTML5Audio extends Handler
// MediaPlayer.OnCompletionListener;
public void onCompletion(MediaPlayer mp) {
mState = COMPLETE;
+ mProcessingOnEnd = true;
nativeOnEnded(mNativePointer);
+ mProcessingOnEnd = false;
+ if (mLoopEnabled == true) {
+ nativeOnRequestPlay(mNativePointer);
+ mLoopEnabled = false;
+ }
}
// MediaPlayer.OnErrorListener
@@ -264,14 +272,10 @@ class HTML5Audio extends Handler
private void play() {
- if (mState == COMPLETE) {
+ if (mState == COMPLETE && mLoopEnabled == true) {
// Play it again, Sam
- mTimer.cancel();
- mTimer = new Timer();
- mAskToPlay = true;
- mMediaPlayer.stop();
- mState = STOPPED;
- mMediaPlayer.prepareAsync();
+ mMediaPlayer.start();
+ mState = STARTED;
return;
}
@@ -304,14 +308,11 @@ class HTML5Audio extends Handler
}
private void seek(int msec) {
+ if (mProcessingOnEnd == true && mState == COMPLETE && msec == 0) {
+ mLoopEnabled = true;
+ }
if (mState >= PREPARED) {
mMediaPlayer.seekTo(msec);
- if (mState == COMPLETE) {
- // Seeking after the stream had completed will
- // cause us to start playing again. This is to
- // support audio tags that specify loop=true.
- play();
- }
}
}
@@ -336,6 +337,7 @@ class HTML5Audio extends Handler
private native void nativeOnBuffering(int percent, int nativePointer);
private native void nativeOnEnded(int nativePointer);
+ private native void nativeOnRequestPlay(int nativePointer);
private native void nativeOnPrepared(int duration, int width, int height, int nativePointer);
private native void nativeOnTimeupdate(int position, int nativePointer);