Merge pull request #229 from lbryio/uri-encode-paths

Uri encode filenames with spaces for the media player
This commit is contained in:
Akinwale Ariwodola 2018-08-14 07:51:05 +01:00 committed by GitHub
commit 56a49e323a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -261,6 +261,12 @@ class MediaPlayer extends React.PureComponent {
return null; return null;
} }
getEncodedDownloadPath = (fileInfo) => {
const { file_name: fileName } = fileInfo;
const encodedFileName = encodeURIComponent(fileName).replace(/!/g, '%21');
return fileInfo.download_path.replace(new RegExp(fileName, 'g'), encodedFileName);
}
render() { render() {
const { backgroundPlayEnabled, fileInfo, thumbnail, onLayout, style } = this.props; const { backgroundPlayEnabled, fileInfo, thumbnail, onLayout, style } = this.props;
const completedWidth = this.getCurrentTimePercentage() * this.seekerWidth; const completedWidth = this.getCurrentTimePercentage() * this.seekerWidth;
@ -279,7 +285,7 @@ class MediaPlayer extends React.PureComponent {
return ( return (
<View style={styles} onLayout={onLayout}> <View style={styles} onLayout={onLayout}>
<Video source={{ uri: 'file:///' + fileInfo.download_path }} <Video source={{ uri: 'file:///' + this.getEncodedDownloadPath(fileInfo) }}
ref={(ref: Video) => { this.video = ref }} ref={(ref: Video) => { this.video = ref }}
resizeMode={this.state.resizeMode} resizeMode={this.state.resizeMode}
playInBackground={backgroundPlayEnabled} playInBackground={backgroundPlayEnabled}