Please provide the following:
- SDK Version: 36.0.0
- Platforms(Android/iOS/web/all): Android/iOS
I’m having trouble understanding when shouldPlay should be true or false.
I have an app where I’ve basically copied the playlist example, of note is the fact that on clicking “Play”, I call this.playbackInstance.playAsync()
and on “Pause” I call this.playbackInstance.pauseAsync()
, and I understand that they set shouldPlay
to true and false, respectively. So why, when the playback catches up to the buffered amount, does shouldPlay
become false? I understanding isPlaying
becoming false, but I clicked Play earlier, so I expect it to play at the soonest possible frame when enough has buffered again. Instead, I have to click Play again because isPlaying=false
and shouldPlay
is false, and I don’t know if the user actually just paused playback or it paused because it is buffering. Is this thinking incorrect?
code, but heavily simplified. I can expand further if need be.
function _onPlaybackStatusUpdate(status) {
if (status.isLoaded) {
console.log(status)
setPlaybackInstancePosition(status.positionMillis)
setPlaybackInstanceDuration(status.durationMillis)
setShouldPlay(status.shouldPlay)
setIsPlaying(status.isPlaying)
setIsBuffering(status.isBuffering)
setRate(status.rate)
setVolume(status.volume)
if (status.didJustFinish && !status.isLooping) {
// maybe do something?
}
} else {
console.log("NOT YET")
console.log(status)
if (status.error) {
console.log(`FATAL PLAYER ERROR: ${status.error}`);
}
}
};
function togglePlay(){
if (shouldPlay){ //isPlaying or shouldPlay? originally was the former, but neither suffice.
playbackInstance.current.pauseAsync()
} else {
playbackInstance.current.playAsync()
}
}
return (
<TouchableOpacity
disabled={isLoading}
onPress={togglePlay}>
{shouldPlay ? //should this be isPlaying or shouldPlay? neither really suffice
<Icon
style={{height:25}}
type='FontAwesome'
name='pause'
color={isLoading ? 'grey' : 'white'}
size={24}
/>
:
<Icon
style={{height:25}}
type='FontAwesome'
name='play'
color={isLoading ? 'grey' : 'white'}
size={24}
/>
}
</TouchableOpacity>
<Video
ref={playbackInstance}
rate={rate}
volume={volume}
isMuted={false}
resizeMode='contain'
isLooping
useNativeControls={false}
style={{ height: 250}}
onPlaybackStatusUpdate={_onPlaybackStatusUpdate}
/>
{!props.playerPositionTop && buildPlayer(false)}
)