视频开始时调用 react-native-video onEnd [英] react-native-video onEnd is called when video starts

查看:30
本文介绍了视频开始时调用 react-native-video onEnd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我 console.log() 在视频组件的 onEnd 函数中时,它会在页面加载时立即被调用.ThouchableHighlightonPress 中的 console.log() 也同时被调用.我使用了 repo react-native-router-flux 中的 Actions.videoPlayer() 单击此视频的缩略图即可转到此页面.

When I console.log() inside the onEnd function of a video component, it gets called instantly on load of the page. The console.log() from the onPress of ThouchableHighlight is also called at the same time. I used Actions.videoPlayer() from the repo react-native-router-flux to go to this page on click of the thumbnail of this video.

render() {
let video = require('../videos/HISTORISCHETUIN.mp4');

 return (
  <View>
    <TouchableHighlight onPress={console.log("Test")}>
      <View>
        <Video source={video}   // Can be a URL or a local file.
               ref={ref => this.player = ref} // Store reference
               rate={1.0}                     // 0 is paused, 1 is normal.
               volume={1.0}                   // 0 is muted, 1 is normal.
               muted={false}                  // Mutes the audio entirely.
               paused={true}                 // Pauses playback entirely.
               resizeMode="stretch"             // Fill the whole screen at aspect ratio.
               repeat={true}                  // Repeat forever.
               playInBackground={false}       // Audio continues to play when app entering background.
               playWhenInactive={false}       // [iOS] Video continues to play when control or notification center are shown.
               progressUpdateInterval={250.0} // [iOS] Interval to fire onProgress (default to ~250ms)
               onLoadStart={this.loadStart}   // Callback when video starts to load
               onLoad={() => {
                          this.player.seek(30);
                          }}      // Callback when video loads
               onProgress={this.setTime}      // Callback every ~250ms with currentTime
               onEnd={console.log("Test")}             // Callback when playback finishes
               onError={this.videoError}      // Callback when video cannot be loaded
               style={styles.video} />
      </View>
    </TouchableHighlight>
  </View>
)

}

为什么视频结束后不调用console.log()?当我按下视频时,它也没有任何反应.

Why doesn't it call console.log() after the video has ended? And when I press on the video it doesn't do anything either.

推荐答案

那是因为你需要将它包装在一个闭包中.

That's because you need to wrap it in a closure.

此代码:

onEnd={console.log('123')}

将在组件渲染时立即执行 console.log,当 prop 实际需要一个函数时.

Will immediately execute the console.log when the component is rendered, when the prop is actually expecting a function.

要修复它,请使用:

onEnd={() => console.log('123')}

这里你给 prop 一个它可以执行的函数,而不是 console.log 的结果.

Here you're giving the prop a function it can execute, rather than the result of console.log.

这篇关于视频开始时调用 react-native-video onEnd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆