setVolume method
Sets the playback volume of the Player. Defaults to 100.0
.
Implementation
@override
Future<void> setVolume(double volume, {bool synchronized = true}) {
Future<void> function() async {
if (disposed) {
throw AssertionError('[Player] has been disposed');
}
await waitForPlayerInitialization;
await waitForVideoControllerInitializationIfAttached;
{
final name = 'mute'.toNativeUtf8();
final value = calloc<Bool>();
mpv.mpv_get_property(
ctx,
name.cast(),
generated.mpv_format.MPV_FORMAT_FLAG,
value.cast(),
);
if (value.value) {
// Unmute the player before setting the volume.
final command = 'cycle mute'.toNativeUtf8();
mpv.mpv_command_string(
ctx,
command.cast(),
);
calloc.free(command);
}
calloc.free(name);
calloc.free(value);
}
{
final name = 'volume'.toNativeUtf8();
final value = calloc<Double>();
value.value = volume;
mpv.mpv_set_property(
ctx,
name.cast(),
generated.mpv_format.MPV_FORMAT_DOUBLE,
value.cast(),
);
calloc.free(name);
calloc.free(value);
}
}
if (synchronized) {
return lock.synchronized(function);
} else {
return function();
}
}