playOrPause method
Future<void>
playOrPause(
{ - bool notify = true,
- bool synchronized = true,
})
override
Cycles between play & pause states of the Player.
Implementation
@override
Future<void> playOrPause({
bool notify = true,
bool synchronized = true,
}) {
Future<void> function() async {
if (disposed) {
throw AssertionError('[Player] has been disposed');
}
await waitForPlayerInitialization;
await waitForVideoControllerInitializationIfAttached;
if (notify) {
// Do not change the [state.playing] value if [playOrPause] was called from [play] or [pause]; where the [state.playing] value is already changed.
state = state.copyWith(
playing: !state.playing,
);
if (!playingController.isClosed) {
playingController.add(state.playing);
}
}
isPlayingStateChangeAllowed = true;
isBufferingStateChangeAllowed = false;
// This condition is specifically for the case when the internal playlist is ended (with [PlaylistLoopMode.none]), and we want to play the playlist again if play/pause is pressed.
if (state.completed) {
final name = 'playlist-pos'.toNativeUtf8();
final value = calloc<Int64>()..value = 0;
mpv.mpv_set_property(
ctx,
name.cast(),
generated.mpv_format.MPV_FORMAT_INT64,
value.cast(),
);
calloc.free(name);
calloc.free(value);
}
final command = 'cycle pause'.toNativeUtf8();
mpv.mpv_command_string(
ctx,
command.cast(),
);
calloc.free(command);
}
if (synchronized) {
return lock.synchronized(function);
} else {
return function();
}
}