Files
SpotiFLAC-Mobile/test/playback_deck_selection_test.dart
T
zarzet bcb1ee8b90 feat(desktop): play through media_kit with MPRIS and SMTC sessions
Windows and Linux now create a libmpv deck through media_kit; macOS,
Android and iOS keep audioplayers. Without libmpv the runtime falls back
to audioplayers.

- The equalizer becomes one libavfilter graph behind mpv's lavfi filter
  (input gain, peaking bands, balance, compressor, -0.5 dBFS limiter)
  after a planar float conversion. Changes set the af property again.
  Filters a libmpv build lacks are probed once and left out; the input
  gain then moves to mpv's volume. Filter failures are reported per player.
- Deck volume is scaled by the in-app output volume on mpv's cubic curve,
  position updates run on a timer, DSD sources throw when libmpv cannot
  open them, and exclusive output has a hook for a later setting.
- The in-app output volume persists across launches on every desktop OS.
- Previews go through the runtime's preview deck, so desktop previews
  follow the in-app volume.
- Linux publishes MPRIS over D-Bus and Windows uses SMTC through
  smtc_windows, both driven by the audio handler.
- The Linux CI job installs libmpv-dev.
2026-10-20 16:55:01 +07:00

115 lines
3.9 KiB
Dart

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mornye/services/media_kit_playback_deck.dart';
import 'package:mornye/services/music_playback_deck.dart';
import 'package:mornye/services/music_player_runtime.dart';
import 'package:mornye/services/playback_deck.dart';
import 'package:mornye/utils/desktop_platform.dart';
import 'support/fake_mpv_engine.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
final messenger =
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
setUp(() {
for (final name in [
'xyz.luan/audioplayers',
'xyz.luan/audioplayers.global',
'xyz.luan/audioplayers.global/events',
]) {
messenger.setMockMethodCallHandler(MethodChannel(name), (call) async {
final arguments = call.arguments;
if (call.method == 'create' && arguments is Map) {
messenger.setMockMethodCallHandler(
MethodChannel(
'xyz.luan/audioplayers/events/${arguments['playerId']}',
),
(_) async => null,
);
}
return null;
});
}
MediaKitPlaybackDeck.debugEngineFactory = FakeMpvEngine.new;
});
tearDown(() {
debugDefaultTargetPlatformOverride = null;
debugDesktopPlatformOverride = null;
debugPlaybackEngineOverride = null;
MediaKitPlaybackDeck.debugAvailableOverride = null;
MediaKitPlaybackDeck.debugEngineFactory = null;
});
void select(TargetPlatform platform, {required bool desktop}) {
debugDefaultTargetPlatformOverride = platform;
debugDesktopPlatformOverride = desktop;
}
test('Windows and Linux play through media_kit', () {
for (final platform in [TargetPlatform.windows, TargetPlatform.linux]) {
select(platform, desktop: true);
expect(playbackEngine, PlaybackEngine.mediaKit, reason: '$platform');
}
});
test('macOS and mobile keep audioplayers', () {
select(TargetPlatform.macOS, desktop: true);
expect(playbackEngine, PlaybackEngine.audioplayers);
for (final platform in [TargetPlatform.android, TargetPlatform.iOS]) {
select(platform, desktop: false);
expect(playbackEngine, PlaybackEngine.audioplayers, reason: '$platform');
}
});
test('tests can force an engine on any host', () {
select(TargetPlatform.macOS, desktop: true);
debugPlaybackEngineOverride = PlaybackEngine.mediaKit;
expect(playbackEngine, PlaybackEngine.mediaKit);
});
test('the runtime creates the deck of the selected engine', () async {
const dependencies = PlaybackDependencies();
final created = <PlaybackDeck>[];
MediaKitPlaybackDeck.debugAvailableOverride = true;
try {
for (final platform in [TargetPlatform.windows, TargetPlatform.linux]) {
select(platform, desktop: true);
created
..add(dependencies.createDeck('main'))
..add(dependencies.createPreviewDeck('preview'));
expect(
created.reversed.take(2),
everyElement(isA<MediaKitPlaybackDeck>()),
);
}
select(TargetPlatform.macOS, desktop: true);
created.add(dependencies.createDeck('main'));
expect(created.last, isA<AudioplayersPlaybackDeck>());
select(TargetPlatform.android, desktop: false);
created
..add(dependencies.createDeck('main'))
..add(dependencies.createPreviewDeck('preview'));
expect(
created.reversed.take(2),
everyElement(isA<AudioplayersPlaybackDeck>()),
);
} finally {
for (final deck in created) {
await deck.dispose();
}
}
});
test('without libmpv Windows and Linux fall back to audioplayers', () async {
MediaKitPlaybackDeck.debugAvailableOverride = false;
select(TargetPlatform.linux, desktop: true);
final deck = const PlaybackDependencies().createDeck('main');
expect(deck, isA<AudioplayersPlaybackDeck>());
await deck.dispose();
});
}