Merge "Support loading image and paused image for inline video" into honeycomb-mr1
diff --git a/core/java/android/webkit/HTML5VideoInline.java b/core/java/android/webkit/HTML5VideoInline.java
index f1d9189..4f042a6 100644
--- a/core/java/android/webkit/HTML5VideoInline.java
+++ b/core/java/android/webkit/HTML5VideoInline.java
@@ -17,24 +17,15 @@
     private static SurfaceTexture mSurfaceTexture = null;
     private static int[] mTextureNames;
 
-    // Only when the video is prepared, we render using SurfaceTexture.
-    // This in fact is used to avoid showing the obsolete content when
-    // switching videos.
-    private static boolean mReadyToUseSurfTex = false;
-
     // Video control FUNCTIONS:
     @Override
     public void start() {
         super.start();
-        if (mCurrentState == STATE_PREPARED) {
-            mReadyToUseSurfTex = true;
-        }
     }
 
     HTML5VideoInline(int videoLayerId, int position,
             boolean autoStart) {
         init(videoLayerId, position, autoStart);
-        mReadyToUseSurfTex = false;
     }
 
     @Override
@@ -54,7 +45,6 @@
     @Override
     public void pauseAndDispatch(HTML5VideoViewProxy proxy) {
         super.pauseAndDispatch(proxy);
-        mReadyToUseSurfTex = false;
     }
 
     // Inline Video specific FUNCTIONS:
@@ -87,11 +77,6 @@
         return mTextureNames[0];
     }
 
-    @Override
-    public boolean getReadyToUseSurfTex() {
-        return mReadyToUseSurfTex;
-    }
-
     private void setFrameAvailableListener(SurfaceTexture.OnFrameAvailableListener l) {
         mSurfaceTexture.setOnFrameAvailableListener(l);
     }
diff --git a/core/java/android/webkit/HTML5VideoView.java b/core/java/android/webkit/HTML5VideoView.java
index 663497c..b9d55e0 100644
--- a/core/java/android/webkit/HTML5VideoView.java
+++ b/core/java/android/webkit/HTML5VideoView.java
@@ -27,9 +27,12 @@
     // prepared and not prepared.
     // When the video is not prepared, we will have to save the seekTo time,
     // and use it when prepared to play.
-    protected static final int STATE_NOTPREPARED        = 0;
-    protected static final int STATE_PREPARED           = 1;
-
+    // NOTE: these values are in sync with VideoLayerAndroid.h in webkit side.
+    // Please keep them in sync when changed.
+    static final int STATE_INITIALIZED        = 0;
+    static final int STATE_NOTPREPARED        = 1;
+    static final int STATE_PREPARED           = 2;
+    static final int STATE_PLAYING            = 3;
     protected int mCurrentState;
 
     protected HTML5VideoViewProxy mProxy;
@@ -121,7 +124,7 @@
     // Every time we start a new Video, we create a VideoView and a MediaPlayer
     public void init(int videoLayerId, int position, boolean autoStart) {
         mPlayer = new MediaPlayer();
-        mCurrentState = STATE_NOTPREPARED;
+        mCurrentState = STATE_INITIALIZED;
         mProxy = null;
         mVideoLayerId = videoLayerId;
         mSaveSeekTime = position;
@@ -190,6 +193,7 @@
         } catch (IOException e) {
             e.printStackTrace();
         }
+        mCurrentState = STATE_NOTPREPARED;
     }
 
 
@@ -198,6 +202,15 @@
         return mVideoLayerId;
     }
 
+
+    public int getCurrentState() {
+        if (mPlayer.isPlaying()) {
+            return STATE_PLAYING;
+        } else {
+            return mCurrentState;
+        }
+    }
+
     private static final class TimeupdateTask extends TimerTask {
         private HTML5VideoViewProxy mProxy;
 
diff --git a/core/java/android/webkit/HTML5VideoViewProxy.java b/core/java/android/webkit/HTML5VideoViewProxy.java
index d3fcfa5..d12b965 100644
--- a/core/java/android/webkit/HTML5VideoViewProxy.java
+++ b/core/java/android/webkit/HTML5VideoViewProxy.java
@@ -105,12 +105,12 @@
 
                 int currentVideoLayerId = mHTML5VideoView.getVideoLayerId();
                 if (layer != 0 && surfTexture != null && currentVideoLayerId != -1) {
-                    boolean readyToUseSurfTex =
-                        mHTML5VideoView.getReadyToUseSurfTex();
+                    int playerState = mHTML5VideoView.getCurrentState();
                     boolean foundInTree = nativeSendSurfaceTexture(surfTexture,
                             layer, currentVideoLayerId, textureName,
-                            readyToUseSurfTex);
-                    if (readyToUseSurfTex && !foundInTree) {
+                            playerState);
+                    if (playerState == HTML5VideoView.STATE_PREPARED
+                            && !foundInTree) {
                         mHTML5VideoView.pauseAndDispatch(mCurrentProxy);
                         mHTML5VideoView.deleteSurfaceTexture();
                     }
@@ -228,6 +228,9 @@
                     mHTML5VideoView.isFullScreenMode() &&
                     mHTML5VideoView.getAutostart() )
                 mHTML5VideoView.start();
+            if (mBaseLayer != 0) {
+                setBaseLayer(mBaseLayer);
+            }
         }
 
         public static void end() {
@@ -668,5 +671,5 @@
     private native void nativeOnTimeupdate(int position, int nativePointer);
     private native static boolean nativeSendSurfaceTexture(SurfaceTexture texture,
             int baseLayer, int videoLayerId, int textureName,
-            boolean updateTexture);
+            int playerState);
 }