Merge change 1748 into donut
* changes: Add a tool to play all kinds of media files saved in /sdcard/media_api/samples/. It also tests the seeking functionality during the play of each sample file.
This commit is contained in:
@@ -23,7 +23,8 @@ package com.android.mediaframeworktest;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class MediaNames {
|
public class MediaNames {
|
||||||
|
//A directory to hold all kinds of media files
|
||||||
|
public static final String MEDIA_SAMPLE_POOL = "/sdcard/media_api/samples/";
|
||||||
//Audio files
|
//Audio files
|
||||||
public static final String MP3CBR = "/sdcard/media_api/music/MP3CBR.mp3";
|
public static final String MP3CBR = "/sdcard/media_api/music/MP3CBR.mp3";
|
||||||
public static final String MP3VBR = "/sdcard/media_api/music/MP3VBR.mp3";
|
public static final String MP3VBR = "/sdcard/media_api/music/MP3VBR.mp3";
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.Random;
|
||||||
/**
|
/**
|
||||||
* Junit / Instrumentation test case for the media player api
|
* Junit / Instrumentation test case for the media player api
|
||||||
|
|
||||||
@@ -50,8 +51,9 @@ public class CodecTest {
|
|||||||
private static final Object lock = new Object();
|
private static final Object lock = new Object();
|
||||||
private static final Object prepareDone = new Object();
|
private static final Object prepareDone = new Object();
|
||||||
private static final Object videoSizeChanged = new Object();
|
private static final Object videoSizeChanged = new Object();
|
||||||
|
private static final Object onCompletion = new Object();
|
||||||
private static boolean onPrepareSuccess = false;
|
private static boolean onPrepareSuccess = false;
|
||||||
|
private static boolean onCompleteSuccess = false;
|
||||||
|
|
||||||
public static String printCpuInfo(){
|
public static String printCpuInfo(){
|
||||||
String cm = "dumpsys cpuinfo";
|
String cm = "dumpsys cpuinfo";
|
||||||
@@ -726,7 +728,74 @@ public class CodecTest {
|
|||||||
return onPrepareSuccess;
|
return onPrepareSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static MediaPlayer.OnCompletionListener mCompletionListener = new MediaPlayer.OnCompletionListener() {
|
||||||
|
public void onCompletion(MediaPlayer mp) {
|
||||||
|
synchronized (onCompletion) {
|
||||||
|
Log.v(TAG, "notify the completion callback");
|
||||||
|
onCompletion.notify();
|
||||||
|
onCompleteSuccess = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// For each media file, forward twice and backward once, then play to the end
|
||||||
|
public static boolean playMediaSamples(String filePath) throws Exception {
|
||||||
|
int duration = 0;
|
||||||
|
int curPosition = 0;
|
||||||
|
int nextPosition = 0;
|
||||||
|
int waittime = 0;
|
||||||
|
Random r = new Random();
|
||||||
|
initializeMessageLooper();
|
||||||
|
synchronized (lock) {
|
||||||
|
try {
|
||||||
|
lock.wait(WAIT_FOR_COMMAND_TO_COMPLETE);
|
||||||
|
} catch(Exception e) {
|
||||||
|
Log.v(TAG, "looper was interrupted.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
mMediaPlayer.setOnCompletionListener(mCompletionListener);
|
||||||
|
Log.v(TAG, "playMediaSamples: sample file name " + filePath);
|
||||||
|
mMediaPlayer.setDataSource(filePath);
|
||||||
|
mMediaPlayer.setDisplay(MediaFrameworkTest.mSurfaceView.getHolder());
|
||||||
|
mMediaPlayer.prepare();
|
||||||
|
duration = mMediaPlayer.getDuration();
|
||||||
|
Log.v(TAG, "playMediaSamples: duration = " + duration);
|
||||||
|
// start to play
|
||||||
|
mMediaPlayer.start();
|
||||||
|
// randomly play for time within (0, duration/3)
|
||||||
|
Thread.sleep(r.nextInt(duration/3));
|
||||||
|
mMediaPlayer.pause();
|
||||||
|
Log.v(TAG, "playMediaSamples: current position after pause: "
|
||||||
|
+ mMediaPlayer.getCurrentPosition());
|
||||||
|
// seek to position (0, 2/3*duration)
|
||||||
|
nextPosition = mMediaPlayer.getCurrentPosition() + r.nextInt(duration/3);
|
||||||
|
mMediaPlayer.seekTo(nextPosition);
|
||||||
|
Log.v(TAG, "playMediaSamples: current position after the first seek:"
|
||||||
|
+ mMediaPlayer.getCurrentPosition());
|
||||||
|
// play for another short time
|
||||||
|
mMediaPlayer.start();
|
||||||
|
Thread.sleep(r.nextInt(duration/6));
|
||||||
|
Log.v(TAG, "playMediaSamples: position after the second play:"
|
||||||
|
+ mMediaPlayer.getCurrentPosition());
|
||||||
|
// seek to a random position (0, duration)
|
||||||
|
mMediaPlayer.seekTo(r.nextInt(duration));
|
||||||
|
Log.v(TAG, "playMediaSamples: current position after the second seek:"
|
||||||
|
+ mMediaPlayer.getCurrentPosition());
|
||||||
|
waittime = duration - mMediaPlayer.getCurrentPosition();
|
||||||
|
synchronized(onCompletion){
|
||||||
|
try {
|
||||||
|
onCompletion.wait(waittime + 30000);
|
||||||
|
}catch (Exception e) {
|
||||||
|
Log.v(TAG, "playMediaSamples are interrupted");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
terminateMessageLooper();
|
||||||
|
}catch (Exception e) {
|
||||||
|
Log.v(TAG, "playMediaSamples:" + e.getMessage());
|
||||||
|
}
|
||||||
|
return onCompleteSuccess;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ import android.test.suitebuilder.annotation.LargeTest;
|
|||||||
import android.test.suitebuilder.annotation.MediumTest;
|
import android.test.suitebuilder.annotation.MediumTest;
|
||||||
import android.test.suitebuilder.annotation.Suppress;
|
import android.test.suitebuilder.annotation.Suppress;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Junit / Instrumentation test case for the media player api
|
* Junit / Instrumentation test case for the media player api
|
||||||
|
|
||||||
@@ -456,4 +458,29 @@ public class MediaPlayerApiTest extends ActivityInstrumentationTestCase<MediaFra
|
|||||||
CodecTest.prepareAsyncCallback(MediaNames.STREAM_H264_480_360_1411k, true);
|
CodecTest.prepareAsyncCallback(MediaNames.STREAM_H264_480_360_1411k, true);
|
||||||
assertTrue("StreamH264PrepareAsyncCallback", onPrepareSuccess);
|
assertTrue("StreamH264PrepareAsyncCallback", onPrepareSuccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Provide a tool to play all kinds of media files in a directory
|
||||||
|
@Suppress
|
||||||
|
@LargeTest
|
||||||
|
public void testMediaSamples() throws Exception {
|
||||||
|
// load directory files
|
||||||
|
boolean onCompleteSuccess = false;
|
||||||
|
File dir = new File(MediaNames.MEDIA_SAMPLE_POOL);
|
||||||
|
String[] children = dir.list();
|
||||||
|
if (children == null) {
|
||||||
|
Log.v("MediaPlayerApiTest:testMediaSamples", "dir is empty");
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < children.length; i++) {
|
||||||
|
//Get filename of directory
|
||||||
|
String filename = children[i];
|
||||||
|
Log.v("MediaPlayerApiTest",
|
||||||
|
"testMediaSamples: file to be played: "
|
||||||
|
+ dir + "/" + filename);
|
||||||
|
onCompleteSuccess =
|
||||||
|
CodecTest.playMediaSamples(dir + "/" + filename);
|
||||||
|
assertTrue("testMediaSamples", onCompleteSuccess);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user