首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在react-native-video中使用seek的意外行为

在react-native-video中使用seek的意外行为
EN

Stack Overflow用户
提问于 2019-08-21 21:08:26
回答 2查看 2.1K关注 0票数 2

在react-native-video中,每当我点击(自定义)进度条上的值小于50% (一半)时,视频会跳转到开始,而不是寻找合适的时间。当我的点击率超过50%时,它就会上升到50%。实际上不是50,更像是55-60,但不管怎样。这真的很奇怪,我在网上找不到任何东西!

代码语言:javascript
复制
import Video from 'react-native-video';
import ProgressBar from "react-native-progress/Bar";


class Welcome extends React.Component {

  player;

  constructor(props) {
    super(props)
    //this.player = React.createRef();
    this.state = {
      paused: false,
      loaded: false,
      progress: 0,
      duration: 0,
      pressed:false,
      screenType: 'contain',
    };

    console.log("--- Screen --- Welcome")
  }

 componentDidMount = () => {
   setTimeout(() => {
     this.player.seek(8)
   },8000)
 }


   handleMainButtonTouch = () => {
     console.log("inside handleMainButtonTouch")
     console.log(this.state.progress)
     if (this.state.progress >= 1) {
       this.player.seek(0);
     }
     this.setState(state => {
       return {
         paused: !state.paused,
       };
     });
   };

   handleProgressPress = e => {
     const position = e.nativeEvent.locationX;
     const progress = parseFloat(position / 250) * this.state.duration;
     const isPlaying = !this.state.paused;

     this.player.seek(progress);
   };

   handleProgress = progress => {
     this.setState({
       progress: parseFloat(progress.currentTime) / parseFloat(this.state.duration),
     });

   };

   handleEnd = () => {
     this.setState({
       paused: true ,
       progress: 0 ,
     });
     this.player.seek(0);
   };

   handleLoad = meta => {
     this.setState({
       loaded: true,
       duration: meta.duration,
     });
   };

   handleFullScreen = () => {
     if (this.state.screenType == 'contain')
       this.setState({ screenType: 'cover' });
     else this.setState({ screenType: 'contain' });
   };


  render() {

      return (
        <View style={styles.container}>
          <View style={this.handleOuterViewStyle()}>

            <Video
              paused={this.state.paused}
              source={{uri: "https://res.cloudinary.com/dy6bbey4u/video/upload/v1565532579/fam/videos/sample.mp4"}}
              resizeMode={this.state.screenType}
              onLoad={this.handleLoad}
              onProgress={this.handleProgress}
              onEnd={this.handleEnd}
              ref={ref => {
                this.player = ref;
              }}
            />
            { this.state.loaded &&
              <View style={styles.controls}>
                <TouchableWithoutFeedback onPress={this.handleMainButtonTouch}>
                  <Text>Play</Text>
                </TouchableWithoutFeedback>
                <TouchableWithoutFeedback onPress={this.handleProgressPress}>
                  <View>
                    <ProgressBar
                      animated={false}
                      progress={this.state.progress}
                      color="#FFF"
                      borderColor="#FFF"
                      width={250}
                      height={20}
                    />
                  </View>
                </TouchableWithoutFeedback>
                <TouchableWithoutFeedback onPress={this.handleFullScreen}>
                  <Text style={styles.fullscreenButton}>Full</Text>
                </TouchableWithoutFeedback>
              </View>
            }
          </View>

        </View>
      )

  }
}

export default Welcome
EN

回答 2

Stack Overflow用户

发布于 2019-12-30 20:33:33

我也面临着同样的问题。每当我倒着看视频的时候,它就会往前走。问题取决于视频格式。我使用的是Webm格式。现在mp4格式解决了这个问题。另外,很抱歉回复得太晚了。

票数 1
EN

Stack Overflow用户

发布于 2021-02-03 08:22:49

代码语言:javascript
复制
ffmpeg -i input.mp4 -force_key_frames "expr:gte(t,n_forced*1)"  output.mp4

通过强制在视频中添加关键帧来解决。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57592417

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档