Merge pull request #2857 from iFeelSmart/fix/ensure_player_stop_on_invalid_url
Fix/ensure player stop on invalid url
This commit is contained in:
commit
6c84429a76
@ -2,12 +2,13 @@
|
||||
|
||||
### 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)
|
||||
- Sample: Add react-native-video controls support [#2852](https://github.com/react-native-video/react-native-video/pull/2852)
|
||||
- Android: Switch Google's maven repository to default `google()` [#2860](https://github.com/react-native-video/react-native-video/pull/2860)
|
||||
- Android: Implement focusable prop so the video view can toggle whether it is focusable for non-touch devices [#2819](https://github.com/react-native-video/react-native-video/issues/2819)
|
||||
- Fix iOS RCTSwiftLog naming collision [#2868](https://github.com/react-native-video/react-native-video/issues/2868)
|
||||
|
||||
### Version 6.0.0-alpha3
|
||||
### Version 6.0.0-alpha.3
|
||||
|
||||
- Fix ios build [#2854](https://github.com/react-native-video/react-native-video/pull/2854)
|
||||
|
||||
|
14
Video.js
14
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 || 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');
|
||||
|
@ -183,6 +183,8 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
|
||||
if (srcUri != null) {
|
||||
videoView.setRawSrc(srcUri, extension);
|
||||
}
|
||||
} else {
|
||||
videoView.clearSrc();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -390,11 +392,12 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
|
||||
}
|
||||
|
||||
private boolean startsWithValidScheme(String uriString) {
|
||||
return uriString.startsWith("http://")
|
||||
|| uriString.startsWith("https://")
|
||||
|| uriString.startsWith("content://")
|
||||
|| uriString.startsWith("file://")
|
||||
|| uriString.startsWith("asset://");
|
||||
String lowerCaseUri = uriString.toLowerCase();
|
||||
return lowerCaseUri.startsWith("http://")
|
||||
|| lowerCaseUri.startsWith("https://")
|
||||
|| lowerCaseUri.startsWith("content://")
|
||||
|| lowerCaseUri.startsWith("file://")
|
||||
|| lowerCaseUri.startsWith("asset://");
|
||||
}
|
||||
|
||||
private @ResizeMode.Mode int convertToIntDef(String resizeModeOrdinalString) {
|
||||
|
@ -68,6 +68,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',
|
||||
@ -247,8 +253,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 = () => {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user