Skip to content

Commit

Permalink
Merge pull request #796 from default-anton/native-player-get-property
Browse files Browse the repository at this point in the history
feat: add getProperty to NativePlayer
  • Loading branch information
alexmercerind committed Apr 30, 2024
2 parents 9cf7d62 + ffa345c commit 7775f8b
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions media_kit/lib/src/player/native/player/real.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,33 @@ class NativePlayer extends PlatformPlayer {
calloc.free(data);
}

/// Retrieves the value of a property from the internal libmpv instance of this [Player].
/// Please use this method only if you know what you are doing, existing methods in [Player] implementation are suited for the most use cases.
///
/// See:
/// * https://mpv.io/manual/master/#options
/// * https://mpv.io/manual/master/#properties
///
Future<String> getProperty(String property) async {
if (disposed) {
throw AssertionError('[Player] has been disposed');
}
await waitForPlayerInitialization;
await waitForVideoControllerInitializationIfAttached;

final name = property.toNativeUtf8();
final value = mpv.mpv_get_property_string(ctx, name.cast());
if (value != nullptr) {
final result = value.cast<Utf8>().toDartString();
calloc.free(name);
mpv.mpv_free(value.cast());

return result;
}

return "";
}

/// Observes property for the internal libmpv instance of this [Player].
/// Please use this method only if you know what you are doing, existing methods in [Player] implementation are suited for the most use cases.
///
Expand Down

0 comments on commit 7775f8b

Please sign in to comment.