minor fixes
This commit is contained in:
parent
b34487f766
commit
2ba96c78b2
1 changed files with 25 additions and 18 deletions
|
@ -11,9 +11,9 @@ import 'package:media_kit_video/media_kit_video.dart';
|
||||||
|
|
||||||
class MpvVideoController extends AvesVideoController {
|
class MpvVideoController extends AvesVideoController {
|
||||||
late Player _instance;
|
late Player _instance;
|
||||||
late VideoController _controller;
|
|
||||||
late VideoStatus _status;
|
late VideoStatus _status;
|
||||||
bool _firstFrameRendered = false;
|
bool _firstFrameRendered = false;
|
||||||
|
final ValueNotifier<VideoController?> _controllerNotifier = ValueNotifier(null);
|
||||||
final List<StreamSubscription> _subscriptions = [];
|
final List<StreamSubscription> _subscriptions = [];
|
||||||
final StreamController<VideoStatus> _statusStreamController = StreamController.broadcast();
|
final StreamController<VideoStatus> _statusStreamController = StreamController.broadcast();
|
||||||
final StreamController<String?> _timedTextStreamController = StreamController.broadcast();
|
final StreamController<String?> _timedTextStreamController = StreamController.broadcast();
|
||||||
|
@ -82,6 +82,7 @@ class MpvVideoController extends AvesVideoController {
|
||||||
if (status == VideoStatus.idle) return;
|
if (status == VideoStatus.idle) return;
|
||||||
_statusStreamController.add(v ? VideoStatus.playing : VideoStatus.paused);
|
_statusStreamController.add(v ? VideoStatus.playing : VideoStatus.paused);
|
||||||
}));
|
}));
|
||||||
|
_subscriptions.add(_instance.stream.subtitle.listen((v) => _timedTextStreamController.add(v.isEmpty ? null : v[0])));
|
||||||
_subscriptions.add(_instance.stream.videoParams.listen((v) => sarNotifier.value = v.par));
|
_subscriptions.add(_instance.stream.videoParams.listen((v) => sarNotifier.value = v.par));
|
||||||
_subscriptions.add(_instance.stream.log.listen((v) => debugPrint('libmpv log: $v')));
|
_subscriptions.add(_instance.stream.log.listen((v) => debugPrint('libmpv log: $v')));
|
||||||
_subscriptions.add(_instance.stream.error.listen((v) => debugPrint('libmpv error: $v')));
|
_subscriptions.add(_instance.stream.error.listen((v) => debugPrint('libmpv error: $v')));
|
||||||
|
@ -115,16 +116,15 @@ class MpvVideoController extends AvesVideoController {
|
||||||
|
|
||||||
void _initController() {
|
void _initController() {
|
||||||
_firstFrameRendered = false;
|
_firstFrameRendered = false;
|
||||||
_controller = VideoController(
|
_controllerNotifier.value = VideoController(
|
||||||
_instance,
|
_instance,
|
||||||
configuration: VideoControllerConfiguration(
|
configuration: VideoControllerConfiguration(
|
||||||
enableHardwareAcceleration: settings.enableVideoHardwareAcceleration,
|
enableHardwareAcceleration: settings.enableVideoHardwareAcceleration,
|
||||||
),
|
),
|
||||||
);
|
)..waitUntilFirstFrameRendered.then((v) {
|
||||||
_controller.waitUntilFirstFrameRendered.then((v) {
|
_firstFrameRendered = true;
|
||||||
_firstFrameRendered = true;
|
_statusStreamController.add(_status);
|
||||||
_statusStreamController.add(_status);
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -191,7 +191,7 @@ class MpvVideoController extends AvesVideoController {
|
||||||
Stream<int> get positionStream => _instance.stream.position.map((pos) => pos.inMilliseconds);
|
Stream<int> get positionStream => _instance.stream.position.map((pos) => pos.inMilliseconds);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Stream<String?> get timedTextStream => _instance.stream.subtitle.map((v) => v.isEmpty ? null : v[0]);
|
Stream<String?> get timedTextStream => _timedTextStreamController.stream;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get isMuted => _instance.state.volume == 0;
|
bool get isMuted => _instance.state.volume == 0;
|
||||||
|
@ -218,16 +218,21 @@ class MpvVideoController extends AvesVideoController {
|
||||||
// derive DAR (Display Aspect Ratio) from SAR (Storage Aspect Ratio), if any
|
// derive DAR (Display Aspect Ratio) from SAR (Storage Aspect Ratio), if any
|
||||||
// e.g. 960x536 (~16:9) with SAR 4:3 should be displayed as ~2.39:1
|
// e.g. 960x536 (~16:9) with SAR 4:3 should be displayed as ~2.39:1
|
||||||
final dar = entry.displayAspectRatio * sar;
|
final dar = entry.displayAspectRatio * sar;
|
||||||
return Video(
|
return ValueListenableBuilder<VideoController?>(
|
||||||
controller: _controller,
|
valueListenable: _controllerNotifier,
|
||||||
fill: Colors.transparent,
|
builder: (context, controller, child) {
|
||||||
aspectRatio: dar,
|
if (controller == null) return const SizedBox();
|
||||||
controls: NoVideoControls,
|
return Video(
|
||||||
wakelock: false,
|
controller: controller,
|
||||||
subtitleViewConfiguration: const SubtitleViewConfiguration(
|
fill: Colors.transparent,
|
||||||
visible: false,
|
aspectRatio: dar,
|
||||||
),
|
controls: NoVideoControls,
|
||||||
);
|
wakelock: false,
|
||||||
|
subtitleViewConfiguration: const SubtitleViewConfiguration(
|
||||||
|
visible: false,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -334,6 +339,8 @@ class MpvVideoController extends AvesVideoController {
|
||||||
break;
|
break;
|
||||||
case MediaStreamType.text:
|
case MediaStreamType.text:
|
||||||
await _instance.setSubtitleTrack(SubtitleTrack.no());
|
await _instance.setSubtitleTrack(SubtitleTrack.no());
|
||||||
|
// remove current subtitle, if any
|
||||||
|
_timedTextStreamController.add(null);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue