Search in sources :

Example 56 with MediaPlayer

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

Example 57 with MediaPlayer

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

Example 58 with MediaPlayer

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

Example 59 with MediaPlayer

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

Example 60 with MediaPlayer

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;
}
Also used : MediaRecorder(android.media.MediaRecorder) 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