The expo-video-player repo with custom control has been very helpful to me (this is the link of the repo I based from). I was wondering how can I make a function where I can do something when the video ends (like alert "The video ends").
代码:这是我到目前为止尝试的:
const updatePlaybackCallback = (status: AVPlaybackStatus) => {
props.playbackCallback(status)
if (status.didJustFinish){
alert('END!');
}
}
return (
<View style={styles.container}>
<VideoPlayer
videoProps={{
shouldPlay: false,
resizeMode: Video.RESIZE_MODE_COVER,
source: {
uri: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
},
ref: refVideo2,
}}
onPlaybackStatusUpdate={updatePlaybackCallback}
fullscreen={{
inFullscreen: isFullscreen,
enterFullscreen: async () => {
setStatusBarHidden(true, 'fade')
setFullscreen(true)
await ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE_RIGHT)
},
exitFullscreen: async () => {
setStatusBarHidden(false, 'fade')
setFullscreen(false)
await ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.DEFAULT)
},
}}
style={{
videoBackgroundColor: 'black',
height: isFullscreen ? Dimensions.get('window').width : 160,
width: isFullscreen ? Dimensions.get('window').height : 320,
}}
/>
</View>
我也尝试了这些,但没有任何作用:
_onPlaybackStatusUpdate = playbackStatus => {
if (playbackStatus.durationMillis === playbackStatus.positionMillis)
alert('END!')
console.log('end')
};
return (
<View style={styles.container}>
<VideoPlayer
videoProps={{
shouldPlay: false,
resizeMode: Video.RESIZE_MODE_COVER,
source: {
uri: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
},
ref: refVideo2,
}}
onPlaybackStatusUpdate={(playbackStatus) => this._onPlaybackStatusUpdate(playbackStatus)}
和
_onPlaybackStatusUpdate = playbackStatus => {
if (playbackStatus.didJustFinish)
alert('END!');
};
return (
<View style={styles.container}>
<VideoPlayer
videoProps={{
shouldPlay: false,
resizeMode: Video.RESIZE_MODE_COVER,
source: {
uri: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
},
ref: refVideo2,
}}
onPlaybackStatusUpdate={(playbackStatus) => this._onPlaybackStatusUpdate(playbackStatus)}