暫停並繼續播放

當使用者按一下廣告時,您的應用程式應暫停播放主要視訊內容。

  1. 從Android活動覆寫onPauseonResume

    @Override 
    public void onResume() { 
        super.onResume(); 
        requestAudioFocus(); 
        if (_lastKnownStatus == MediaPlayerStatus.PAUSED) { 
            _mediaPlayer.play(); 
        } 
    } 
    ... 
    
    @Override 
    public void onPause() { 
        super.onPause(); 
        if (_mediaPlayer != null) { 
            if (_mediaPlayer.getStatus() == MediaPlayerStatus.PLAYING || 
              _mediaPlayer.getStatus() == MediaPlayerStatus.PAUSED) { 
                _savedPlayerStatus = _mediaPlayer.getStatus(); 
                _lastKnownTime = _mediaPlayer.getCurrentTime(); 
            } 
            if (_mediaPlayer.getStatus() == MediaPlayerStatus.PLAYING) { 
                _mediaPlayer.pause(); 
                _lastKnownStatus = MediaPlayerStatus.PAUSED; 
            } 
        } 
    } 
    abandonAudioFocus(); 
    

本頁內容