2

在 react-native-video 中,每当我在小于 50%(一半)的值上单击(自定义)进度条时,视频就会跳到开始而不是寻找正确的时间。当我点击 50% 以上时,它会变为 50%。它实际上不是 50,更像是 55-60,但无论如何。这真的很奇怪,在网上找不到任何东西!

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
4

2 回答 2

1
ffmpeg -i input.mp4 -force_key_frames "expr:gte(t,n_forced*1)"  output.mp4

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

于 2021-02-03T00:22:49.213 回答
1

我也面临同样的问题。每当我向后播放视频时,它都会向前播放。问题取决于视频格式。我使用的是 Webm 格式。现在mp4格式解决了这个问题。PS 抱歉回复晚了。

于 2019-12-30T12:33:33.450 回答