fix(android): apply dv conversion mode during init

This commit is contained in:
edde746
2026-05-18 20:32:34 +02:00
parent d85a622fbe
commit f4f2571168
3 changed files with 84 additions and 23 deletions
+69 -15
View File
@@ -1,3 +1,5 @@
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:plezy/mpv/mpv.dart';
@@ -32,6 +34,53 @@ void main() {
);
});
test('ExoPlayer applies DV conversion mode changed during in-flight initialization', () async {
final initialize = Completer<bool>();
final calls = <MethodCall>[];
await _withMockChannels(
methodChannelName: 'com.plezy/exo_player',
eventChannelName: 'com.plezy/exo_player/events',
methodHandler: (call) {
calls.add(call);
switch (call.method) {
case 'initialize':
return initialize.future;
case 'requestAudioFocus':
return Future.value(true);
default:
return Future.value(null);
}
},
testBody: () async {
final player = PlayerAndroid();
try {
final focusFuture = player.requestAudioFocus();
await Future<void>.delayed(Duration.zero);
final modeFuture = player.setProperty('dv-conversion-mode', 'hevc_strip');
await Future<void>.delayed(Duration.zero);
final initCall = calls.singleWhere((call) => call.method == 'initialize');
final initArgs = Map<Object?, Object?>.from(initCall.arguments as Map);
expect(initArgs['dvConversionMode'], 'auto');
expect(calls.where((call) => call.method == 'setDvConversionMode'), isEmpty);
initialize.complete(true);
await modeFuture;
await focusFuture;
final dvCall = calls.singleWhere((call) => call.method == 'setDvConversionMode');
final dvArgs = Map<Object?, Object?>.from(dvCall.arguments as Map);
expect(dvArgs['mode'], 'hevc_strip');
} finally {
if (!initialize.isCompleted) initialize.complete(true);
await player.dispose();
}
},
);
});
test('MPV clears stale Dart track state before opening new media', () async {
await _withMockChannels(
methodChannelName: 'com.plezy/mpv_player',
@@ -61,27 +110,32 @@ void main() {
Future<void> _withMockChannels({
required String methodChannelName,
required String eventChannelName,
Future<Object?> Function(MethodCall call)? methodHandler,
required Future<void> Function() testBody,
}) async {
final messenger = TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
final methodChannel = MethodChannel(methodChannelName);
final eventChannel = MethodChannel(eventChannelName);
messenger.setMockMethodCallHandler(methodChannel, (call) async {
switch (call.method) {
case 'initialize':
return true;
case 'observeProperty':
case 'setVisible':
case 'setProperty':
case 'command':
case 'open':
case 'dispose':
return null;
default:
return null;
}
});
messenger.setMockMethodCallHandler(
methodChannel,
methodHandler ??
(call) async {
switch (call.method) {
case 'initialize':
return true;
case 'observeProperty':
case 'setVisible':
case 'setProperty':
case 'command':
case 'open':
case 'dispose':
return null;
default:
return null;
}
},
);
messenger.setMockMethodCallHandler(eventChannel, (call) async => null);
try {