Fixed an incorrect test case where MediaPlayer.start() was called right after MediaPlayer.stop() was called.

I also changed the test case so that it becomes more interesting:
1) video plays on surface A.
2) switch to use surface B.
3) switch to use a null surface.
4) switch back to use surface A.

o related-to-bug: 6158159

Change-Id: I2f5f9ad4077017c37ab4912c9cea48c3e7020621
diff --git a/tests/tests/media/src/android/media/cts/MediaPlayerTest.java b/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
index ff43e27..9c03a0b 100644
--- a/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
@@ -123,9 +123,9 @@
             }
         });
 
-        playVideoTest(R.raw.testvideo, 352, 288);
+        loadResource(R.raw.testvideo);
+        playLoadedVideo(352, 288, -1);
 
-        mMediaPlayer.start();
         Thread.sleep(SLEEP_TIME);
 
         int posBefore = mMediaPlayer.getCurrentPosition();
@@ -152,7 +152,7 @@
         Thread.sleep(SLEEP_TIME);
 
         posBefore = mMediaPlayer.getCurrentPosition();
-        mMediaPlayer.setDisplay(getActivity().generateSurfaceHolder());
+        mMediaPlayer.setDisplay(getActivity().getSurfaceHolder());
         posAfter = mMediaPlayer.getCurrentPosition();
 
         assertEquals(posAfter, posBefore, tolerance);
diff --git a/tests/tests/media/src/android/media/cts/MediaPlayerTestBase.java b/tests/tests/media/src/android/media/cts/MediaPlayerTestBase.java
index 59a50d5..a594122 100644
--- a/tests/tests/media/src/android/media/cts/MediaPlayerTestBase.java
+++ b/tests/tests/media/src/android/media/cts/MediaPlayerTestBase.java
@@ -141,9 +141,13 @@
      *
      * @param width width of the video to verify, or null to skip verification
      * @param height height of the video to verify, or null to skip verification
-     * @param playTime length of time to play video, or 0 to play entire video
+     * @param playTime length of time to play video, or 0 to play entire video.
+     * with a non-negative value, this method stops the playback after the length of
+     * time or the duration the video is elapsed. With a value of -1,
+     * this method simply starts the video and returns immediately without
+     * stoping the video playback.
      */
-    private void playLoadedVideo(final Integer width, final Integer height, int playTime)
+    protected void playLoadedVideo(final Integer width, final Integer height, int playTime)
             throws Exception {
         final float leftVolume = 0.5f;
         final float rightVolume = 0.5f;
@@ -181,7 +185,9 @@
         mMediaPlayer.setVolume(leftVolume, rightVolume);
 
         // waiting to complete
-        if (playTime == 0) {
+        if (playTime == -1) {
+            return;
+        } else if (playTime == 0) {
             while (mMediaPlayer.isPlaying()) {
                 Thread.sleep(SLEEP_TIME);
             }