Skip to content

Commit d83b9e2

Browse files
committed
fix #4211
Refactor: Optimize audio focus management Refined the audio focus handling logic. The player now checks if it is actively playing before pausing on audio focus loss. This prevents inactive players from incorrectly responding to focus changes. Additionally, audio focus is now requested when playback starts and properly released when the view is detached or videos are released. Also includes miscellaneous code cleanup and formatting.
1 parent b1c9c77 commit d83b9e2

File tree

1 file changed

+9
-4
lines changed
  • gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/video/base

1 file changed

+9
-4
lines changed

gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/video/base/GSYVideoView.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,11 @@ public void run() {
390390
if (GSYVideoView.this.mReleaseWhenLossAudio) {
391391
GSYVideoView.this.releaseVideos();
392392
} else {
393-
if (getGSYVideoManager().listener() != null)
394-
getGSYVideoManager().listener().onVideoPause();
393+
// 确保只有当前活跃的播放器才响应音频焦点变化
394+
GSYMediaPlayerListener listener = getGSYVideoManager().listener();
395+
if (listener != null && getGSYVideoManager().isPlaying()) {
396+
listener.onVideoPause();
397+
}
395398
}
396399
}
397400
});
@@ -403,8 +406,10 @@ public void run() {
403406
@Override
404407
public void onAudioFocusLossTransient() {
405408
try {
406-
if (getGSYVideoManager().listener() != null) {
407-
getGSYVideoManager().listener().onVideoPause();
409+
// 确保只有当前活跃的播放器才响应音频焦点变化
410+
GSYMediaPlayerListener listener = getGSYVideoManager().listener();
411+
if (listener != null && getGSYVideoManager().isPlaying()) {
412+
listener.onVideoPause();
408413
}
409414
} catch (Exception var2) {
410415
var2.printStackTrace();

0 commit comments

Comments
 (0)