React native 在react本机视频中使用seek时出现意外行为
在react native video中,每当我单击值小于50%(一半)的(自定义)进度条时,视频就会跳到开始,而不是寻找正确的时间。当我点击超过50%时,它会变成50%。实际上不是50岁,更像55-60岁,但不管怎样。这真的很奇怪,在网上找不到任何东西React native 在react本机视频中使用seek时出现意外行为,react-native,react-native-video,React Native,React Native Video,在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
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
从“react native Video”导入视频;
从“反应本机进度/Bar”导入进度栏;
类欢迎扩展React.Component{
玩家;
建造师(道具){
超级(道具)
//this.player=React.createRef();
此.state={
暂停:错,
加载:false,
进展:0,
持续时间:0,
答:错,,
屏幕类型:“包含”,
};
console.log(“---屏幕---欢迎”)
}
componentDidMount=()=>{
设置超时(()=>{
此.player.seek(8)
},8000)
}
handleMainButtonTouch=()=>{
console.log(“内把手mainbuttonouch”)
console.log(this.state.progress)
如果(this.state.progress>=1){
这个.player.seek(0);
}
this.setState(state=>{
返回{
暂停:!state.paused,
};
});
};
handleProgressPress=e=>{
const position=e.nativeEvent.locationX;
const progress=parseFloat(位置/250)*this.state.duration;
常量显示=!this.state.paused;
这个。玩家。寻求(进步);
};
handleProgress=进度=>{
这是我的国家({
进度:parseFloat(progress.currentTime)/parseFloat(this.state.duration),
});
};
handleEnd=()=>{
这是我的国家({
是的,
进展:0,
});
这个.player.seek(0);
};
handleLoad=meta=>{
这是我的国家({
是的,
持续时间:meta.duration,
});
};
handleFullScreen=()=>{
if(this.state.screenType=='contain')
this.setState({screenType:'cover'});
else这个.setState({screenType:'contain'});
};
render(){
返回(
{
this.player=ref;
}}
/>
{this.state.loaded&&
玩
满满的
}
)
}
}
导出默认欢迎
我也面临同样的问题。每当我向后看视频时,它就会向前看。问题在于视频格式不同。我使用的是Webm格式。现在mp4格式解决了这个问题。
顺便说一句,很抱歉回复晚了
ffmpeg -i input.mp4 -force_key_frames "expr:gte(t,n_forced*1)" output.mp4
通过强制向视频中添加关键帧来解决此问题。有时在“onSeek”中我也会遇到奇怪的seekTime:{currentTime:0,seekTime:-9223372036854776}这是因为格式吗?(它是.m3u8)