diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/NsdDiscoveryListener.java b/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/NsdDiscoveryListener.java index 905dcb67f86bc8..1a9556e5fdb6d2 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/NsdDiscoveryListener.java +++ b/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/NsdDiscoveryListener.java @@ -109,6 +109,7 @@ public void onDiscoveryStopped(String serviceType) { @Override public void onStartDiscoveryFailed(String serviceType, int errorCode) { Log.e(TAG, "Discovery failed to start: Error code:" + errorCode); + TvCastingApp.getInstance().resetDiscoveryState(); failureCallback.handle( new MatterError( 3, "NsdDiscoveryListener Discovery failed to start: Nsd Error code:" + errorCode)); diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TvCastingApp.java b/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TvCastingApp.java index a846ffcb7ee9a2..24852986768e7c 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TvCastingApp.java +++ b/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TvCastingApp.java @@ -297,6 +297,17 @@ public void stopVideoPlayerDiscovery() { } } + void resetDiscoveryState() { + synchronized (discoveryLock) { + Log.d(TAG, "TvCastingApp resetting discovery state"); + this.discoveryStarted = false; + this.nsdDiscoveryListener = null; + if (multicastLock != null && multicastLock.isHeld()) { + multicastLock.release(); + } + } + } + public native boolean openBasicCommissioningWindow( int duration, CommissioningCallbacks commissioningCallbacks,