Search in sources :

Example 66 with MediaPlayer

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

the class MediaRecorderStressTest method testStressTimeLapse.

// Test case for stressing time lapse
@LargeTest
public void testStressTimeLapse() throws Exception {
    SurfaceHolder mSurfaceHolder;
    mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
    int recordDuration = MediaRecorderStressTestRunner.mTimeLapseDuration;
    boolean removeVideo = MediaRecorderStressTestRunner.mRemoveVideo;
    double captureRate = MediaRecorderStressTestRunner.mCaptureRate;
    Log.v(TAG, "Start camera time lapse stress:");
    mOutput.write("Total number of loops: " + NUMBER_OF_TIME_LAPSE_LOOPS + "\n");
    try {
        for (int i = 0, n = Camera.getNumberOfCameras(); i < n; i++) {
            mOutput.write("No of loop: camera " + i);
            for (int j = 0; j < NUMBER_OF_TIME_LAPSE_LOOPS; j++) {
                String fileName = String.format("%s/temp%d_%d%s", Environment.getExternalStorageDirectory(), i, j, OUTPUT_FILE_EXT);
                Log.v(TAG, fileName);
                runOnLooper(new Runnable() {

                    @Override
                    public void run() {
                        mRecorder = new MediaRecorder();
                    }
                });
                // Set callback
                mRecorder.setOnErrorListener(mRecorderErrorCallback);
                // Set video source
                mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
                // Set camcorder profile for time lapse
                CamcorderProfile profile = CamcorderProfile.get(j, CamcorderProfile.QUALITY_TIME_LAPSE_HIGH);
                mRecorder.setProfile(profile);
                // Set the timelapse setting; 0.1 = 10 sec timelapse, 0.5 = 2 sec timelapse, etc
                // http://developer.android.com/guide/topics/media/camera.html#time-lapse-video
                mRecorder.setCaptureRate(captureRate);
                // Set output file
                mRecorder.setOutputFile(fileName);
                // Set the preview display
                Log.v(TAG, "mediaRecorder setPreviewDisplay");
                mRecorder.setPreviewDisplay(mSurfaceHolder.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(mSurfaceHolder);
                mp.prepare();
                mp.start();
                Thread.sleep(TIME_LAPSE_PLAYBACK_WAIT_TIME);
                mp.release();
                validateRecordedVideo(fileName);
                if (removeVideo) {
                    removeRecordedVideo(fileName);
                }
                if (j == 0) {
                    mOutput.write(j + 1);
                } else {
                    mOutput.write(String.format(", %d", (j + 1)));
                }
            }
        }
    } catch (IllegalStateException e) {
        Log.e(TAG, e.toString());
        fail("Camera time lapse stress test IllegalStateException");
    } catch (IOException e) {
        Log.e(TAG, e.toString());
        fail("Camera time lapse stress test IOException");
    } catch (Exception e) {
        Log.e(TAG, e.toString());
        fail("Camera time lapse stress test Exception");
    }
}
Also used : CamcorderProfile(android.media.CamcorderProfile) IOException(java.io.IOException) IOException(java.io.IOException) SurfaceHolder(android.view.SurfaceHolder) MediaRecorder(android.media.MediaRecorder) MediaPlayer(android.media.MediaPlayer) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 67 with MediaPlayer

use of android.media.MediaPlayer in project AndEngine by nicolasgramlich.

the class MusicFactory method createMusicFromAssetFileDescriptor.

public static Music createMusicFromAssetFileDescriptor(final MusicManager pMusicManager, final AssetFileDescriptor pAssetFileDescriptor) throws IOException {
    final MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setDataSource(pAssetFileDescriptor.getFileDescriptor(), pAssetFileDescriptor.getStartOffset(), pAssetFileDescriptor.getLength());
    mediaPlayer.prepare();
    final Music music = new Music(pMusicManager, mediaPlayer);
    pMusicManager.add(music);
    return music;
}
Also used : MediaPlayer(android.media.MediaPlayer)

Example 68 with MediaPlayer

use of android.media.MediaPlayer in project AndEngine by nicolasgramlich.

the class MusicFactory method createMusicFromResource.

public static Music createMusicFromResource(final MusicManager pMusicManager, final Context pContext, final int pMusicResID) throws IOException {
    final MediaPlayer mediaPlayer = MediaPlayer.create(pContext, pMusicResID);
    mediaPlayer.prepare();
    final Music music = new Music(pMusicManager, mediaPlayer);
    pMusicManager.add(music);
    return music;
}
Also used : MediaPlayer(android.media.MediaPlayer)

Example 69 with MediaPlayer

use of android.media.MediaPlayer in project AndEngine by nicolasgramlich.

the class MusicFactory method createMusicFromFile.

// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
// ===========================================================
// Methods
// ===========================================================
public static Music createMusicFromFile(final MusicManager pMusicManager, final File pFile) throws IOException {
    final MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setDataSource(new FileInputStream(pFile).getFD());
    mediaPlayer.prepare();
    final Music music = new Music(pMusicManager, mediaPlayer);
    pMusicManager.add(music);
    return music;
}
Also used : FileInputStream(java.io.FileInputStream) MediaPlayer(android.media.MediaPlayer)

Example 70 with MediaPlayer

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

the class AudioPlaybackQueueItem method run.

@Override
public void run() {
    final UtteranceProgressDispatcher dispatcher = getDispatcher();
    dispatcher.dispatchOnStart();
    int sessionId = mAudioParams.mSessionId;
    mPlayer = MediaPlayer.create(mContext, mUri, null, mAudioParams.mAudioAttributes, sessionId > 0 ? sessionId : AudioManager.AUDIO_SESSION_ID_GENERATE);
    if (mPlayer == null) {
        dispatcher.dispatchOnError(TextToSpeech.ERROR_OUTPUT);
        return;
    }
    try {
        mPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {

            @Override
            public boolean onError(MediaPlayer mp, int what, int extra) {
                Log.w(TAG, "Audio playback error: " + what + ", " + extra);
                mDone.open();
                return true;
            }
        });
        mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

            @Override
            public void onCompletion(MediaPlayer mp) {
                mFinished = true;
                mDone.open();
            }
        });
        setupVolume(mPlayer, mAudioParams.mVolume, mAudioParams.mPan);
        mPlayer.start();
        mDone.block();
        finish();
    } catch (IllegalArgumentException ex) {
        Log.w(TAG, "MediaPlayer failed", ex);
        mDone.open();
    }
    if (mFinished) {
        dispatcher.dispatchOnSuccess();
    } else {
        dispatcher.dispatchOnStop();
    }
}
Also used : UtteranceProgressDispatcher(android.speech.tts.TextToSpeechService.UtteranceProgressDispatcher) 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