use of android.media.MediaPlayer in project android_frameworks_base by ResurrectionRemix.
the class CodecTest method seekTo.
public static boolean seekTo(String filePath) {
Log.v(TAG, "seekTo " + filePath);
int currentPosition = 0;
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(filePath);
mp.prepare();
mp.start();
mp.seekTo(MediaNames.SEEK_TIME);
Thread.sleep(MediaNames.WAIT_TIME);
currentPosition = mp.getCurrentPosition();
} catch (Exception e) {
Log.v(TAG, e.getMessage());
}
mp.stop();
mp.release();
Log.v(TAG, "CurrentPosition = " + currentPosition);
//The currentposition should be at least greater than the 80% of seek time
if ((currentPosition > MediaNames.SEEK_TIME * 0.8))
return true;
else
return false;
}
use of android.media.MediaPlayer in project android_frameworks_base by ResurrectionRemix.
the class CodecTest method mediaRecorderRecord.
public static boolean mediaRecorderRecord(String filePath) {
Log.v(TAG, "SoundRecording - " + filePath);
//This test is only for the short media file
int duration = 0;
try {
MediaRecorder mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.setOutputFile(filePath);
mRecorder.prepare();
mRecorder.start();
Thread.sleep(500);
mRecorder.stop();
Log.v(TAG, "sound recorded");
mRecorder.release();
} catch (Exception e) {
Log.v(TAG, e.toString());
}
//Verify the recorded file
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(filePath);
mp.prepare();
duration = mp.getDuration();
Log.v(TAG, "Duration " + duration);
mp.release();
} catch (Exception e) {
}
//Check the record media file length is greate than zero
if (duration > 0)
return true;
else
return false;
}
use of android.media.MediaPlayer in project android_frameworks_base by ResurrectionRemix.
the class CodecTest method setLooping.
public static boolean setLooping(String filePath) {
int currentPosition = 0;
int duration = 0;
long t1 = 0;
long t2 = 0;
Log.v(TAG, "SetLooping - " + filePath);
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(filePath);
mp.prepare();
duration = mp.getDuration();
Log.v(TAG, "setLooping duration " + duration);
mp.setLooping(true);
mp.start();
Thread.sleep(5000);
mp.seekTo(duration - 5000);
t1 = SystemClock.uptimeMillis();
Thread.sleep(20000);
t2 = SystemClock.uptimeMillis();
Log.v(TAG, "pause");
//Bug# 1106852 - IllegalStateException will be thrown if pause is called
//in here
//mp.pause();
currentPosition = mp.getCurrentPosition();
Log.v(TAG, "looping position " + currentPosition + "duration = " + (t2 - t1));
} catch (Exception e) {
Log.v(TAG, "Exception : " + e.toString());
}
mp.stop();
mp.release();
//and should be greater than zero.
if ((currentPosition < ((t2 - t1 - 5000) * 1.2)) && currentPosition > 0)
return true;
else
return false;
}
use of android.media.MediaPlayer in project android_frameworks_base by ResurrectionRemix.
the class CodecTest method seektoBeforeStart.
public static boolean seektoBeforeStart(String filePath) {
Log.v(TAG, "seektoBeforeStart - " + filePath);
//This test is only for the short media file
int duration = 0;
int currentPosition = 0;
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(filePath);
mp.prepare();
duration = mp.getDuration();
mp.seekTo(duration - 10000);
mp.start();
currentPosition = mp.getCurrentPosition();
mp.stop();
mp.release();
} catch (Exception e) {
}
if (currentPosition < duration / 2)
return false;
else
return true;
}
use of android.media.MediaPlayer in project android_frameworks_base by ResurrectionRemix.
the class CodecTest method videoSeekTo.
//This also test the streaming video which may take a long
//time to start the playback.
public static boolean videoSeekTo(String filePath) throws Exception {
Log.v(TAG, "videoSeekTo - " + filePath);
int currentPosition = 0;
int duration = 0;
boolean videoResult = false;
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(filePath);
mp.setDisplay(MediaFrameworkTest.mSurfaceView.getHolder());
mp.prepare();
mp.start();
if (filePath.equals(MediaNames.VIDEO_SHORT_3GP)) {
mp.pause();
Thread.sleep(MediaNames.PAUSE_WAIT_TIME);
mp.seekTo(0);
mp.start();
Thread.sleep(1000);
currentPosition = mp.getCurrentPosition();
Log.v(TAG, "short position " + currentPosition);
if (currentPosition > 100)
return true;
else
return false;
}
Thread.sleep(5000);
duration = mp.getDuration();
Log.v(TAG, "video duration " + duration);
mp.pause();
Thread.sleep(MediaNames.PAUSE_WAIT_TIME);
mp.seekTo(duration - 20000);
mp.start();
Thread.sleep(1000);
mp.pause();
Thread.sleep(MediaNames.PAUSE_WAIT_TIME);
mp.seekTo(duration / 2);
mp.start();
Thread.sleep(10000);
currentPosition = mp.getCurrentPosition();
Log.v(TAG, "video currentPosition " + currentPosition);
mp.release();
if (currentPosition > (duration / 2) * 0.9)
return true;
else
return false;
}
Aggregations