Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@
"@jridgewell/sourcemap-codec" "^1.4.14"

"@jwplayer/jwplayer-react-native@../../jwplayer-react-native":
version "1.3.1"
version "1.3.2"
dependencies:
lodash.isequalwith "^4.4.0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ public class RNJWPlayerView extends RelativeLayout implements
// Add completion handler field
PlaylistItemDecision itemUpdatePromise = null;

// Flag to prevent race conditions during player destruction
private volatile boolean isDestroying = false;

private void doBindService() {
if (mMediaServiceController != null) {
if (!isBackgroundAudioServiceRunning()) {
Expand Down Expand Up @@ -380,7 +383,22 @@ public Lifecycle getLifecycle() {
// }

public void destroyPlayer() {
if (mPlayer != null) {
if (mPlayer != null && !isDestroying) {
isDestroying = true;

// Disable touch events immediately to prevent race conditions
if (mPlayerView != null) {
Handler mainHandler = new Handler(Looper.getMainLooper());
mainHandler.post(() -> {
if (mPlayerView != null) {
mPlayerView.setClickable(false);
mPlayerView.setFocusable(false);
mPlayerView.setEnabled(false);
mPlayerView.setOnTouchListener(null);
}
});
}

unRegisterReceiver();

// If we are casting we need to break the cast session as there is no simple
Expand Down Expand Up @@ -480,6 +498,8 @@ public void destroyPlayer() {
audioManager = null;

doUnbindService();

isDestroying = false; // Reset flag for potential reuse
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.jwplayer.rnjwplayer;

import android.util.Log;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.common.MapBuilder;
Expand Down Expand Up @@ -43,7 +45,14 @@ public void setControls(RNJWPlayerView view, Boolean controls) {
if (view == null || view.mPlayerView == null) {
return;
}
view.mPlayerView.getPlayer().setControls(controls);
// Add null check for getPlayer() to prevent crashes
try {
if (view.mPlayerView.getPlayer() != null) {
view.mPlayerView.getPlayer().setControls(controls);
}
} catch (Exception e) {
Log.w(TAG, "Error setting controls: " + e.getMessage());
}
}

/**
Expand All @@ -58,8 +67,15 @@ public void recreatePlayerWithConfig(RNJWPlayerView view, ReadableMap config) {
if (view == null || view.mPlayerView == null) {
return;
}
view.mPlayerView.getPlayer().stop();
view.setConfig(config);
// Add null check for getPlayer() to prevent crashes
try {
if (view.mPlayerView.getPlayer() != null) {
view.mPlayerView.getPlayer().stop();
}
view.setConfig(config);
} catch (Exception e) {
Log.w(TAG, "Error recreating player: " + e.getMessage());
}
}

public Map getExportedCustomBubblingEventTypeConstants() {
Expand Down