Code example for MediaPlayer

Methods: setOnCompletionListenersetOnErrorListenersetOnPreparedListenersetWakeMode

0
        if (this.mediaPlayer != null) {
            // The MediaPlayer object is already set up. We just reset it. 
            this.mediaPlayer.reset();
            return; 
        } 
        this.mediaPlayer = new MediaPlayer();
        // This means that the screen can go off, but the CPU has to stay running. 
        this.mediaPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
        // Various events we need to handle. 
        this.mediaPlayer.setOnPreparedListener(this);
        this.mediaPlayer.setOnCompletionListener(this);
        this.mediaPlayer.setOnErrorListener(this);
    } 
 
    /** 
     * Reconfigures MediaPlayer according to audio focus settings and starts/restarts it. 
     */ 
    void configAndStartMediaPlayer() { 
        if (this.focus == AudioFocus.NoFocusNoDuck) {
            // If we don't have audio focus and can't duck, we have to pause. 
Contextual code suggestions in your IDE  Get Codota for Java