mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-11-29 15:43:47 +01:00
feat(playback): spatial audio switch for the platform spatializer
A Spatial audio switch in Playback settings, on by default, in the Audio output group of both styles: after Skip silence on Android, after exclusive output on macOS, and in its own Audio output group on iOS. Windows and Linux have no row and no search entry. The app renders nothing; the switch only tells the platform whether it may spatialize. - media3: a new `setSpatialAudio` call maps to the audio attributes' spatialization behavior (auto or never). It applies live: the sink reopens its AudioTrack and drops its buffer, so native seeks to the current position to decode that audio again instead of skipping it. - Old Android engine: the fork takes `setSpatialAudio` on its player channel (no platform interface change) and sets the behavior on API 32+ as each source loads, so a change applies from the next song. The subtitle says so while the new engine is off. - iOS and macOS: the Darwin fork sets allowedAudioSpatializationFormats (iOS 14, macOS 11) to mono, stereo and multichannel or to none, on the current item and every new one. The subtitle ends with a live status line. Android reads the Spatializer (available, enabled, head tracker, and canBeSpatialized for stereo and 5.1) over a new event channel that re-reads on spatializer, head tracker and device changes and on resume. iOS reports whether the output port has spatial audio enabled, on route and spatial capability changes. The line names the direct USB and AAudio paths and macOS exclusive output, which never reach the system's spatial audio.
This commit is contained in:
1 parent
0a9eac574d
commit
a4a476e44e
35 files changed
+1408
-16
No files matched your search
@@ -436,6 +436,57 @@ void main() {
|
||||
expect(native.calls, isEmpty);
|
||||
});
|
||||
|
||||
test(
|
||||
'spatial audio off reaches the player before its first source',
|
||||
() async {
|
||||
addTearDown(() => playbackSpatialAudio.value = true);
|
||||
playbackSpatialAudio.value = false;
|
||||
await deck.setFileSource('/song.flac');
|
||||
final methods = native.methods;
|
||||
expect(
|
||||
methods.indexOf('setSpatialAudio'),
|
||||
lessThan(methods.indexOf('setSource')),
|
||||
);
|
||||
expect(native.last('setSpatialAudio'), {
|
||||
'playerId': 'one',
|
||||
'enabled': false,
|
||||
});
|
||||
|
||||
playbackSpatialAudio.value = true;
|
||||
await _settle();
|
||||
expect(native.last('setSpatialAudio'), {
|
||||
'playerId': 'one',
|
||||
'enabled': true,
|
||||
});
|
||||
expect(native.count('setSpatialAudio'), 2);
|
||||
},
|
||||
);
|
||||
|
||||
test('spatial audio is sent only when it differs from auto', () async {
|
||||
addTearDown(() => playbackSpatialAudio.value = true);
|
||||
await deck.setFileSource('/song.flac');
|
||||
expect(native.methods, isNot(contains('setSpatialAudio')));
|
||||
|
||||
playbackSpatialAudio.value = false;
|
||||
await _settle();
|
||||
expect(native.last('setSpatialAudio')['enabled'], isFalse);
|
||||
|
||||
// An older native player without the method keeps playing.
|
||||
native.replies['setSpatialAudio'] = (_) async =>
|
||||
throw MissingPluginException();
|
||||
playbackSpatialAudio.value = true;
|
||||
await _settle();
|
||||
await deck.resume();
|
||||
expect(native.count('play'), 1);
|
||||
});
|
||||
|
||||
test('a deck never created sends nothing for spatial audio', () async {
|
||||
addTearDown(() => playbackSpatialAudio.value = true);
|
||||
playbackSpatialAudio.value = false;
|
||||
await _settle();
|
||||
expect(native.calls, isEmpty);
|
||||
});
|
||||
|
||||
test('a disabled equalizer is never sent', () async {
|
||||
await deck.setFileSource('/song.flac');
|
||||
playbackEqualizer.value = const EqualizerSettings(preamp: 2);
|
||||
|
||||
@@ -890,6 +890,15 @@ void main() {
|
||||
expect(playbackSkipSilence.value, isFalse);
|
||||
});
|
||||
|
||||
test('spatial audio follows the setting for the decks', () {
|
||||
addTearDown(() => playbackSpatialAudio.value = true);
|
||||
final runtime = _runtime(isAndroid: true);
|
||||
runtime.configure(runtime.settings.copyWith(spatialAudio: false));
|
||||
expect(playbackSpatialAudio.value, isFalse);
|
||||
runtime.configure(runtime.settings.copyWith(spatialAudio: true));
|
||||
expect(playbackSpatialAudio.value, isTrue);
|
||||
});
|
||||
|
||||
test('changing the engine drops a song queued on the old one', () async {
|
||||
final deck = _QueuedDeck();
|
||||
final runtime = _runtime(
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mornye/services/music_playback_deck.dart';
|
||||
import 'package:mornye/services/playback_deck.dart';
|
||||
|
||||
/// The audioplayers deck sends the Spatial audio setting to both forks
|
||||
/// (Android's MediaPlayer wrapper and the Darwin AVPlayer wrapper).
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
final messenger =
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
|
||||
final calls = <MethodCall>[];
|
||||
|
||||
List<String> methods() => [for (final call in calls) call.method];
|
||||
List<Object?> spatial() => [
|
||||
for (final call in calls)
|
||||
if (call.method == 'setSpatialAudio') call.arguments,
|
||||
];
|
||||
|
||||
setUp(() {
|
||||
calls.clear();
|
||||
for (final name in [
|
||||
'xyz.luan/audioplayers.global',
|
||||
'xyz.luan/audioplayers.global/events',
|
||||
]) {
|
||||
messenger.setMockMethodCallHandler(
|
||||
MethodChannel(name),
|
||||
(_) async => null,
|
||||
);
|
||||
}
|
||||
messenger.setMockMethodCallHandler(
|
||||
const MethodChannel('xyz.luan/audioplayers'),
|
||||
(call) async {
|
||||
calls.add(call);
|
||||
final args = call.arguments as Map<Object?, Object?>;
|
||||
final id = args['playerId']! as String;
|
||||
if (call.method == 'create') {
|
||||
messenger.setMockMethodCallHandler(
|
||||
MethodChannel('xyz.luan/audioplayers/events/$id'),
|
||||
(_) async => null,
|
||||
);
|
||||
} else if (call.method == 'setSourceUrl') {
|
||||
unawaited(
|
||||
messenger.handlePlatformMessage(
|
||||
'xyz.luan/audioplayers/events/$id',
|
||||
const StandardMethodCodec().encodeSuccessEnvelope({
|
||||
'event': 'audio.onPrepared',
|
||||
'value': true,
|
||||
}),
|
||||
(_) {},
|
||||
),
|
||||
);
|
||||
} else if (call.method == 'getDuration') {
|
||||
return 60000;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
tearDown(() => playbackSpatialAudio.value = true);
|
||||
|
||||
test('the default sends nothing', () async {
|
||||
final deck = AudioplayersPlaybackDeck(
|
||||
playerId: 'spatial-default',
|
||||
spatialAudioAvailable: true,
|
||||
);
|
||||
await deck.setFileSource('/song.flac');
|
||||
expect(methods(), isNot(contains('setSpatialAudio')));
|
||||
await deck.dispose();
|
||||
});
|
||||
|
||||
test('off reaches the player before the source it applies to', () async {
|
||||
playbackSpatialAudio.value = false;
|
||||
final deck = AudioplayersPlaybackDeck(
|
||||
playerId: 'spatial-off',
|
||||
spatialAudioAvailable: true,
|
||||
);
|
||||
await deck.setFileSource('/song.flac');
|
||||
expect(spatial(), [
|
||||
{'playerId': 'spatial-off', 'enabled': false},
|
||||
]);
|
||||
expect(
|
||||
methods().indexOf('setSpatialAudio'),
|
||||
lessThan(methods().indexOf('setSourceUrl')),
|
||||
);
|
||||
// The next song needs nothing new.
|
||||
await deck.setFileSource('/next.flac');
|
||||
expect(spatial(), hasLength(1));
|
||||
await deck.dispose();
|
||||
});
|
||||
|
||||
test('a change is sent at once, for each value', () async {
|
||||
final deck = AudioplayersPlaybackDeck(
|
||||
playerId: 'spatial-live',
|
||||
spatialAudioAvailable: true,
|
||||
);
|
||||
await deck.setFileSource('/song.flac');
|
||||
playbackSpatialAudio.value = false;
|
||||
await Future<void>.delayed(const Duration(milliseconds: 20));
|
||||
playbackSpatialAudio.value = true;
|
||||
await Future<void>.delayed(const Duration(milliseconds: 20));
|
||||
expect(spatial(), [
|
||||
{'playerId': 'spatial-live', 'enabled': false},
|
||||
{'playerId': 'spatial-live', 'enabled': true},
|
||||
]);
|
||||
await deck.dispose();
|
||||
playbackSpatialAudio.value = false;
|
||||
await Future<void>.delayed(const Duration(milliseconds: 20));
|
||||
expect(spatial(), hasLength(2));
|
||||
});
|
||||
|
||||
test('a platform without the fork method sends nothing', () async {
|
||||
playbackSpatialAudio.value = false;
|
||||
final deck = AudioplayersPlaybackDeck(
|
||||
playerId: 'spatial-none',
|
||||
spatialAudioAvailable: false,
|
||||
);
|
||||
await deck.setFileSource('/song.flac');
|
||||
expect(methods(), isNot(contains('setSpatialAudio')));
|
||||
await deck.dispose();
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,451 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:mornye/l10n/app_localizations.dart';
|
||||
import 'package:mornye/models/settings.dart';
|
||||
import 'package:mornye/models/theme_settings.dart';
|
||||
import 'package:mornye/providers/settings_provider.dart';
|
||||
import 'package:mornye/screens/settings/playback_settings_page.dart';
|
||||
import 'package:mornye/services/music_playback_deck.dart';
|
||||
import 'package:mornye/services/spatial_audio.dart';
|
||||
import 'package:mornye/theme/app_theme.dart';
|
||||
import 'package:mornye/theme/mornye_theme.dart';
|
||||
import 'package:mornye/utils/desktop_platform.dart';
|
||||
import 'package:mornye/utils/settings_search_catalog.dart';
|
||||
import 'package:mornye/widgets/settings_group.dart';
|
||||
|
||||
const _title = 'Spatial audio';
|
||||
const _events = EventChannel('com.zarz.mornye/spatial_audio');
|
||||
|
||||
final _l10n = lookupAppLocalizations(const Locale('en'));
|
||||
|
||||
TestDefaultBinaryMessenger get _messenger =>
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
|
||||
|
||||
/// Answers a listen with [state], like the native stream does.
|
||||
void _mockState(Map<String, Object?> state) {
|
||||
_messenger.setMockStreamHandler(
|
||||
_events,
|
||||
MockStreamHandler.inline(onListen: (_, events) => events.success(state)),
|
||||
);
|
||||
addTearDown(() => _messenger.setMockStreamHandler(_events, null));
|
||||
}
|
||||
|
||||
Map<String, Object?> _android({
|
||||
bool available = true,
|
||||
bool enabled = true,
|
||||
bool headTracking = false,
|
||||
bool stereo = false,
|
||||
bool multichannel = false,
|
||||
}) => {
|
||||
'platform': 'android',
|
||||
'sdk': 34,
|
||||
'spatializer': {
|
||||
'available': available,
|
||||
'enabled': enabled,
|
||||
'headTracking': headTracking,
|
||||
'stereo': stereo,
|
||||
'multichannel': multichannel,
|
||||
},
|
||||
};
|
||||
|
||||
Future<ProviderContainer> _pumpPage(
|
||||
WidgetTester tester, {
|
||||
required bool mornye,
|
||||
AppSettings settings = const AppSettings(),
|
||||
}) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
tester.view.physicalSize = const Size(1200, 1600);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final container = ProviderContainer(
|
||||
overrides: [initialSettingsProvider.overrideWithValue(settings)],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
theme: mornye
|
||||
? MornyeTheme.build(Brightness.dark, accent: MornyeAccent.blue)
|
||||
: AppTheme.light(),
|
||||
locale: const Locale('en'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: const PlaybackSettingsPage(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
return container;
|
||||
}
|
||||
|
||||
Finder get _row => find.byWidgetPredicate(
|
||||
(widget) => widget is SettingsSwitchItem && widget.title == _title,
|
||||
);
|
||||
|
||||
Future<SettingsSwitchItem> _scrollToRow(WidgetTester tester) async {
|
||||
await tester.scrollUntilVisible(
|
||||
_row,
|
||||
300,
|
||||
scrollable: find.byType(Scrollable).first,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
return tester.widget<SettingsSwitchItem>(_row);
|
||||
}
|
||||
|
||||
void main() {
|
||||
tearDown(() {
|
||||
debugAndroidAudioSettingsOverride = null;
|
||||
debugSpatialAudioPlatformOverride = null;
|
||||
debugDesktopPlatformOverride = null;
|
||||
usbAudioStatus.value = const UsbAudioStatus();
|
||||
});
|
||||
|
||||
test('the setting defaults to on and round-trips through JSON', () {
|
||||
expect(const AppSettings().spatialAudio, isTrue);
|
||||
expect(AppSettings.fromJson(const {}).spatialAudio, isTrue);
|
||||
final off = const AppSettings().copyWith(spatialAudio: false);
|
||||
expect(off.toJson()['spatialAudio'], isFalse);
|
||||
expect(AppSettings.fromJson(off.toJson()).spatialAudio, isFalse);
|
||||
expect(off.copyWith().spatialAudio, isFalse);
|
||||
});
|
||||
|
||||
group('platform', () {
|
||||
test('mobile hosts are neither platform in tests', () {
|
||||
expect(spatialAudioPlatform, SpatialAudioPlatform.none);
|
||||
});
|
||||
|
||||
for (final (platform, expected) in [
|
||||
(TargetPlatform.macOS, SpatialAudioPlatform.macos),
|
||||
(TargetPlatform.windows, SpatialAudioPlatform.none),
|
||||
(TargetPlatform.linux, SpatialAudioPlatform.none),
|
||||
]) {
|
||||
test('desktop $platform is $expected', () {
|
||||
debugDesktopPlatformOverride = true;
|
||||
debugDefaultTargetPlatformOverride = platform;
|
||||
addTearDown(() => debugDefaultTargetPlatformOverride = null);
|
||||
expect(spatialAudioPlatform, expected);
|
||||
});
|
||||
}
|
||||
|
||||
test('settings search lists it except on Windows and Linux', () {
|
||||
bool listed({bool androidAudio = false}) => SettingsSearchCatalog(
|
||||
_l10n,
|
||||
androidAudio: androidAudio,
|
||||
).playback.any((entry) => entry.title == _l10n.spatialAudio);
|
||||
expect(listed(androidAudio: true), isTrue);
|
||||
expect(listed(), isFalse);
|
||||
debugSpatialAudioPlatformOverride = SpatialAudioPlatform.ios;
|
||||
expect(listed(), isTrue);
|
||||
debugSpatialAudioPlatformOverride = null;
|
||||
debugDesktopPlatformOverride = true;
|
||||
for (final (platform, shown) in [
|
||||
(TargetPlatform.macOS, true),
|
||||
(TargetPlatform.windows, false),
|
||||
(TargetPlatform.linux, false),
|
||||
]) {
|
||||
debugDefaultTargetPlatformOverride = platform;
|
||||
expect(listed(), shown, reason: '$platform');
|
||||
}
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
});
|
||||
});
|
||||
|
||||
group('state', () {
|
||||
test('reads the Android spatializer facts', () {
|
||||
final state = SpatialAudioState.fromMap(
|
||||
_android(headTracking: true, stereo: true, multichannel: true),
|
||||
);
|
||||
expect(state.platform, 'android');
|
||||
expect(state.available, isTrue);
|
||||
expect(state.enabled, isTrue);
|
||||
expect(state.headTracking, isTrue);
|
||||
expect(state.stereo, isTrue);
|
||||
expect(state.multichannel, isTrue);
|
||||
});
|
||||
|
||||
test('an Android release without a spatializer has none', () {
|
||||
final state = SpatialAudioState.fromMap(const {
|
||||
'platform': 'android',
|
||||
'sdk': 31,
|
||||
'spatializer': null,
|
||||
});
|
||||
expect(state.available, isFalse);
|
||||
expect(
|
||||
spatialAudioStatus(
|
||||
enabled: true,
|
||||
platform: SpatialAudioPlatform.android,
|
||||
state: state,
|
||||
),
|
||||
SpatialAudioStatus.unavailable,
|
||||
);
|
||||
});
|
||||
|
||||
test('reads the iOS output port', () {
|
||||
final state = SpatialAudioState.fromMap(const {
|
||||
'platform': 'ios',
|
||||
'enabled': true,
|
||||
});
|
||||
expect(state.enabled, isTrue);
|
||||
expect(state.available, isNull);
|
||||
});
|
||||
});
|
||||
|
||||
group('status', () {
|
||||
SpatialAudioStatus? android(
|
||||
Map<String, Object?> map, {
|
||||
bool enabled = true,
|
||||
UsbAudioStatus? usb,
|
||||
}) => spatialAudioStatus(
|
||||
enabled: enabled,
|
||||
platform: SpatialAudioPlatform.android,
|
||||
state: SpatialAudioState.fromMap(map),
|
||||
usb: usb,
|
||||
);
|
||||
|
||||
test('Android maps the spatializer to what it does', () {
|
||||
expect(
|
||||
android(_android(available: false, stereo: true)),
|
||||
SpatialAudioStatus.unavailable,
|
||||
);
|
||||
expect(
|
||||
android(_android(enabled: false, stereo: true)),
|
||||
SpatialAudioStatus.systemOff,
|
||||
);
|
||||
expect(android(_android(stereo: true)), SpatialAudioStatus.stereo);
|
||||
expect(
|
||||
android(_android(stereo: true, headTracking: true)),
|
||||
SpatialAudioStatus.stereoHeadTracking,
|
||||
);
|
||||
expect(
|
||||
android(_android(multichannel: true, headTracking: true)),
|
||||
SpatialAudioStatus.multichannelOnly,
|
||||
);
|
||||
expect(android(_android()), SpatialAudioStatus.unavailable);
|
||||
});
|
||||
|
||||
test('the direct Android outputs never reach the spatializer', () {
|
||||
final state = _android(stereo: true);
|
||||
expect(
|
||||
android(
|
||||
state,
|
||||
usb: const UsbAudioStatus(reason: 'active', driver: 'usb_direct'),
|
||||
),
|
||||
SpatialAudioStatus.directUsb,
|
||||
);
|
||||
expect(
|
||||
android(state, usb: const UsbAudioStatus(reason: 'active')),
|
||||
SpatialAudioStatus.directUsb,
|
||||
);
|
||||
expect(
|
||||
android(
|
||||
state,
|
||||
usb: const UsbAudioStatus(
|
||||
reason: 'active',
|
||||
driver: 'aaudio_exclusive',
|
||||
),
|
||||
),
|
||||
SpatialAudioStatus.directAAudio,
|
||||
);
|
||||
// Only a playing direct path counts.
|
||||
expect(
|
||||
android(state, usb: const UsbAudioStatus(reason: 'unsupported')),
|
||||
SpatialAudioStatus.stereo,
|
||||
);
|
||||
});
|
||||
|
||||
test('no status while the setting is off or nothing is known', () {
|
||||
expect(android(_android(stereo: true), enabled: false), isNull);
|
||||
expect(
|
||||
spatialAudioStatus(
|
||||
enabled: true,
|
||||
platform: SpatialAudioPlatform.android,
|
||||
),
|
||||
isNull,
|
||||
);
|
||||
expect(
|
||||
spatialAudioStatus(enabled: true, platform: SpatialAudioPlatform.none),
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
|
||||
test('iOS follows the output port', () {
|
||||
SpatialAudioStatus? ios(bool? on) => spatialAudioStatus(
|
||||
enabled: true,
|
||||
platform: SpatialAudioPlatform.ios,
|
||||
state: SpatialAudioState(platform: 'ios', enabled: on),
|
||||
);
|
||||
expect(ios(true), SpatialAudioStatus.outputOn);
|
||||
expect(ios(false), SpatialAudioStatus.outputOff);
|
||||
expect(ios(null), isNull);
|
||||
});
|
||||
|
||||
test('macOS names exclusive output only', () {
|
||||
SpatialAudioStatus? macos({required bool exclusive}) =>
|
||||
spatialAudioStatus(
|
||||
enabled: true,
|
||||
platform: SpatialAudioPlatform.macos,
|
||||
exclusiveOutput: exclusive,
|
||||
);
|
||||
expect(macos(exclusive: true), SpatialAudioStatus.exclusiveOutput);
|
||||
expect(macos(exclusive: false), isNull);
|
||||
});
|
||||
|
||||
test('every status has its message', () {
|
||||
expect(
|
||||
{
|
||||
for (final status in SpatialAudioStatus.values)
|
||||
status: spatialAudioStatusLabel(_l10n, status),
|
||||
},
|
||||
{
|
||||
SpatialAudioStatus.directUsb: 'Not used with direct USB output.',
|
||||
SpatialAudioStatus.directAAudio:
|
||||
'Not used with AAudio exclusive output.',
|
||||
SpatialAudioStatus.exclusiveOutput: 'Not used with exclusive output.',
|
||||
SpatialAudioStatus.systemOff:
|
||||
'Spatial audio is off in system settings.',
|
||||
SpatialAudioStatus.unavailable:
|
||||
'Not available on this device or output.',
|
||||
SpatialAudioStatus.stereo: 'Stereo music is spatialized.',
|
||||
SpatialAudioStatus.stereoHeadTracking:
|
||||
'Stereo music is spatialized, with head tracking available.',
|
||||
SpatialAudioStatus.multichannelOnly:
|
||||
'Only multichannel songs (such as 5.1 or Dolby Atmos) are '
|
||||
'spatialized on this device.',
|
||||
SpatialAudioStatus.outputOn: 'Spatial audio is on for this output.',
|
||||
SpatialAudioStatus.outputOff:
|
||||
'Not available with this output, or turned off in Control '
|
||||
'Center.',
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
for (final mornye in [false, true]) {
|
||||
testWidgets('Android shows the live status and turns it off ($mornye)', (
|
||||
tester,
|
||||
) async {
|
||||
debugAndroidAudioSettingsOverride = true;
|
||||
_mockState(_android(stereo: true, headTracking: true));
|
||||
final container = await _pumpPage(tester, mornye: mornye);
|
||||
var item = await _scrollToRow(tester);
|
||||
expect(item.value, isTrue);
|
||||
expect(item.subtitle, startsWith(_l10n.spatialAudioDescription));
|
||||
expect(
|
||||
item.subtitle,
|
||||
endsWith('Stereo music is spatialized, with head tracking available.'),
|
||||
);
|
||||
expect(item.subtitle, isNot(contains(_l10n.spatialAudioNextSong)));
|
||||
|
||||
usbAudioStatus.value = const UsbAudioStatus(
|
||||
reason: 'active',
|
||||
driver: 'usb_direct',
|
||||
);
|
||||
await tester.pump();
|
||||
item = tester.widget<SettingsSwitchItem>(_row);
|
||||
expect(item.subtitle, endsWith('Not used with direct USB output.'));
|
||||
|
||||
await tester.tap(find.text(_title));
|
||||
await tester.pumpAndSettle();
|
||||
expect(container.read(settingsProvider).spatialAudio, isFalse);
|
||||
item = tester.widget<SettingsSwitchItem>(_row);
|
||||
expect(item.value, isFalse);
|
||||
expect(item.subtitle, _l10n.spatialAudioDescription);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('the old Android engine applies it from the next song', (
|
||||
tester,
|
||||
) async {
|
||||
debugAndroidAudioSettingsOverride = true;
|
||||
_mockState(_android(enabled: false, stereo: true));
|
||||
await _pumpPage(
|
||||
tester,
|
||||
mornye: false,
|
||||
settings: const AppSettings(media3Engine: false),
|
||||
);
|
||||
final item = await _scrollToRow(tester);
|
||||
expect(item.enabled, isTrue);
|
||||
expect(
|
||||
item.subtitle,
|
||||
[
|
||||
_l10n.spatialAudioDescription,
|
||||
_l10n.spatialAudioNextSong,
|
||||
'Spatial audio is off in system settings.',
|
||||
].join('\n\n'),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('a state change updates the status line', (tester) async {
|
||||
debugAndroidAudioSettingsOverride = true;
|
||||
MockStreamHandlerEventSink? sink;
|
||||
_messenger.setMockStreamHandler(
|
||||
_events,
|
||||
MockStreamHandler.inline(
|
||||
onListen: (_, events) {
|
||||
sink = events;
|
||||
events.success(_android(multichannel: true));
|
||||
},
|
||||
),
|
||||
);
|
||||
addTearDown(() => _messenger.setMockStreamHandler(_events, null));
|
||||
await _pumpPage(tester, mornye: false);
|
||||
var item = await _scrollToRow(tester);
|
||||
expect(item.subtitle, endsWith(_l10n.spatialAudioMultichannelOnly));
|
||||
sink!.success(_android(available: false));
|
||||
await tester.pumpAndSettle();
|
||||
item = tester.widget<SettingsSwitchItem>(_row);
|
||||
expect(item.subtitle, endsWith(_l10n.spatialAudioUnavailable));
|
||||
});
|
||||
|
||||
for (final mornye in [false, true]) {
|
||||
testWidgets('iOS has its own Audio output group ($mornye)', (tester) async {
|
||||
debugSpatialAudioPlatformOverride = SpatialAudioPlatform.ios;
|
||||
_mockState(const {'platform': 'ios', 'enabled': false});
|
||||
await _pumpPage(tester, mornye: mornye);
|
||||
final item = await _scrollToRow(tester);
|
||||
expect(item.value, isTrue);
|
||||
expect(item.subtitle, endsWith(_l10n.spatialAudioOutputOff));
|
||||
expect(find.text(_l10n.newPlaybackEngine), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets(
|
||||
'macOS names exclusive output in the desktop group',
|
||||
variant: TargetPlatformVariant.only(TargetPlatform.macOS),
|
||||
(tester) async {
|
||||
debugDesktopPlatformOverride = true;
|
||||
await _pumpPage(
|
||||
tester,
|
||||
mornye: false,
|
||||
settings: const AppSettings(exclusiveOutput: true),
|
||||
);
|
||||
final item = await _scrollToRow(tester);
|
||||
expect(item.subtitle, endsWith('Not used with exclusive output.'));
|
||||
expect(item.showDivider, isFalse);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'Windows and Linux have no spatial audio row',
|
||||
variant: TargetPlatformVariant({
|
||||
TargetPlatform.windows,
|
||||
TargetPlatform.linux,
|
||||
}),
|
||||
(tester) async {
|
||||
debugDesktopPlatformOverride = true;
|
||||
await _pumpPage(tester, mornye: false);
|
||||
for (var i = 0; i < 10; i++) {
|
||||
await tester.drag(find.byType(Scrollable).first, const Offset(0, -600));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_row, findsNothing);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user