Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: 6.3.0 iOS crash at RCTVideoUtils function #4181

Open
NguyenHoangMinhkkkk opened this issue Sep 19, 2024 · 4 comments · May be fixed by #4182
Open

[BUG]: 6.3.0 iOS crash at RCTVideoUtils function #4181

NguyenHoangMinhkkkk opened this issue Sep 19, 2024 · 4 comments · May be fixed by #4182
Labels
Accepted Issue is confirmed and accepted by maintainers team bug Missing info Some information from template are missing Newer Version Available Platform: iOS

Comments

@NguyenHoangMinhkkkk
Copy link

NguyenHoangMinhkkkk commented Sep 19, 2024

Version

6.3.0

What platforms are you having the problem on?

iOS

System Version

6.3.0

On what device are you experiencing the issue?

Real device, Simulator

Architecture

Old architecture

What happened?

I faced this issue while trying to open an .mkv video file from a Url that i dont know exaclty what is extension of file given.
and App error/crashes on iOS devices/simulators.

  • iOS 15 -> crash directly.
  • iOS 17 -> not crash but got onError ->
    "error": {
    "code": -11829,
    "localizedDescription": "Cannot Open",
    "localizedFailureReason": "This media may be damaged.",
    "domain": "AVFoundationErrorDomain",
    "localizedRecoverySuggestion": ""
    }

At file: react-native-video/ios/Video/Features/RCTVideoUtils.swift, at line 380
Need to check the url variable =! nil
image

Reproduction Link

repository link

Reproduction

Here the patch i'm temporary using for avoid crash issue. while waiting for upgrade place into lastest RNVideo in future

diff --git a/ios/Video/Features/RCTVideoUtils.swift b/ios/Video/Features/RCTVideoUtils.swift
index c13c4d94031f9adf728306e8d98942ca9973ad3c..0d22b0d51ab08954b4616d61752d4eb8ca8bd315 100644
--- a/ios/Video/Features/RCTVideoUtils.swift
+++ b/ios/Video/Features/RCTVideoUtils.swift
@@ -368,9 +368,14 @@ enum RCTVideoUtils {
             }
             let cookies: [AnyObject]! = HTTPCookieStorage.shared.cookies
             assetOptions.setObject(cookies, forKey: AVURLAssetHTTPCookiesKey as NSCopying)
-            asset = AVURLAsset(url: url!, options: assetOptions as! [String: Any])
+            // asset = AVURLAsset(url: url!, options: assetOptions as! [String: Any])
+            if(url != nil) {
+                asset = AVURLAsset(url: url!, options: assetOptions as! [String: Any])
+            }
         } else {
-            asset = AVURLAsset(url: url!)
+            if(url != nil) {
+                asset = AVURLAsset(url: url!)
+            }
         }
         return (asset, assetOptions)
      }
Copy link

Thank you for your issue report. Please note that the following information is missing or incomplete:

  • reproduction link

Please update your issue with this information to help us address it more effectively.

Note: issues without complete information have a lower priority

There is a newer version of the library available. You are using version 6.3.0, while the latest stable version is 6.6.1. Please update to the latest version and check if the issue still exists.

Note: If the issue still exists, please update the issue report with the latest information.

Copy link

Thank you for your issue report. Please note that the following information is missing or incomplete:

  • reproduction link

Please update your issue with this information to help us address it more effectively.

Note: issues without complete information have a lower priority

There is a newer version of the library available. You are using version 6.3.0, while the latest stable version is 6.6.1. Please update to the latest version and check if the issue still exists.

Note: If the issue still exists, please update the issue report with the latest information.

@freeboub
Copy link
Collaborator

@NguyenHoangMinhkkkk Can you please test this patch ? I think code is a bit cleaner...
BTW, Thank you for the investigation !

diff --git a/ios/Video/Features/RCTVideoUtils.swift b/ios/Video/Features/RCTVideoUtils.swift
index 703b35fb..e213fdda 100644
--- a/ios/Video/Features/RCTVideoUtils.swift
+++ b/ios/Video/Features/RCTVideoUtils.swift
@@ -364,9 +364,10 @@ enum RCTVideoUtils {
         guard let sourceUri = source.uri, sourceUri != "" else { return nil }
         var asset: AVURLAsset!
         let bundlePath = Bundle.main.path(forResource: source.uri, ofType: source.type) ?? ""
-        let url = source.isNetwork || source.isAsset
-            ? URL(string: source.uri ?? "")
-            : URL(fileURLWithPath: bundlePath)
+        guard let url = source.isNetwork || source.isAsset
+            ? URL(string: sourceUri)
+            : URL(fileURLWithPath: bundlePath) else { return nil }
+
         let assetOptions: NSMutableDictionary! = NSMutableDictionary()
 
         if source.isNetwork {
@@ -375,9 +376,9 @@ enum RCTVideoUtils {
             }
             let cookies: [AnyObject]! = HTTPCookieStorage.shared.cookies
             assetOptions.setObject(cookies as Any, forKey: AVURLAssetHTTPCookiesKey as NSCopying)
-            asset = AVURLAsset(url: url!, options: assetOptions as? [String: Any])
+            asset = AVURLAsset(url: url, options: assetOptions as? [String: Any])
         } else {
-            asset = AVURLAsset(url: url!)
+            asset = AVURLAsset(url: url)
         }
         return (asset, assetOptions)
     }

@freeboub freeboub added Accepted Issue is confirmed and accepted by maintainers team and removed Repro Provided labels Sep 19, 2024
@freeboub
Copy link
Collaborator

@NguyenHoangMinhkkkk I created a PR with that change & much more fixes where ! are used: https://github.com/TheWidlarzGroup/react-native-video/pull/4182/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Issue is confirmed and accepted by maintainers team bug Missing info Some information from template are missing Newer Version Available Platform: iOS
Projects
None yet
2 participants