use of android.media.MediaPlayer in project android_frameworks_base by ParanoidAndroid.
the class CodecTest method isLooping.
public static boolean isLooping(String filePath) {
MediaPlayer mp = null;
try {
mp = new MediaPlayer();
if (mp.isLooping()) {
Log.v(TAG, "MediaPlayer.isLooping() returned true after ctor");
return false;
}
mp.setDataSource(filePath);
mp.prepare();
mp.setLooping(true);
if (!mp.isLooping()) {
Log.v(TAG, "MediaPlayer.isLooping() returned false after setLooping(true)");
return false;
}
mp.setLooping(false);
if (mp.isLooping()) {
Log.v(TAG, "MediaPlayer.isLooping() returned true after setLooping(false)");
return false;
}
} catch (Exception e) {
Log.v(TAG, "Exception : " + e.toString());
return false;
} finally {
if (mp != null)
mp.release();
}
return true;
}
use of android.media.MediaPlayer in project android_frameworks_base by ParanoidAndroid.
the class CodecTest method isLoopingAfterReset.
public static boolean isLoopingAfterReset(String filePath) {
MediaPlayer mp = null;
try {
mp = new MediaPlayer();
mp.setDataSource(filePath);
mp.prepare();
mp.setLooping(true);
mp.reset();
if (mp.isLooping()) {
Log.v(TAG, "MediaPlayer.isLooping() returned true after reset()");
return false;
}
} catch (Exception e) {
Log.v(TAG, "Exception : " + e.toString());
return false;
} finally {
if (mp != null)
mp.release();
}
return true;
}
use of android.media.MediaPlayer in project android_frameworks_base by ParanoidAndroid.
the class CodecTest method getCurrentPosition.
public static boolean getCurrentPosition(String filePath) {
Log.v(TAG, "GetCurrentPosition - " + filePath);
int currentPosition = 0;
long t1 = 0;
long t2 = 0;
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(filePath);
Log.v(TAG, "start playback");
mp.prepare();
mp.start();
t1 = SystemClock.uptimeMillis();
Thread.sleep(10000);
mp.pause();
Thread.sleep(MediaNames.PAUSE_WAIT_TIME);
t2 = SystemClock.uptimeMillis();
} catch (Exception e) {
Log.v(TAG, e.toString());
}
currentPosition = mp.getCurrentPosition();
mp.stop();
mp.release();
Log.v(TAG, "mp currentPositon = " + currentPosition + " play duration = " + (t2 - t1));
//For the very short mp3, it should return the length instead of 10 seconds
if (filePath.equals(MediaNames.SHORTMP3)) {
if (currentPosition < 1000)
return true;
}
if ((currentPosition < ((t2 - t1) * 1.2)) && (currentPosition > 0))
return true;
else
return false;
}
use of android.media.MediaPlayer in project android_frameworks_base by ParanoidAndroid.
the class CodecTest method pause.
public static boolean pause(String filePath) throws Exception {
Log.v(TAG, "pause - " + filePath);
boolean misPlaying = true;
boolean pauseResult = false;
long t1 = 0;
long t2 = 0;
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(filePath);
mp.prepare();
int duration = mp.getDuration();
mp.start();
t1 = SystemClock.uptimeMillis();
Thread.sleep(5000);
mp.pause();
Thread.sleep(MediaNames.PAUSE_WAIT_TIME);
t2 = SystemClock.uptimeMillis();
misPlaying = mp.isPlaying();
int curPosition = mp.getCurrentPosition();
Log.v(TAG, filePath + " pause currentPositon " + curPosition);
Log.v(TAG, "isPlaying " + misPlaying + " wait time " + (t2 - t1));
String cpuinfo = printCpuInfo();
Log.v(TAG, cpuinfo);
if ((curPosition > 0) && (curPosition < ((t2 - t1) * 1.3)) && (misPlaying == false))
pauseResult = true;
mp.stop();
mp.release();
return pauseResult;
}
use of android.media.MediaPlayer in project android_frameworks_base by ParanoidAndroid.
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;
}
Aggregations