From 3f44d6ee253ab527ad914360079df2000a5c9563 Mon Sep 17 00:00:00 2001 From: olivier bouillet Date: Wed, 14 Sep 2022 21:57:37 +0200 Subject: [PATCH 1/8] fix: ensure player receive uri update event if the uri is empty --- Video.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Video.js b/Video.js index 287573a1..e068c84d 100644 --- a/Video.js +++ b/Video.js @@ -276,16 +276,20 @@ export default class Video extends Component { let uri = source.uri || ''; if (uri && uri.match(/^\//)) { uri = `file://${uri}`; - } else if (uri === '') { - return null; } if (!uri) { - console.warn('Trying to load empty source.'); + console.log('Trying to load empty source.'); } - const isNetwork = !!(uri && uri.match(/^https?:/)); - const isAsset = !!(uri && uri.match(/^(assets-library|ph|ipod-library|file|content|ms-appx|ms-appdata):/)); + const isNetwork = !!(uri && uri.match(/^https?:/i)); + const isAsset = !!(uri && uri.match(/^(assets-library|ph|ipod-library|file|content|ms-appx|ms-appdata):/i)); + + if (uri && !isNetwork && !isAsset) { + if (this.props.onError) { + this.props.onError({error: {errorString: 'invalid url, player will stop', errorCode: 'INVALID_URL'}}); + } + } let nativeResizeMode; const RCTVideoInstance = this.getViewManagerConfig('RCTVideo'); From f31e47f36007a3d75f76eb454b051597bd9d12df Mon Sep 17 00:00:00 2001 From: olivier bouillet Date: Wed, 14 Sep 2022 21:58:17 +0200 Subject: [PATCH 2/8] fix(exoplayer): ensure player is stopped when invalid uri is configured --- .../com/brentvatne/exoplayer/ReactExoplayerViewManager.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java index ce1d6a8c..cd9fc222 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java +++ b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java @@ -182,6 +182,8 @@ public class ReactExoplayerViewManager extends ViewGroupManager Date: Wed, 14 Sep 2022 21:58:39 +0200 Subject: [PATCH 3/8] fix(exoplayer): allow uri to high case --- .../exoplayer/ReactExoplayerViewManager.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java index cd9fc222..7b6f1dd4 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java +++ b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java @@ -386,11 +386,12 @@ public class ReactExoplayerViewManager extends ViewGroupManager Date: Wed, 14 Sep 2022 21:58:59 +0200 Subject: [PATCH 4/8] demo: update sample to support invalid uri --- examples/basic/src/VideoPlayer.android.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/basic/src/VideoPlayer.android.tsx b/examples/basic/src/VideoPlayer.android.tsx index ef53c752..727a463f 100644 --- a/examples/basic/src/VideoPlayer.android.tsx +++ b/examples/basic/src/VideoPlayer.android.tsx @@ -51,7 +51,7 @@ class VideoPlayer extends Component { require('./broadchurch.mp4'), { description: '(dash) sintel subtitles', - uri: 'https://bitmovin-a.akamaihd.net/content/sintel/sintel.mpd', + uri: 'Https://bitmovin-a.akamaihd.net/content/sintel/sintel.mpd', }, { description: '(mp4) big buck bunny', @@ -67,6 +67,12 @@ class VideoPlayer extends Component { 'http://www.youtube.com/api/manifest/dash/id/bf5bb2419360daf1/source/youtube?as=fmp4_audio_clear,fmp4_sd_hd_clear&sparams=ip,ipbits,expire,source,id,as&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=51AF5F39AB0CEC3E5497CD9C900EBFEAECCCB5C7.8506521BFC350652163895D4C26DEE124209AA9E&key=ik0', type: 'mpd', }, + { + description: 'invalid URL', + uri: + 'mmt://www.youtube.com', + type: 'mpd', + }, { description: '(no url) Stopped playback', uri: undefined }, { description: '(no view) no View', @@ -246,8 +252,8 @@ class VideoPlayer extends Component { } onError = (err: any) => { - console.log(JSON.stringify(err)) - this.toast(true, 'error: ' + err?.error?.code) + console.log(JSON.stringify(err?.error.errorCode)) + this.toast(true, 'error: ' + err?.error.errorCode) } onEnd = () => { From 32949120bfb9d979e02ae8f321b8cf6ee7e86622 Mon Sep 17 00:00:00 2001 From: olivier bouillet Date: Wed, 14 Sep 2022 22:05:43 +0200 Subject: [PATCH 5/8] chore: update changeLog --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 267f52b2..a197d0a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Changelog -### Version 6.0.0-alpha3 + +### Version 6.0.0-alpha.4 +- ensure src is always provided to native player even if it is invalid [#2857](https://github.com/react-native-video/react-native-video/pull/2857) + +### Version 6.0.0-alpha.3 - fix ios build [#2854](https://gthub.com/react-native-video/react-native-video/pull/2854) ### Version 6.0.0-alpha.2 From d67b3c45b5fc01c6e4c03b8e056eaf79f1accebe Mon Sep 17 00:00:00 2001 From: olivier bouillet Date: Sun, 2 Oct 2022 21:33:03 +0200 Subject: [PATCH 6/8] fix: improve initial test for checking url validity --- Video.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Video.js b/Video.js index e9ac1466..0a449e43 100644 --- a/Video.js +++ b/Video.js @@ -285,7 +285,7 @@ export default class Video extends Component { const isNetwork = !!(uri && uri.match(/^https?:/i)); const isAsset = !!(uri && uri.match(/^(assets-library|ph|ipod-library|file|content|ms-appx|ms-appdata):/i)); - if (uri && !isNetwork && !isAsset) { + if ((uri || uri === '') && !isNetwork && !isAsset) { if (this.props.onError) { this.props.onError({error: {errorString: 'invalid url, player will stop', errorCode: 'INVALID_URL'}}); } From c197271889031f2510d4c75eafb6bfc02557ff8b Mon Sep 17 00:00:00 2001 From: olivier bouillet Date: Sun, 2 Oct 2022 21:33:24 +0200 Subject: [PATCH 7/8] chore: revert strange url in sample --- examples/basic/src/VideoPlayer.android.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/basic/src/VideoPlayer.android.tsx b/examples/basic/src/VideoPlayer.android.tsx index dba99ac5..4b426ace 100644 --- a/examples/basic/src/VideoPlayer.android.tsx +++ b/examples/basic/src/VideoPlayer.android.tsx @@ -52,7 +52,7 @@ class VideoPlayer extends Component { require('./broadchurch.mp4'), { description: '(dash) sintel subtitles', - uri: 'Https://bitmovin-a.akamaihd.net/content/sintel/sintel.mpd', + uri: 'https://bitmovin-a.akamaihd.net/content/sintel/sintel.mpd', }, { description: '(mp4) big buck bunny', From 2efa746eed85eb2b4fd1df2e119b407d9fb1b9a2 Mon Sep 17 00:00:00 2001 From: olivier bouillet Date: Sun, 2 Oct 2022 21:33:53 +0200 Subject: [PATCH 8/8] fix(ios): ensure we stop playback on invalid or empty url --- ios/Video/RCTVideo.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ios/Video/RCTVideo.swift b/ios/Video/RCTVideo.swift index 47231a78..bc36d17d 100644 --- a/ios/Video/RCTVideo.swift +++ b/ios/Video/RCTVideo.swift @@ -219,6 +219,12 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH @objc func setSrc(_ source:NSDictionary!) { _source = VideoSource(source) + if (_source?.uri == nil || _source?.uri == "") { + DispatchQueue.global(qos: .default).async { + self._player?.replaceCurrentItem(with: nil) + } + return; + } removePlayerLayer() _playerObserver.player = nil _playerObserver.playerItem = nil