MediaPlayer setWakeMode - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for MediaPlayer setWakeMode method.

This code example shows how to use the following methods:setOnCompletionListener, setOnErrorListener, setOnPreparedListener, setWakeMode
     * Makes sure the media player exists and has been reset. This will create the media player 
     * if needed. reset the existing media player if one already exists. 
     */ 
    protected void createMediaPlayerIfNeeded() { 
        if (mPlayer == null) {
            mPlayer = new MediaPlayer();
 
            // make sure the CPU won't go to sleep while media is playing 
            mPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
 
            // the media player will notify the service when it's ready preparing, and when it's done playing 
            mPlayer.setOnPreparedListener(this);
            mPlayer.setOnCompletionListener(this);
            mPlayer.setOnErrorListener(this);
             
        } else { 
            mPlayer.reset();
        } 
    } 
 
7
CodeRank
This code example shows how to use the following methods:setOnCompletionListener, setOnErrorListener, setOnPreparedListener, setWakeMode
     * Makes sure the media player exists and has been reset. This will create the media player 
     * if needed, or reset the existing media player if one already exists. 
     */ 
    void createMediaPlayerIfNeeded() { 
        if (mPlayer == null) {
            mPlayer = new MediaPlayer();
 
            // Make sure the media player will acquire a wake-lock while playing. If we don't do 
            // that, the CPU might go to sleep while the song is playing, causing playback to stop. 
            // 
            // Remember that to use this, we have to declare the android.permission.WAKE_LOCK 
            // permission in AndroidManifest.xml. 
            mPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
 
            // we want the media player to notify us when it's ready preparing, and when it's done 
            // playing: 
            mPlayer.setOnPreparedListener(this);
            mPlayer.setOnCompletionListener(this);
            mPlayer.setOnErrorListener(this);
        } 

7
CodeRank
This code example shows how to use the following methods:setWakeMode
		} 
	} 
 
	@Override 
	public MediaPlayer swapPlayer(MediaPlayer mediaPlayer, int state) {
		MediaPlayer mp = super.swapPlayer(mediaPlayer, state);
		if (mEnabled) {
			mediaPlayer.setWakeMode(mContext, WAKE_LOCK);
		} 
		return mp;
	} 
} 
6
CodeRank
This code example shows how to use the following methods:setOnErrorListener, setOnPreparedListener, setVolume, setWakeMode
	    { 
	        case AudioManager.AUDIOFOCUS_GAIN:
	            // resume playback 
	            if (mp == null) initMediaPlayer();
	            else if (!mp.isPlaying()) mp.start();
	            mp.setVolume(1.0f, 1.0f);
	            break; 
 
	        case AudioManager.AUDIOFOCUS_LOSS:
	            // Lost focus for an unbounded amount of time: stop playback and release media player 
	        	if(mp != null)
	        	{ 
		            if (mp.isPlaying()) mp.stop();
		            mp.release();
		            mp = null;
	        	} 
	            break; 
 
	        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
	        	if(mp != null)

6
CodeRank
This code example shows how to use the following methods:setOnCompletionListener, setOnErrorListener, setOnPreparedListener, setWakeMode
     * Makes sure the media player exists and has been reset. This will create the media player if 
     * needed, or reset the existing media player if one already exists. 
     */ 
    void createMediaPlayerIfNeeded() { 
        if (mPlayer == null) {
            mPlayer = new MediaPlayer();
 
            // Make sure the media player will acquire a wake-lock while playing. If we don't do 
            // that, the CPU might go to sleep while the song is playing, causing playback to stop. 
            // 
            // Remember that to use this, we have to declare the android.permission.WAKE_LOCK 
            // permission in AndroidManifest.xml. 
            mPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
 
            // we want the media player to notify us when it's ready preparing, and when it's done 
            // playing: 
            mPlayer.setOnPreparedListener(this);
            mPlayer.setOnCompletionListener(this);
            mPlayer.setOnErrorListener(this);
        } else { 

6
CodeRank
This code example shows how to use the following methods:setOnCompletionListener, setOnErrorListener, setOnPreparedListener, setWakeMode
     * the media player if needed, or reset the existing media player if one 
     * already exists. 
     */ 
    void createMediaPlayerIfNeeded() { 
        if (mPlayer == null) {
            mPlayer = new MediaPlayer();
 
            // Make sure the media player will acquire a wake-lock while 
            // playing. If we don't do 
            // that, the CPU might go to sleep while the song is playing, 
            // causing playback to stop. 
            // 
            // Remember that to use this, we have to declare the 
            // android.permission.WAKE_LOCK 
            // permission in AndroidManifest.xml. 
            mPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
 
            // we want the media player to notify us when it's ready preparing, 
            // and when it's done 
            // playing: 

5
CodeRank
This code example shows how to use the following methods:setOnCompletionListener, setOnErrorListener, setOnPreparedListener, setWakeMode
     * Makes sure the media player exists and has been reset. This will create the media player 
     * if needed, or reset the existing media player if one already exists. 
     */ 
    void createMediaPlayerIfNeeded() { 
        if (mPlayer == null) {
            mPlayer = new MediaPlayer();
 
            // Make sure the media player will acquire a wake-lock while playing. If we don't do 
            // that, the CPU might go to sleep while the song is playing, causing playback to stop. 
            // 
            // Remember that to use this, we have to declare the android.permission.WAKE_LOCK 
            // permission in AndroidManifest.xml. 
            mPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
 
            // we want the media player to notify us when it's ready preparing, and when it's done 
            // playing: 
            mPlayer.setOnPreparedListener(this);
            mPlayer.setOnCompletionListener(this);
            mPlayer.setOnErrorListener(this);
        } 

5
CodeRank
This code example shows how to use the following methods:prepare, setAudioStreamType, setDataSource, setLooping, setWakeMode
                .parse(alarm);
 
        boolean override = settings.getBoolean("override", false);
        boolean vibrate = settings.getBoolean("vibrate", false);
 
        mediaPlayer = new MediaPlayer();
        alarmPlaying = false;
 
        try { 
 
            if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL || override) {
                mediaPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
                mediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
                mediaPlayer.setDataSource(this, uri);
                mediaPlayer.setLooping(true);
                mediaPlayer.prepare();
                mediaPlayer.start();
 
                alarmPlaying = true;
            } 

6
CodeRank
This code example shows how to use the following methods:prepare, setAudioStreamType, setDataSource, setWakeMode, start
This code example shows how to use the following methods:setOnCompletionListener, setOnErrorListener, setOnPreparedListener, setWakeMode
     * Makes sure the media player exists and has been reset. This will create the media player 
     * if needed, or reset the existing media player if one already exists. 
     */ 
    private void createMediaPlayerIfNeeded() { 
        if (mPlayer == null) {
            mPlayer = new MediaPlayer();
 
            // Make sure the media player will acquire a wake-lock while playing. If we don't do 
            // that, the CPU might go to sleep while the song is playing, causing playback to stop. 
            // 
            // Remember that to use this, we have to declare the android.permission.WAKE_LOCK 
            // permission in AndroidManifest.xml. 
            mPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
 
            // we want the media player to notify us when it's ready preparing, and when it's done 
            // playing: 
            mPlayer.setOnPreparedListener(this);
            mPlayer.setOnCompletionListener(this);
            mPlayer.setOnErrorListener(this);
        } 

6
CodeRank

Related MediaPlayer setWakeMode Questions & Answers:

setWakeMode Method Overview
Set the low-level power management behavior for this MediaPlayer.
See Code Examples for other Android MediaPlayer Methods: