Player constructor

Player(
  1. Map<String, String> options, {
  2. bool initialize = true,
  3. bool videoOutput = false,
})

Implementation

Player(Map<String, String> options,
    {bool initialize = true, bool videoOutput = false}) {
  if (!Library.loaded) {
    if (!Library.flagFirst) {
      Library.init();
    } else {
      throw Exception('libmpv is not loaded!');
    }
  }
  ctx = Library.libmpv.mpv_create();
  for (var entry in options.entries) {
    final key = entry.key.toNativeUtf8();
    final value = entry.value.toNativeUtf8();
    int error =
        Library.libmpv.mpv_set_option_string(ctx, key.cast(), value.cast());
    if (error != mpv_error.MPV_ERROR_SUCCESS.value) {
      throw Exception(
        Library.libmpv.mpv_error_string(error).cast<Utf8>().toDartString(),
      );
    }
    calloc.free(key);
    calloc.free(value);
  }
  if (initialize) {
    init(videoOutput: videoOutput);
  }
}