Skip to content

Commit

Permalink
fix: releaseAllVideos post 到主线程
Browse files Browse the repository at this point in the history
  • Loading branch information
br3ant committed Feb 4, 2021
1 parent dff8023 commit d6a8988
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 6 additions & 0 deletions library/src/main/java/cn/jzvd/JZMediaInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,10 @@ public JZMediaInterface(Jzvd jzvd) {
public abstract void setSpeed(float speed);

public abstract void setSurface(Surface surface);

public void runOnUiThread(Runnable runnable) {
if (handler != null) {
handler.post(runnable);
}
}
}
18 changes: 10 additions & 8 deletions library/src/main/java/cn/jzvd/Jzvd.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,20 @@ public void onAudioFocusChange(int focusChange) {
case AudioManager.AUDIOFOCUS_GAIN:
break;
case AudioManager.AUDIOFOCUS_LOSS:
CURRENT_JZVD.mediaInterface.handler.post(Jzvd::releaseAllVideos);
CURRENT_JZVD.mediaInterface.runOnUiThread(Jzvd::releaseAllVideos);
Log.d(TAG, "AUDIOFOCUS_LOSS [" + this.hashCode() + "]");
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
try {
Jzvd player = CURRENT_JZVD;
if (player != null && player.state == Jzvd.STATE_PLAYING) {
player.startButton.performClick();
CURRENT_JZVD.mediaInterface.runOnUiThread(() -> {
try {
Jzvd player = CURRENT_JZVD;
if (player != null && player.state == Jzvd.STATE_PLAYING) {
player.startButton.performClick();
}
} catch (IllegalStateException e) {
e.printStackTrace();
}
} catch (IllegalStateException e) {
e.printStackTrace();
}
});
Log.d(TAG, "AUDIOFOCUS_LOSS_TRANSIENT [" + this.hashCode() + "]");
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
Expand Down

0 comments on commit d6a8988

Please sign in to comment.