Search in sources :

Example 36 with MediaPlayer

use of android.media.MediaPlayer in project JamsMusicPlayer by psaravan.

the class AudioPlaybackService method initMediaPlayers.

/**
	 * Initializes the MediaPlayer objects for this service session.
	 */
private void initMediaPlayers() {
    /*
		 * Release the MediaPlayer objects if they are still valid.
		 */
    if (mMediaPlayer != null) {
        mMediaPlayer.release();
        mMediaPlayer = null;
    }
    if (mMediaPlayer2 != null) {
        getMediaPlayer2().release();
        mMediaPlayer2 = null;
    }
    mMediaPlayer = new MediaPlayer();
    mMediaPlayer2 = new MediaPlayer();
    setCurrentMediaPlayer(1);
    getMediaPlayer().reset();
    getMediaPlayer2().reset();
    //Loop the players if the repeat mode is set to repeat the current song.
    if (getRepeatMode() == Common.REPEAT_SONG) {
        getMediaPlayer().setLooping(true);
        getMediaPlayer2().setLooping(true);
    }
    try {
        mMediaPlayer.setWakeMode(mContext, PowerManager.PARTIAL_WAKE_LOCK);
        getMediaPlayer2().setWakeMode(mContext, PowerManager.PARTIAL_WAKE_LOCK);
    } catch (Exception e) {
        mMediaPlayer = new MediaPlayer();
        mMediaPlayer2 = new MediaPlayer();
        setCurrentMediaPlayer(1);
    }
    //Set the mediaPlayers' stream sources.
    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    getMediaPlayer2().setAudioStreamType(AudioManager.STREAM_MUSIC);
}
Also used : MediaPlayer(android.media.MediaPlayer)

Example 37 with MediaPlayer

use of android.media.MediaPlayer in project android-ocr by rmtheis.

the class BeepManager method buildMediaPlayer.

private static MediaPlayer buildMediaPlayer(Context activity) {
    MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    // When the beep has finished playing, rewind to queue up another one.
    mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

        public void onCompletion(MediaPlayer player) {
            player.seekTo(0);
        }
    });
    AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep);
    try {
        mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
        file.close();
        mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
        mediaPlayer.prepare();
    } catch (IOException ioe) {
        Log.w(TAG, ioe);
        mediaPlayer = null;
    }
    return mediaPlayer;
}
Also used : AssetFileDescriptor(android.content.res.AssetFileDescriptor) IOException(java.io.IOException) MediaPlayer(android.media.MediaPlayer)

Example 38 with MediaPlayer

use of android.media.MediaPlayer in project robolectric by robolectric.

the class ShadowMediaPlayerTest method testSimulatenousEventsAllRun.

@Test
public void testSimulatenousEventsAllRun() {
    // Simultaneous events should all run even if
    // one of them stops playback.
    MediaEvent e1 = new MediaEvent() {

        @Override
        public void run(MediaPlayer mp, ShadowMediaPlayer smp) {
            smp.doStop();
        }
    };
    MediaEvent e2 = Mockito.mock(MediaEvent.class);
    info.scheduleEventAtOffset(100, e1);
    info.scheduleEventAtOffset(100, e2);
    shadowMediaPlayer.setState(INITIALIZED);
    shadowMediaPlayer.doStart();
    scheduler.advanceBy(100);
    // Verify that the first event ran
    assertThat(shadowMediaPlayer.isReallyPlaying()).isFalse();
    Mockito.verify(e2).run(mediaPlayer, shadowMediaPlayer);
}
Also used : MediaEvent(org.robolectric.shadows.ShadowMediaPlayer.MediaEvent) MediaPlayer(android.media.MediaPlayer) Test(org.junit.Test)

Example 39 with MediaPlayer

use of android.media.MediaPlayer in project glass-progress-bar by pif.

the class MessageDialog method play.

private void play(DialogSound sound) {
    int id = R.raw.sound_success;
    switch(sound) {
        case DISMISS:
            id = R.raw.sound_dismiss;
            break;
        case SUCCESS:
            id = R.raw.sound_success;
            break;
        case ERROR:
            id = R.raw.sound_error;
            break;
    }
    if (lastPlayer != null) {
        lastPlayer.release();
    }
    MediaPlayer mediaPlayer = MediaPlayer.create(getContext(), id);
    mediaPlayer.setLooping(false);
    mediaPlayer.start();
    lastPlayer = mediaPlayer;
}
Also used : MediaPlayer(android.media.MediaPlayer)

Example 40 with MediaPlayer

use of android.media.MediaPlayer in project android-app by eoecn.

the class CaptureActivity method initBeepSound.

/**
     * 扫描正确后的震动声音,如果感觉apk大了,可以删除
     */
private void initBeepSound() {
    if (playBeep && mediaPlayer == null) {
        // The volume on STREAM_SYSTEM is not adjustable, and users found it
        // too loud,
        // so we now play on the music stream.
        setVolumeControlStream(AudioManager.STREAM_MUSIC);
        mediaPlayer = new MediaPlayer();
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mediaPlayer.setOnCompletionListener(beepListener);
        AssetFileDescriptor file = getResources().openRawResourceFd(R.raw.beep);
        try {
            mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
            file.close();
            mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
            mediaPlayer.prepare();
        } catch (IOException e) {
            mediaPlayer = null;
        }
    }
}
Also used : AssetFileDescriptor(android.content.res.AssetFileDescriptor) 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