Search in sources :

Example 76 with MediaPlayer

use of android.media.MediaPlayer in project android_frameworks_base by ResurrectionRemix.

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);
}
Also used : AudioManager(android.media.AudioManager) EnergyProbe(com.android.mediaframeworktest.functional.EnergyProbe) AudioEffect(android.media.audiofx.AudioEffect) MediaPlayer(android.media.MediaPlayer) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 77 with MediaPlayer

use of android.media.MediaPlayer in project android_frameworks_base by ResurrectionRemix.

the class CodecTest method seekToEnd.

public static boolean seekToEnd(String filePath) {
    Log.v(TAG, "seekToEnd - " + filePath);
    int duration = 0;
    int currentPosition = 0;
    boolean isPlaying = false;
    MediaPlayer mp = new MediaPlayer();
    try {
        mp.setDataSource(filePath);
        Log.v(TAG, "start playback");
        mp.prepare();
        duration = mp.getDuration();
        mp.seekTo(duration - 3000);
        mp.start();
        Thread.sleep(6000);
    } catch (Exception e) {
    }
    isPlaying = mp.isPlaying();
    currentPosition = mp.getCurrentPosition();
    Log.v(TAG, "seekToEnd currentPosition= " + currentPosition + " isPlaying = " + isPlaying);
    mp.stop();
    mp.release();
    Log.v(TAG, "duration = " + duration);
    if (currentPosition < 0.9 * duration || isPlaying)
        return false;
    else
        return true;
}
Also used : IOException(java.io.IOException) MediaPlayer(android.media.MediaPlayer)

Example 78 with MediaPlayer

use of android.media.MediaPlayer in project android_frameworks_base by ResurrectionRemix.

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);
}
Also used : MediaPlayer(android.media.MediaPlayer) AudioEffect(android.media.audiofx.AudioEffect) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 79 with MediaPlayer

use of android.media.MediaPlayer in project android_frameworks_base by ResurrectionRemix.

the class MediaAudioEffectTest method test1_5AuxiliaryOnMediaPlayer.

//Test case 1.5: test auxiliary effect attachement on MediaPlayer
@LargeTest
public void test1_5AuxiliaryOnMediaPlayer() throws Exception {
    boolean result = false;
    String msg = "test1_5AuxiliaryOnMediaPlayer()";
    try {
        MediaPlayer mp = new MediaPlayer();
        mp.setDataSource(MediaNames.SHORTMP3);
        AudioEffect effect = new AudioEffect(AudioEffect.EFFECT_TYPE_ENV_REVERB, AudioEffect.EFFECT_TYPE_NULL, 0, 0);
        assertNotNull(msg + ": could not create AudioEffect", effect);
        mp.attachAuxEffect(effect.getId());
        mp.setAuxEffectSendLevel(1.0f);
        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);
}
Also used : MediaPlayer(android.media.MediaPlayer) AudioEffect(android.media.audiofx.AudioEffect) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 80 with MediaPlayer

use of android.media.MediaPlayer in project android_frameworks_base by ResurrectionRemix.

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;
}
Also used : IOException(java.io.IOException) MediaPlayer(android.media.MediaPlayer)

Aggregations

MediaPlayer (android.media.MediaPlayer)370 IOException (java.io.IOException)180 LargeTest (android.test.suitebuilder.annotation.LargeTest)60 AudioEffect (android.media.audiofx.AudioEffect)54 AudioManager (android.media.AudioManager)50 AssetFileDescriptor (android.content.res.AssetFileDescriptor)28 EnergyProbe (com.android.mediaframeworktest.functional.EnergyProbe)24 MediaRecorder (android.media.MediaRecorder)18 Uri (android.net.Uri)16 SurfaceHolder (android.view.SurfaceHolder)16 CamcorderProfile (android.media.CamcorderProfile)12 File (java.io.File)12 VideoView (android.widget.VideoView)11 Intent (android.content.Intent)8 OnPreparedListener (android.media.MediaPlayer.OnPreparedListener)7 Surface (android.view.Surface)7 View (android.view.View)7 MediaController (android.widget.MediaController)7 MediaFormat (android.media.MediaFormat)6 UtteranceProgressDispatcher (android.speech.tts.TextToSpeechService.UtteranceProgressDispatcher)6