账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    react-native-video视频不显示
    58
    0

    用网上的例子测试可行
    constructor( props ) {

        super( props );
        this.state = {
          videoUrl: "http://124.129.157.208:8810/SD/2017qingdao/xiaoxueEnglish/grade3/b/1.mp4",
        };
    }

    <Video

    ref={(ref) => this.videoPlayer = ref}
    source={{uri: this.state.videoUrl}}
    rate={1.0}
    volume={1.0}
    muted={false}
    paused={!this.state.isPlaying}
    resizeMode={'contain'}
    onLoadStart={this._onLoadStart}
    onLoad={this._onLoaded}
    onProgress={this._onProgressChanged}
    onEnd={this._onPlayEnd}
    onError={this._onPlayError}
    onBuffer={this._onBuffering}
    style={{width: this.state.videoWidth, height: this.state.videoHeight}}

    />
    一旦将URL改成我自己的请求之后视频就不显示了
    videoUrl: "http://XXX.XXX.X.XXX:8004/resource/" + this.courseItem.video,(普通测试可用)
    是什么原因啊

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • VIP、首席╮ 普通会员 1楼

      在React Native中,如果你尝试播放一个视频但视频没有显示,可能是由于以下原因:

      1. 您的代码可能没有正确地加载视频。尝试使用 useEffect 替代 setTimeout 来在 componentDidMount 中加载视频。

      jsx useEffect(() => { fetchVideo().then(response => response.json()) .then(data => { this.setState({ videoData: data }); }) .catch(error => { console.error('Error loading video:', error); }); }, []);

      1. 视频加载失败时,尝试重新加载。例如,可以使用 componentDidMountcomponentDidUpdate 来在视频加载失败时重新加载。

      ```jsx componentDidMount() { setTimeout(() => { fetchVideo().then(response => response.json()) .then(data => { this.setState({ videoData: data }); }) .catch(error => { console.error('Error loading video:', error); }); }, 2000); // 在 2 秒后重新加载 }

      componentDidUpdate(prevProps) { if (prevProps.videoData !== this.state.videoData) { setTimeout(() => { fetchVideo().then(response => response.json()) .then(data => { this.setState({ videoData: data }); }) .catch(error => { console.error('Error loading video:', error); }); }, 2000); // 在 2 秒后重新加载 } } ```

      1. 确保您的视频 URL 是正确的。尝试检查视频 URL 是否正确,包括其中的分隔符、斜杠和问号。
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部