Search in sources :

Example 81 with MediaPlayer

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

Example 82 with MediaPlayer

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

Example 83 with MediaPlayer

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

Example 84 with MediaPlayer

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

Example 85 with MediaPlayer

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;
}
Also used : 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