Merge "More lenient on playback start" into nyc-dev
diff --git a/tests/tests/view/src/android/view/cts/PixelCopyTests.java b/tests/tests/view/src/android/view/cts/PixelCopyTests.java
index 1555d00..3fa3634 100644
--- a/tests/tests/view/src/android/view/cts/PixelCopyTests.java
+++ b/tests/tests/view/src/android/view/cts/PixelCopyTests.java
@@ -176,13 +176,15 @@
                 mVideoSourceActivityRule.launchActivity(null);
         if (!activity.canPlayVideo()) {
             Log.i(TAG, "Skipping testVideoProducer, video codec isn't supported");
+            return;
         }
         // This returns when the video has been prepared and playback has
         // been started, it doesn't necessarily means a frame has actually been
         // produced. There sadly isn't a callback for that.
-        // So we'll try for up to 300ms after this event to acquire a frame, otherwise
+        // So we'll try for up to 900ms after this event to acquire a frame, otherwise
         // it's considered a timeout.
         activity.waitForPlaying();
+        assertTrue("Failed to start video playback", activity.canPlayVideo());
         SynchronousPixelCopy copyHelper = new SynchronousPixelCopy();
         Bitmap bitmap = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
         int copyResult = PixelCopy.ERROR_SOURCE_NO_DATA;
@@ -191,7 +193,7 @@
             if (copyResult != PixelCopy.ERROR_SOURCE_NO_DATA) {
                 break;
             }
-            Thread.sleep(10);
+            Thread.sleep(30);
         }
         assertEquals(PixelCopy.SUCCESS, copyResult);
         // A large threshold is used because decoder accuracy is covered in the
diff --git a/tests/tests/view/src/android/view/cts/PixelCopyVideoSourceActivity.java b/tests/tests/view/src/android/view/cts/PixelCopyVideoSourceActivity.java
index 08e3951..e250390 100644
--- a/tests/tests/view/src/android/view/cts/PixelCopyVideoSourceActivity.java
+++ b/tests/tests/view/src/android/view/cts/PixelCopyVideoSourceActivity.java
@@ -20,11 +20,13 @@
 import android.cts.util.MediaUtils;
 import android.net.Uri;
 import android.os.Bundle;
+import android.util.Log;
 import android.widget.VideoView;
 
 import java.util.concurrent.CountDownLatch;
 
 public class PixelCopyVideoSourceActivity extends Activity {
+    private static final String TAG = "PixelCopyVideoSourceActivity";
     private VideoView mVideoView;
     private CountDownLatch mVideoPlayingFence = new CountDownLatch(1);
     private boolean mCanPlayVideo;
@@ -38,6 +40,12 @@
             mVideoView.start();
             mVideoPlayingFence.countDown();
         });
+        mVideoView.setOnErrorListener((mp, what, extra) -> {
+            Log.e(TAG, "MediaPlayer encountered error " + what + ", " + extra);
+            mCanPlayVideo = false;
+            mVideoPlayingFence.countDown();
+            return true;
+        });
         mCanPlayVideo = MediaUtils.hasCodecsForResource(this, R.raw.colorgrid_video);
         if (mCanPlayVideo) {
             Uri uri = Uri.parse("android.resource://android.view.cts/" + R.raw.colorgrid_video);