libmpv_dart
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 | ✓ |
Setup
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
How to use?
Generate a player instance(corresponding to mpv_handle)
import 'package:libmpv_dart/libmpv.dart' as mpv;
option={
"terminal":"yes",
"gapless-audio":"yes",
"log-file":logPath, //corresponding to mpv_set_option_string()
};
}
mpv.Player player = mpv.Player(option);
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.
credits
This project is based on open-source projects. Some of the source code has been adapted or reused from the following project: