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();
        } 
    } 
 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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;
	} 
} 
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE

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: