fix(mpv): harden native initialization and logging
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'dart:async' show Completer;
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:plezy/mpv/models.dart';
|
||||
@@ -16,6 +18,41 @@ void main() {
|
||||
await SettingsService.getInstance();
|
||||
});
|
||||
|
||||
test('MPV coalesces concurrent Dart initialization requests', () async {
|
||||
final initialize = Completer<bool>();
|
||||
final calls = <MethodCall>[];
|
||||
|
||||
await withMockPlayerChannels(
|
||||
methodChannelName: 'com.plezy/mpv_player',
|
||||
eventChannelName: 'com.plezy/mpv_player/events',
|
||||
methodHandler: (call) {
|
||||
calls.add(call);
|
||||
if (call.method == 'initialize') return initialize.future;
|
||||
return Future.value(null);
|
||||
},
|
||||
testBody: () async {
|
||||
final player = PlayerNative();
|
||||
try {
|
||||
final logLevel = player.setLogLevel('warn');
|
||||
final command = player.command(['stop']);
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
|
||||
expect(calls.where((call) => call.method == 'initialize'), hasLength(1));
|
||||
|
||||
initialize.complete(true);
|
||||
await Future.wait([logLevel, command]);
|
||||
|
||||
expect(calls.where((call) => call.method == 'initialize'), hasLength(1));
|
||||
expect(calls.where((call) => call.method == 'setLogLevel'), hasLength(1));
|
||||
expect(calls.where((call) => call.method == 'command'), hasLength(1));
|
||||
} finally {
|
||||
if (!initialize.isCompleted) initialize.complete(true);
|
||||
await player.dispose();
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('Android command failure reaches seek recovery', () async {
|
||||
await withMockPlayerChannels(
|
||||
methodChannelName: 'com.plezy/mpv_player',
|
||||
@@ -64,6 +101,28 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
test('audio setLogLevel uses the dedicated native channel', () async {
|
||||
MethodCall? logLevelCall;
|
||||
await withMockPlayerChannels(
|
||||
methodChannelName: 'com.plezy/mpv_audio_player',
|
||||
eventChannelName: 'com.plezy/mpv_audio_player/events',
|
||||
methodHandler: (call) async {
|
||||
if (call.method == 'initialize') return true;
|
||||
if (call.method == 'setLogLevel') logLevelCall = call;
|
||||
return null;
|
||||
},
|
||||
testBody: () async {
|
||||
final player = PlayerNative.audio();
|
||||
try {
|
||||
await player.setLogLevel('v');
|
||||
expect(logLevelCall?.arguments, {'level': 'v'});
|
||||
} finally {
|
||||
await player.dispose();
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('Android mpv end-file error preserves native diagnostic message', () async {
|
||||
await withMockPlayerChannels(
|
||||
methodChannelName: 'com.plezy/mpv_player',
|
||||
|
||||
Reference in New Issue
Block a user