use of android.media.MediaPlayer in project android_frameworks_base by ParanoidAndroid.
the class CodecTest method getDuration.
public static int getDuration(String filePath) {
Log.v(TAG, "getDuration - " + filePath);
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(filePath);
mp.prepare();
} catch (Exception e) {
Log.v(TAG, e.toString());
}
int duration = mp.getDuration();
Log.v(TAG, "Duration " + duration);
mp.release();
Log.v(TAG, "release");
return duration;
}
use of android.media.MediaPlayer in project android_frameworks_base by ParanoidAndroid.
the class MediaAudioEffectTest method test1_4InsertOnMediaPlayer.
//Test case 1.4: test contructor on mediaPlayer audio session
@LargeTest
public void test1_4InsertOnMediaPlayer() throws Exception {
boolean result = false;
String msg = "test1_4InsertOnMediaPlayer()";
try {
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(MediaNames.SHORTMP3);
AudioEffect effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER, AudioEffect.EFFECT_TYPE_NULL, 0, mp.getAudioSessionId());
assertNotNull(msg + ": could not create AudioEffect", effect);
try {
loge(msg, ": effect.setEnabled");
effect.setEnabled(true);
} catch (IllegalStateException e) {
msg = msg.concat(": AudioEffect not initialized");
}
result = true;
effect.release();
mp.release();
} catch (IllegalArgumentException e) {
msg = msg.concat(": Equalizer not found");
loge(msg, ": Equalizer not found");
} catch (UnsupportedOperationException e) {
msg = msg.concat(": Effect library not loaded");
loge(msg, ": Effect library not loaded");
} catch (Exception e) {
loge(msg, "Could not create media player:" + e);
}
assertTrue(msg, result);
}
use of android.media.MediaPlayer in project android_frameworks_base by ParanoidAndroid.
the class MediaPresetReverbTest method test2_1InsertSoundModification.
//Test case 2.1: test actual insert reverb influence on sound
@LargeTest
public void test2_1InsertSoundModification() throws Exception {
boolean result = false;
String msg = "test2_1InsertSoundModification()";
EnergyProbe probe = null;
AudioEffect vc = null;
MediaPlayer mp = null;
AudioEffect rvb = null;
AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);
int ringerMode = am.getRingerMode();
am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
am.setStreamVolume(AudioManager.STREAM_MUSIC, am.getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0);
try {
// creating a volume controller on output mix ensures that ro.audio.silent mutes
// audio after the effects and not before
vc = new AudioEffect(AudioEffect.EFFECT_TYPE_NULL, VOLUME_EFFECT_UUID, 0, 0);
vc.setEnabled(true);
mp = new MediaPlayer();
mp.setDataSource(MediaNames.SINE_200_1000);
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
// create reverb with UUID instead of PresetReverb constructor otherwise an auxiliary
// reverb will be chosen by the effect framework as we are on session 0
rvb = new AudioEffect(AudioEffect.EFFECT_TYPE_NULL, PRESET_REVERB_EFFECT_UUID, 0, 0);
rvb.setParameter(PresetReverb.PARAM_PRESET, PresetReverb.PRESET_PLATE);
rvb.setEnabled(true);
// create probe after reverb so that it is chained behind the reverb in the
// effect chain
probe = new EnergyProbe(0);
mp.prepare();
mp.start();
Thread.sleep(1000);
mp.stop();
Thread.sleep(200);
// measure energy around 1kHz after media player was stopped for 200 ms
int energy1000 = probe.capture(1000);
assertTrue(msg + ": reverb has no effect", energy1000 > 0);
result = true;
} catch (IllegalArgumentException e) {
msg = msg.concat(": Bad parameter value");
loge(msg, "Bad parameter value");
} catch (UnsupportedOperationException e) {
msg = msg.concat(": get parameter() rejected");
loge(msg, "get parameter() rejected");
} catch (IllegalStateException e) {
msg = msg.concat("get parameter() called in wrong state");
loge(msg, "get parameter() called in wrong state");
} catch (InterruptedException e) {
loge(msg, "sleep() interrupted");
} finally {
if (mp != null) {
mp.release();
}
if (vc != null) {
vc.release();
}
if (rvb != null) {
rvb.release();
}
if (probe != null) {
probe.release();
}
am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
am.setRingerMode(ringerMode);
}
assertTrue(msg, result);
}
use of android.media.MediaPlayer in project android_frameworks_base by ParanoidAndroid.
the class MediaRecorderTest method getOutputVideoProperty.
private void getOutputVideoProperty(String outputFilePath) {
MediaPlayer mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(outputFilePath);
Log.v(TAG, "file Path = " + outputFilePath);
mediaPlayer.setDisplay(MediaFrameworkTest.mSurfaceView.getHolder());
Log.v(TAG, "before player prepare");
mediaPlayer.prepare();
Log.v(TAG, "before getduration");
mOutputDuration = mediaPlayer.getDuration();
Log.v(TAG, "get video dimension");
Thread.sleep(1000);
mOutputVideoHeight = mediaPlayer.getVideoHeight();
mOutputVideoWidth = mediaPlayer.getVideoWidth();
mediaPlayer.release();
} catch (Exception e) {
Log.v(TAG, e.toString());
mediaPlayer.release();
}
}
use of android.media.MediaPlayer in project android_frameworks_base by ParanoidAndroid.
the class MediaRecorderStressTest method recordVideoAndPlayback.
// Helper method for record & playback testing with different camcorder profiles
private void recordVideoAndPlayback(int profile) throws Exception {
int iterations;
int recordDuration;
boolean removeVideo;
int videoEncoder;
int audioEncoder;
int frameRate;
int videoWidth;
int videoHeight;
int bitRate;
if (profile != USE_TEST_RUNNER_PROFILE) {
assertTrue(String.format("Camera doesn't support profile %d", profile), CamcorderProfile.hasProfile(CAMERA_ID, profile));
CamcorderProfile camcorderProfile = CamcorderProfile.get(CAMERA_ID, profile);
videoEncoder = camcorderProfile.videoCodec;
audioEncoder = camcorderProfile.audioCodec;
frameRate = camcorderProfile.videoFrameRate;
videoWidth = camcorderProfile.videoFrameWidth;
videoHeight = camcorderProfile.videoFrameHeight;
bitRate = camcorderProfile.videoBitRate;
} else {
videoEncoder = MediaRecorderStressTestRunner.mVideoEncoder;
audioEncoder = MediaRecorderStressTestRunner.mAudioEncoder;
frameRate = MediaRecorderStressTestRunner.mFrameRate;
videoWidth = MediaRecorderStressTestRunner.mVideoWidth;
videoHeight = MediaRecorderStressTestRunner.mVideoHeight;
bitRate = MediaRecorderStressTestRunner.mBitRate;
}
iterations = MediaRecorderStressTestRunner.mIterations;
recordDuration = MediaRecorderStressTestRunner.mDuration;
removeVideo = MediaRecorderStressTestRunner.mRemoveVideo;
SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
mOutput.write("Total number of loops: " + iterations + "\n");
try {
mOutput.write("No of loop: ");
for (int i = 0; i < iterations; i++) {
String fileName = String.format("%s/temp%d%s", Environment.getExternalStorageDirectory(), i, OUTPUT_FILE_EXT);
Log.v(TAG, fileName);
runOnLooper(new Runnable() {
@Override
public void run() {
mRecorder = new MediaRecorder();
}
});
Log.v(TAG, "iterations : " + iterations);
Log.v(TAG, "video encoder : " + videoEncoder);
Log.v(TAG, "audio encoder : " + audioEncoder);
Log.v(TAG, "frame rate : " + frameRate);
Log.v(TAG, "video width : " + videoWidth);
Log.v(TAG, "video height : " + videoHeight);
Log.v(TAG, "bit rate : " + bitRate);
Log.v(TAG, "record duration : " + recordDuration);
mRecorder.setOnErrorListener(mRecorderErrorCallback);
mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setOutputFile(fileName);
mRecorder.setVideoFrameRate(frameRate);
mRecorder.setVideoSize(videoWidth, videoHeight);
mRecorder.setVideoEncoder(videoEncoder);
mRecorder.setAudioEncoder(audioEncoder);
mRecorder.setVideoEncodingBitRate(bitRate);
Log.v(TAG, "mediaRecorder setPreview");
mRecorder.setPreviewDisplay(surfaceHolder.getSurface());
mRecorder.prepare();
mRecorder.start();
Thread.sleep(recordDuration);
Log.v(TAG, "Before stop");
mRecorder.stop();
mRecorder.release();
//start the playback
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(fileName);
mp.setDisplay(MediaFrameworkTest.mSurfaceView.getHolder());
mp.prepare();
mp.start();
Thread.sleep(recordDuration);
mp.release();
validateRecordedVideo(fileName);
if (removeVideo) {
removeRecordedVideo(fileName);
}
if (i == 0) {
mOutput.write(i + 1);
} else {
mOutput.write(String.format(", %d", (i + 1)));
}
}
} catch (Exception e) {
Log.e(TAG, e.toString());
fail("Record and playback");
}
}
Aggregations