mpv: sample aspect ratio
This commit is contained in:
parent
017264d2bc
commit
043b2c54aa
5 changed files with 44 additions and 35 deletions
|
@ -34,9 +34,9 @@ extension ExtraAvesEntryProps on AvesEntry {
|
|||
|
||||
bool get isSized => width > 0 && height > 0;
|
||||
|
||||
Size videoDisplaySize(double sar) {
|
||||
Size videoDisplaySize(double? sar) {
|
||||
final size = displaySize;
|
||||
if (sar != 1) {
|
||||
if (sar != null && sar != 1) {
|
||||
final dar = displayAspectRatio * sar;
|
||||
final w = size.width;
|
||||
final h = size.height;
|
||||
|
|
|
@ -197,7 +197,7 @@ class _EntryPageViewState extends State<EntryPageView> with SingleTickerProvider
|
|||
final videoController = context.read<VideoConductor>().getController(entry);
|
||||
if (videoController == null) return const SizedBox();
|
||||
|
||||
return ValueListenableBuilder<double>(
|
||||
return ValueListenableBuilder<double?>(
|
||||
valueListenable: videoController.sarNotifier,
|
||||
builder: (context, sar, child) {
|
||||
final videoDisplaySize = entry.videoDisplaySize(sar);
|
||||
|
|
|
@ -102,7 +102,7 @@ abstract class AvesVideoController {
|
|||
|
||||
ValueNotifier<bool> get canSelectStreamNotifier;
|
||||
|
||||
ValueNotifier<double> get sarNotifier;
|
||||
ValueNotifier<double?> get sarNotifier;
|
||||
|
||||
bool get isMuted;
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ class IjkVideoController extends AvesVideoController {
|
|||
final ValueNotifier<bool> canSelectStreamNotifier = ValueNotifier(false);
|
||||
|
||||
@override
|
||||
final ValueNotifier<double> sarNotifier = ValueNotifier(1);
|
||||
final ValueNotifier<double?> sarNotifier = ValueNotifier(null);
|
||||
|
||||
Stream<FijkValue> get _valueStream => _valueStreamController.stream;
|
||||
|
||||
|
@ -115,7 +115,7 @@ class IjkVideoController extends AvesVideoController {
|
|||
_startListening();
|
||||
}
|
||||
|
||||
sarNotifier.value = 1;
|
||||
sarNotifier.value = null;
|
||||
streams.clear();
|
||||
_applyOptions(startMillis);
|
||||
|
||||
|
@ -380,24 +380,25 @@ class IjkVideoController extends AvesVideoController {
|
|||
|
||||
@override
|
||||
Widget buildPlayerWidget(BuildContext context) {
|
||||
return ValueListenableBuilder<double>(
|
||||
valueListenable: sarNotifier,
|
||||
builder: (context, sar, child) {
|
||||
// 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
|
||||
final dar = entry.displayAspectRatio * sar;
|
||||
return FijkView(
|
||||
player: _instance,
|
||||
fit: FijkFit(
|
||||
sizeFactor: 1.0,
|
||||
aspectRatio: dar,
|
||||
alignment: _alignmentForRotation(entry.rotationDegrees),
|
||||
macroBlockCrop: _macroBlockCrop,
|
||||
),
|
||||
panelBuilder: (player, data, context, viewSize, texturePos) => const SizedBox(),
|
||||
color: Colors.transparent,
|
||||
);
|
||||
});
|
||||
return ValueListenableBuilder<double?>(
|
||||
valueListenable: sarNotifier,
|
||||
builder: (context, sar, child) {
|
||||
// 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
|
||||
final dar = entry.displayAspectRatio * (sar ?? 1);
|
||||
return FijkView(
|
||||
player: _instance,
|
||||
fit: FijkFit(
|
||||
sizeFactor: 1.0,
|
||||
aspectRatio: dar,
|
||||
alignment: _alignmentForRotation(entry.rotationDegrees),
|
||||
macroBlockCrop: _macroBlockCrop,
|
||||
),
|
||||
panelBuilder: (player, data, context, viewSize, texturePos) => const SizedBox(),
|
||||
color: Colors.transparent,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Alignment _alignmentForRotation(int rotation) {
|
||||
|
|
|
@ -37,7 +37,7 @@ class MpvVideoController extends AvesVideoController {
|
|||
final ValueNotifier<bool> canSelectStreamNotifier = ValueNotifier(false);
|
||||
|
||||
@override
|
||||
final ValueNotifier<double> sarNotifier = ValueNotifier(1);
|
||||
final ValueNotifier<double?> sarNotifier = ValueNotifier(null);
|
||||
|
||||
MpvVideoController(
|
||||
super.entry, {
|
||||
|
@ -81,6 +81,7 @@ class MpvVideoController extends AvesVideoController {
|
|||
if (status == VideoStatus.idle) return;
|
||||
_statusStreamController.add(v ? VideoStatus.playing : VideoStatus.paused);
|
||||
}));
|
||||
_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.error.listen((v) => debugPrint('libmpv error: $v')));
|
||||
_subscriptions.add(settings.updateStream.where((event) => event.key == SettingKeys.enableVideoHardwareAccelerationKey).listen((_) => _initController()));
|
||||
|
@ -203,16 +204,23 @@ class MpvVideoController extends AvesVideoController {
|
|||
|
||||
@override
|
||||
Widget buildPlayerWidget(BuildContext context) {
|
||||
// TODO TLAD handle SAR / DAR (media_kit Player.stream.width/height just gives raw video size, not rendered size)
|
||||
return Video(
|
||||
controller: _controller,
|
||||
fit: BoxFit.cover,
|
||||
alignment: Alignment.center,
|
||||
controls: NoVideoControls,
|
||||
wakelock: false,
|
||||
subtitleViewConfiguration: const SubtitleViewConfiguration(
|
||||
style: TextStyle(color: Colors.transparent),
|
||||
),
|
||||
return ValueListenableBuilder<double?>(
|
||||
valueListenable: sarNotifier,
|
||||
builder: (context, sar, child) {
|
||||
// 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
|
||||
final dar = entry.displayAspectRatio * (sar ?? 1);
|
||||
return Video(
|
||||
controller: _controller,
|
||||
fill: Colors.transparent,
|
||||
aspectRatio: dar,
|
||||
controls: NoVideoControls,
|
||||
wakelock: false,
|
||||
subtitleViewConfiguration: const SubtitleViewConfiguration(
|
||||
style: TextStyle(color: Colors.transparent),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue