setVolume method

  1. @override
Future<void> setVolume(
  1. double volume, {
  2. bool synchronized = true,
})
override

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 = '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();
  }
}