Skip to content

Fix fullscreen player requiring two clicks to resume from paused state#4228

Merged
CarGuo merged 2 commits intomasterfrom
copilot/fix-fullscreen-playback-issue
Mar 6, 2026
Merged

Fix fullscreen player requiring two clicks to resume from paused state#4228
CarGuo merged 2 commits intomasterfrom
copilot/fix-fullscreen-playback-issue

Conversation

Copy link
Contributor

Copilot AI commented Mar 6, 2026

After pausing playback and entering fullscreen, the player required two clicks on the play button to resume — introduced in the "Request audio focus on resume from pause" change.

Root Cause

When the fullscreen player resumes from CURRENT_STATE_PAUSE, it calls start() then requestAudioFocus(). Since the original player still holds audio focus (not released on pause), Android fires AUDIOFOCUS_LOSS_TRANSIENT on the original player's manager. The callback then called getGSYVideoManager().listener().onVideoPause() — but listener() returns the fullscreen player (now the active listener), immediately re-pausing it.

Fix

Add a listener == GSYVideoView.this identity check in both onAudioFocusLoss() and onAudioFocusLossTransient() so a player only acts on focus loss when it is the current active listener:

// Before
if (listener != null && getGSYVideoManager().isPlaying()) {
    listener.onVideoPause();
}

// After
if (listener != null && listener == GSYVideoView.this && getGSYVideoManager().isPlaying()) {
    listener.onVideoPause();
}

This preserves correct behavior for all other scenarios (external app interruptions, fullscreen player itself being interrupted) while preventing a stale player's focus-loss callback from pausing its successor.

Original prompt

This section details on the original issue you should resolve

<issue_title>切换全屏之后需要按两下播放才能播放</issue_title>
<issue_description>点击暂停进入全屏,然后需要点击两下播放视频才能正常播放。</issue_description>

<agent_instructions>点击简单播放,选择简单列表1,然后点视频播放,点击暂停,再点击全屏,然后需要点击两下才开始播放。v10.2.1是没有问题的,v11.3.0才有这个问题。</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@CarGuo Demo哪里复现

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…tener identity in audio focus callbacks

Co-authored-by: CarGuo <10770362+CarGuo@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix playback issue after entering fullscreen mode Fix fullscreen player requiring two clicks to resume from paused state Mar 6, 2026
@CarGuo CarGuo marked this pull request as ready for review March 6, 2026 02:18
Copilot AI review requested due to automatic review settings March 6, 2026 02:18
@CarGuo CarGuo merged commit 3d4da96 into master Mar 6, 2026
3 checks passed
@CarGuo CarGuo deleted the copilot/fix-fullscreen-playback-issue branch March 6, 2026 02:18
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a regression where resuming playback in fullscreen after pausing requires two clicks, caused by a previous (non-active) player instance receiving an audio-focus loss callback and pausing the new fullscreen listener.

Changes:

  • Add an identity check (listener == GSYVideoView.this) before pausing on onAudioFocusLoss() to ensure only the active listener reacts.
  • Add the same identity check for onAudioFocusLossTransient() to prevent stale callbacks from pausing the fullscreen player.
  • Add inline comments explaining the fullscreen-switch audio focus edge case.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 410 to 414
// 确保只有当前活跃的播放器才响应音频焦点变化
// 防止全屏切换时,旧播放器的焦点丢失回调错误地暂停新的全屏播放器
GSYMediaPlayerListener listener = getGSYVideoManager().listener();
if (listener != null && getGSYVideoManager().isPlaying()) {
if (listener != null && listener == GSYVideoView.this && getGSYVideoManager().isPlaying()) {
listener.onVideoPause();
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The listener != null && listener == GSYVideoView.this check duplicates the existing isCurrentMediaListener() helper later in this class. Using the helper here would reduce duplication and keep the “current listener” definition consistent in one place.

Copilot uses AI. Check for mistakes.
Comment on lines 390 to +396
if (GSYVideoView.this.mReleaseWhenLossAudio) {
GSYVideoView.this.releaseVideos();
} else {
// 确保只有当前活跃的播放器才响应音频焦点变化
// 防止全屏切换时,旧播放器的焦点丢失回调错误地暂停新的全屏播放器
GSYMediaPlayerListener listener = getGSYVideoManager().listener();
if (listener != null && getGSYVideoManager().isPlaying()) {
if (listener != null && listener == GSYVideoView.this && getGSYVideoManager().isPlaying()) {
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says only the current active player responds to audio focus loss, but when mReleaseWhenLossAudio is true the code calls releaseVideos() without verifying this view is still the current GSYVideoManager listener. If an old (non-active) view instance still receives AUDIOFOCUS_LOSS, it could release the active playback. Consider guarding the release path with the same listener == this / isCurrentMediaListener() check (or adjust the comment to match behavior).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

切换全屏之后需要按两下播放才能播放

3 participants