mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-11-23 04:40:52 +01:00
fix(player): read deferred ReplayGain tags in audio info
This commit is contained in:
1 parent
82fbcda28a
commit
a325cb6ae0
4 files changed
+125
-11
No files matched your search
@@ -100,6 +100,13 @@ class PlayerMetadataController extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// Reads deferred file tags when opening technical details. Already loaded
|
||||
/// metadata, including online lyrics, stays cached for the current item.
|
||||
Future<void> ensureFileMetadata() async {
|
||||
if (_disposed || _item == null || _loadedPath != null) return;
|
||||
await load(_item, inspectUnresolvedContentUri: true);
|
||||
}
|
||||
|
||||
Future<void> load(
|
||||
MediaItem? item, {
|
||||
bool inspectUnresolvedContentUri = false,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:math' as math;
|
||||
|
||||
@@ -33,16 +34,19 @@ Future<void> showAudioInfoSheet(
|
||||
BuildContext context, {
|
||||
required PlayerMetadataController metadata,
|
||||
Map<String, String> linkSources = const {},
|
||||
}) => showAppScrollableBottomSheet<void>(
|
||||
context: context,
|
||||
title: context.l10n.audioInfoTitle,
|
||||
subtitle: metadata.qualityLabel,
|
||||
builder: (context, controller) => _AudioInfoSheet(
|
||||
metadata: metadata,
|
||||
controller: controller,
|
||||
linkSources: linkSources,
|
||||
),
|
||||
);
|
||||
}) {
|
||||
unawaited(metadata.ensureFileMetadata());
|
||||
return showAppScrollableBottomSheet<void>(
|
||||
context: context,
|
||||
title: context.l10n.audioInfoTitle,
|
||||
subtitle: metadata.qualityLabel,
|
||||
builder: (context, controller) => _AudioInfoSheet(
|
||||
metadata: metadata,
|
||||
controller: controller,
|
||||
linkSources: linkSources,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _AudioInfoSheet extends StatefulWidget {
|
||||
const _AudioInfoSheet({
|
||||
@@ -124,6 +128,7 @@ class _AudioInfoSheetState extends State<_AudioInfoSheet> {
|
||||
final facts = _AudioFacts(
|
||||
l10n: context.l10n,
|
||||
metadata: widget.metadata.metadata ?? const {},
|
||||
loading: widget.metadata.loading,
|
||||
path: widget.metadata.filePath,
|
||||
fileSize: _fileSize,
|
||||
route: _route,
|
||||
@@ -344,6 +349,7 @@ class _AudioFacts {
|
||||
_AudioFacts({
|
||||
required this.l10n,
|
||||
required this.metadata,
|
||||
required this.loading,
|
||||
required this.path,
|
||||
required this.fileSize,
|
||||
required this.route,
|
||||
@@ -356,6 +362,7 @@ class _AudioFacts {
|
||||
|
||||
final AppLocalizations l10n;
|
||||
final Map<String, dynamic> metadata;
|
||||
final bool loading;
|
||||
final String? path;
|
||||
final int? fileSize;
|
||||
final AudioRouteInfo? route;
|
||||
@@ -499,7 +506,10 @@ class _AudioFacts {
|
||||
}
|
||||
return [
|
||||
if (facts.isEmpty)
|
||||
_Fact(l10n.audioInfoTrackGain, l10n.audioInfoNoGainTags),
|
||||
_Fact(
|
||||
l10n.audioInfoTrackGain,
|
||||
loading ? l10n.linkFileReading : l10n.audioInfoNoGainTags,
|
||||
),
|
||||
...facts,
|
||||
_Fact(l10n.libraryPlaybackNormalization, normalization),
|
||||
];
|
||||
|
||||
@@ -3,10 +3,12 @@ import 'dart:async';
|
||||
import 'package:audio_service/audio_service.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:mornye/controllers/player_metadata_controller.dart';
|
||||
import 'package:mornye/l10n/app_localizations.dart';
|
||||
import 'package:mornye/services/audio_route_info.dart';
|
||||
import 'package:mornye/theme/mornye_theme.dart';
|
||||
import 'package:mornye/widgets/audio_info_sheet.dart';
|
||||
|
||||
const _route = MethodChannel('com.zarz.mornye/audio_route');
|
||||
@@ -141,6 +143,81 @@ void main() {
|
||||
expect(find.text('Network storage'), findsNothing);
|
||||
});
|
||||
|
||||
for (final mornye in [false, true]) {
|
||||
testWidgets(
|
||||
'SAF ReplayGain is loaded on opening Audio info (Mornye=$mornye)',
|
||||
(tester) async {
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(_route, (call) async => null);
|
||||
final tags = Completer<Map<String, dynamic>>();
|
||||
var reads = 0;
|
||||
final metadata = PlayerMetadataController(
|
||||
readMetadata: (path) {
|
||||
expect(path, 'content://library/Song.opus');
|
||||
reads++;
|
||||
return tags.future;
|
||||
},
|
||||
);
|
||||
addTearDown(metadata.dispose);
|
||||
await metadata.load(
|
||||
const MediaItem(
|
||||
id: 'song',
|
||||
title: 'Song',
|
||||
extras: {
|
||||
'source': 'content://library/Song.opus',
|
||||
'format': 'opus',
|
||||
'bitrate': 380,
|
||||
},
|
||||
),
|
||||
);
|
||||
expect(reads, 0, reason: 'Now Playing keeps SAF tag reads on demand');
|
||||
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
child: MaterialApp(
|
||||
theme: mornye ? MornyeTheme.build(Brightness.dark) : ThemeData(),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Builder(
|
||||
builder: (context) => TextButton(
|
||||
onPressed: () =>
|
||||
showAudioInfoSheet(context, metadata: metadata),
|
||||
child: const Text('open'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('open'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(reads, 1);
|
||||
expect(find.text('Reading tags...'), findsOneWidget);
|
||||
expect(find.text('No ReplayGain tags'), findsNothing);
|
||||
|
||||
tags.complete({
|
||||
'format': 'opus',
|
||||
'bitrate': 380,
|
||||
'replaygain_track_gain': '5.00 dB',
|
||||
'replaygain_track_peak': '0.326353',
|
||||
'replaygain_album_gain': '5.00 dB',
|
||||
'replaygain_album_peak': '0.326353',
|
||||
});
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('No ReplayGain tags'), findsNothing);
|
||||
expect(find.text('Reading tags...'), findsNothing);
|
||||
expect(find.text('+5.00 dB'), findsNWidgets(2));
|
||||
expect(find.textContaining('0.326353'), findsNWidgets(2));
|
||||
|
||||
Navigator.of(tester.element(find.text('Audio info'))).pop();
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('open'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(reads, 1, reason: 'Reopening the sheet reuses the loaded tags');
|
||||
expect(find.text('+5.00 dB'), findsNWidgets(2));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('late route replies cannot replace the latest track snapshot', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
@@ -293,6 +293,26 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
test('inspecting loaded stream tags preserves online lyrics', () async {
|
||||
final controller = PlayerMetadataController(
|
||||
readMetadata: (_) async => fail('Streams must not probe a local file'),
|
||||
parseLyrics: (raw) async => LyricsParser.parse(raw),
|
||||
fetchOnlineLyrics: (_) async => '[00:01.00]Online lyrics',
|
||||
);
|
||||
addTearDown(controller.dispose);
|
||||
await controller.load(
|
||||
_item(
|
||||
'stream',
|
||||
source: 'https://audio.test/song.opus',
|
||||
metadata: {'format': 'opus'},
|
||||
),
|
||||
);
|
||||
await controller.searchOnline();
|
||||
await controller.ensureFileMetadata();
|
||||
expect(controller.lyrics.lines.single.text, 'Online lyrics');
|
||||
expect(controller.qualityLabel, 'OPUS');
|
||||
});
|
||||
|
||||
test('details snapshot probes SAF without changing lyrics state', () async {
|
||||
final controller = PlayerMetadataController(
|
||||
readMetadata: (_) async => {
|
||||
|
||||
Reference in new issue
Block a user