首页 > 解决方案 > 视频预览(来自 react-native-video)未显示

问题描述

我按照文档进行了操作,但我无法弄清楚为什么视频没有播放。

console.log mp4 文件:这就是我在记录itemToPreview 时从相机中检索 mp4 文件的方式: file:///data/user/0/com.sentinel/cache/Camera/550b75a0-e1bd-4d0d-90ee-e8012a087e35.mp4 ,

然后我将它传递给视频源: source={{uri: 'itemToPreview'}}

请帮助我做错了什么?

onLoad = (data) => {
         //set duration
         this.setState({duration: data.duration});
     }
     onProgress = (data)=> {
         //set current time
         this.setState({currentTime: data.currentTime});
     }
    
     onEnd = ()=>{
         //set pausedText and paused, set video current time to 0
         this.setState({pausedText: 'Play', paused: true});
    
         this.video.seek(0);
     }
        render()
        {
            const { itemToPreview } = this.props.route.params;
            console.log("itemToPreview :"+ itemToPreview);
            return(
            <View style={styles.container}>
                <TouchableOpacity
                style={styles.fullScreen}
                onPress={()=> this.setState({paused: !this.state.paused})}
                >
                    <Video source={{uri: 'itemToPreview'}}
                        ref={(ref)=> {this.video = ref }}
                        style ={styles.fullScreen}
                        repeat={this.state.repeat}
                        rate={this.state.rate}
                        volume ={this.state.volume}
                        muted = {this.state.muted}
                        resizeMode={this.state.resizeMode}
                        paused = {this.state.paused}
                        onLoad ={this.onLoad}
                        onProgress = {this.onProgress}
                        onEnd = {this.onEnd}
                    />
    
                </TouchableOpacity>
             </View>
            );
    
        }
       
    }
    const styles = StyleSheet.create({
        container: {
            flex: 1,
            alignItems: 'center',
            justifyContent: 'center',
            backgroundColor: 'black'
        },
    
        text: {
            fontFamily: 'roboto',
            fontSize: 16,
            fontWeight: 'bold', 
        }, 
        fullScreen: {
            position: 'absolute',
            top: 0,
            left: 0,
            bottom: 0,
            right: 0,
        }

标签: react-native

解决方案


itemToPreview 是从参数中提取的变量,您将其用作字符串

尝试这个:

source={{uri: itemToPreview}}

推荐阅读