From e96c17321f1347818c1f5a38628d65b5b4bd5e7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20B=E1=BA=A3o=20Kh=C6=B0=C6=A1ng?= Date: Wed, 1 May 2024 16:31:20 +0700 Subject: [PATCH] fix(ios): destroy adsManager when player detach from super view (#3716) (#3722) * fix(ios): destroy adsManager when player detach from super view (#3716) * fix: swift format --- ios/Video/Features/RCTIMAAdsManager.swift | 10 ++++++++++ ios/Video/RCTVideo.swift | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/ios/Video/Features/RCTIMAAdsManager.swift b/ios/Video/Features/RCTIMAAdsManager.swift index 46a16b9e..26c6213e 100644 --- a/ios/Video/Features/RCTIMAAdsManager.swift +++ b/ios/Video/Features/RCTIMAAdsManager.swift @@ -44,6 +44,16 @@ } } + func releaseAds() { + guard let adsManager else { return } + // Destroy AdsManager may be delayed for a few milliseconds + // But what we want is it stopped producing sound immediately + // Issue found on tvOS 17, or iOS if view detach & STARTED event happen at the same moment + adsManager.volume = 0 + adsManager.pause() + adsManager.destroy() + } + // MARK: - Getters func getAdsLoader() -> IMAAdsLoader? { diff --git a/ios/Video/RCTVideo.swift b/ios/Video/RCTVideo.swift index cf73fb5b..0b1f430a 100644 --- a/ios/Video/RCTVideo.swift +++ b/ios/Video/RCTVideo.swift @@ -1187,6 +1187,10 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH _resouceLoaderDelegate = nil _playerObserver.clearPlayer() + #if USE_GOOGLE_IMA + _imaAdsManager.releaseAds() + #endif + self.removePlayerLayer() if let _playerViewController {