setAudioDevice method

  1. @override
Future<void> setAudioDevice(
  1. AudioDevice audioDevice, {
  2. bool synchronized = true,
})
override

Sets the current AudioDevice for audio output.

  • Currently selected AudioDevice can be accessed using state.audioDevice or stream.audioDevice.
  • The list of currently available AudioDevices can be obtained accessed using state.audioDevices or stream.audioDevices.

Implementation

@override
Future<void> setAudioDevice(AudioDevice audioDevice,
    {bool synchronized = true}) {
  Future<void> function() async {
    if (disposed) {
      throw AssertionError('[Player] has been disposed');
    }
    await waitForPlayerInitialization;
    await waitForVideoControllerInitializationIfAttached;

    final name = 'audio-device'.toNativeUtf8();
    final value = audioDevice.name.toNativeUtf8();
    mpv.mpv_set_property_string(
      ctx,
      name.cast(),
      value.cast(),
    );
    calloc.free(name);
    calloc.free(value);
  }

  if (synchronized) {
    return lock.synchronized(function);
  } else {
    return function();
  }
}