perf(metadata): avoid SAF copies during quality probes

This commit is contained in:
zarzet
2026-07-28 01:50:41 +07:00
parent 26570792a9
commit 80d9d87870
7 changed files with 186 additions and 3 deletions
+20
View File
@@ -6,6 +6,7 @@ import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:spotiflac_android/services/download_request_payload.dart';
import 'package:spotiflac_android/utils/audio_format_utils.dart';
import 'package:spotiflac_android/utils/logger.dart';
final _log = AppLogger('PlatformBridge');
@@ -833,6 +834,25 @@ class PlatformBridge {
return _invokeMap('readFileMetadata', {'file_path': filePath});
}
/// Reads the tags and quality fields used for automatic Library display.
///
/// Android's readAudioMetadata implementation can inspect most SAF files
/// through /proc/self/fd, avoiding the full-file cache copy required by tag
/// editing. Keep the complete reader as a compatibility fallback for
/// malformed or incorrectly named files that the lightweight scanner could
/// only identify from their filename.
static Future<Map<String, dynamic>> readDisplayAudioMetadata(
String filePath,
) async {
final scanned = await readAudioMetadata(filePath);
if (scanned != null &&
scanned['error'] == null &&
scanned['metadataFromFilename'] != true) {
return normalizeScannedAudioMetadata(scanned);
}
return readFileMetadata(filePath);
}
static Future<Map<String, dynamic>> editFileMetadata(
String filePath,
Map<String, String> metadata,