Handle YouTube video errors (#1978)

This commit is contained in:
Elias Nahum 2018-08-08 14:24:47 -04:00 committed by GitHub
parent dabc24892f
commit 22455fe682
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 2 deletions

View file

@ -4,6 +4,7 @@
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import {
Alert,
Image,
Linking,
Platform,
@ -13,6 +14,7 @@ import {
View,
} from 'react-native';
import {YouTubeStandaloneAndroid, YouTubeStandaloneIOS} from 'react-native-youtube';
import {intlShape} from 'react-intl';
import ProgressiveImage from 'app/components/progressive_image';
@ -53,6 +55,10 @@ export default class PostBodyAdditionalContent extends PureComponent {
onLongPress: emptyFunction,
};
static contextTypes = {
intl: intlShape.isRequired,
};
constructor(props) {
super(props);
@ -348,7 +354,9 @@ export default class PostBodyAdditionalContent extends PureComponent {
const startTime = this.getYouTubeTime(link);
if (Platform.OS === 'ios') {
YouTubeStandaloneIOS.playVideo(videoId, startTime);
YouTubeStandaloneIOS.
playVideo(videoId, startTime).
catch(this.playYouTubeVideoError);
} else {
const {config} = this.props;
@ -358,13 +366,30 @@ export default class PostBodyAdditionalContent extends PureComponent {
videoId,
autoplay: true,
startTime,
});
}).catch(this.playYouTubeVideoError);
} else {
Linking.openURL(link);
}
}
};
playYouTubeVideoError = (errorMessage) => {
const {formatMessage} = this.context.intl;
Alert.alert(
formatMessage({
id: 'mobile.youtube_playback_error.title',
defaultMessage: 'YouTube playback error',
}),
formatMessage({
id: 'mobile.youtube_playback_error.description',
defaultMessage: 'An error occurred while trying to play the YouTube video.\nDetails: {details}',
}, {
details: errorMessage,
}),
);
};
render() {
const {link, openGraphData, postProps} = this.props;
const {linkLoadError} = this.state;

View file

@ -2631,6 +2631,8 @@
"mobile.video.save_error_title": "Save Video Error",
"mobile.video_playback.failed_description": "An error occurred while trying to play the video.\n",
"mobile.video_playback.failed_title": "Video playback failed",
"mobile.youtube_playback_error.title": "YouTube playback error",
"mobile.youtube_playback_error.description": "An error occurred while trying to play the YouTube video.\nDetails: {details}",
"modal.manual_status.ask": "Do not ask me again",
"modal.manual_status.auto_responder.message_": "Would you like to switch your status to \"{status}\" and disable Automatic Replies?",
"modal.manual_status.auto_responder.message_away": "Would you like to switch your status to \"Away\" and disable Automatic Replies?",