libmpv_dart is a Dart binding for libmpv,aiming to provide Dart users with an efficient and convenient way to use libmpv.
a package that provides ability to access libmpv feature in dart application.
Platform | libmpv API | Video Render |
---|---|---|
Windows | ✓ | ✓ |
Linux | ✓ | |
macOS | ✓ | |
android | ✓ |
First,add libmpv_dart to your pubspec.yaml:
flutter pub add libmpv_dart
For windows/android users,run following command in your terminal:
dart run libmpv_dart:setup --platform windows
dart run libmpv_dart:setup --platform android
For linux users,all you need to do is install libmpv.
sudo apt install libmpv-dart
Generate a player instance(corresponding to mpv_handle)
// initial options for players
_player = Player(
{
'config': 'yes',
'input-default-bindings': 'yes',
},
videoOutput: true,
);
_player.setPropertyString('keep-open', 'yes');
then you can execute some command,for example.load a file:
player.command(["loadfile",inputPath]);
After all the jobs are done,destory the player to free memory:
player.destroy();
or you can wait for a mpv event:
while (true) {
Pointer<mpv_event> event = player.waitEvent(0);
if (event.ref.event_id == mpv_event_id.MPV_EVENT_SHUTDOWN) {
break;
} else if (event.ref.event_id == mpv_event_id.MPV_EVENT_END_FILE) {
break;
}
//wait until event happen.
}
This project is based on open-source projects. Some of the source code has been adapted or reused from the following project: