Java Code Examples for android.media.MediaPlayer#setWakeMode()

The following examples show how to use android.media.MediaPlayer#setWakeMode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FadeMediaPlayer.java    From Rey-MusicPlayer with Apache License 2.0 6 votes vote down vote up
public FadeMediaPlayer(MusicService musicService) {
    mMusicService = musicService;

    mMediaPlayer1 = new MediaPlayer();
    mMediaPlayer2 = new MediaPlayer();
    mHandler = new Handler();

    mMediaPlayer1.setWakeMode(mMusicService, PowerManager.PARTIAL_WAKE_LOCK);
    mMediaPlayer1.setAudioStreamType(AudioManager.STREAM_MUSIC);

    mMediaPlayer2.setWakeMode(mMusicService, PowerManager.PARTIAL_WAKE_LOCK);
    mMediaPlayer2.setAudioStreamType(AudioManager.STREAM_MUSIC);

    try {
        startSong();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 2
Source File: MusicService.java    From Rey-MusicPlayer with Apache License 2.0 5 votes vote down vote up
private void initMediaPlayers() {
    mMediaPlayer1 = new MediaPlayer();
    mMediaPlayer1.setWakeMode(this, PowerManager.PARTIAL_WAKE_LOCK);
    mMediaPlayer1.setAudioStreamType(AudioManager.STREAM_MUSIC);


    if (mSongs.size() > 0) {
        startSong();
    }
}
 
Example 3
Source File: RadioPlaybackService.java    From Sky31Radio with Apache License 2.0 5 votes vote down vote up
public RadioPlayer() {
    mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setLooping(true);
    mediaPlayer.setOnBufferingUpdateListener(this);
    mediaPlayer.setOnPreparedListener(this);
    mediaPlayer.setScreenOnWhilePlaying(true);
    mediaPlayer.setOnErrorListener(this);
    mediaPlayer.setOnCompletionListener(this);
    mediaPlayer.setWakeMode(RadioPlaybackService.this, PowerManager.PARTIAL_WAKE_LOCK);
}
 
Example 4
Source File: SoundLogic.java    From redalert-android with Apache License 2.0 5 votes vote down vote up
static void playSoundURI(Uri alarmSoundUi, Context context) {
    // No URI?
    if (alarmSoundUi == null) {
        return;
    }

    // Already initialized or currently playing?
    stopSound(context);

    // Create new MediaPlayer
    mPlayer = new MediaPlayer();

    // Wake up processor
    mPlayer.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK);

    // Set stream type
    mPlayer.setAudioStreamType(getSoundStreamType(context));

    try {
        // Set URI data source
        mPlayer.setDataSource(context, alarmSoundUi);

        // Prepare media player
        mPlayer.prepare();
    }
    catch (Exception exc) {
        // Log it
        Log.e(Logging.TAG, "Media player preparation failed", exc);

        // Show visible error toast
        Toast.makeText(context, exc.toString(), Toast.LENGTH_LONG).show();
    }

    // Actually start playing
    mPlayer.start();
}