mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-09-16 06:45:26 +02:00
perf(metadata): read complete SAF tags through descriptors
Add complete metadata reads with a display-name hint in Go and both native bridges. Read seekable SAF descriptors directly and use temporary copies only when direct reading fails. Add format parity tests for MP3, FLAC, M4A, and WAV plus a Dart bridge hint regression.
This commit is contained in:
@@ -1495,23 +1495,17 @@ class MainActivity: FlutterFragmentActivity() {
|
||||
}
|
||||
"readFileMetadata" -> {
|
||||
val filePath = call.argument<String>("file_path") ?: ""
|
||||
val displayName = call.argument<String>("display_name") ?: ""
|
||||
val response = withContext(Dispatchers.IO) {
|
||||
try {
|
||||
if (filePath.startsWith("content://")) {
|
||||
val uri = Uri.parse(filePath)
|
||||
val tempPath = copyUriToTemp(uri)
|
||||
?: return@withContext """{"error":"Failed to copy SAF file to temp"}"""
|
||||
try {
|
||||
Gobackend.readFileMetadata(tempPath)
|
||||
} finally {
|
||||
try { File(tempPath).delete() } catch (_: Exception) {}
|
||||
}
|
||||
readCompleteMetadataFromUri(Uri.parse(filePath), displayName)
|
||||
?.toString() ?: errorJson("Failed to read SAF metadata")
|
||||
} else {
|
||||
Gobackend.readFileMetadata(filePath)
|
||||
Gobackend.readFileMetadataWithHint(filePath, displayName)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("SpotiFLAC", "readFileMetadata failed: ${e.message}", e)
|
||||
"""{"error":${org.json.JSONObject.quote(e.message ?: "unknown")}}"""
|
||||
errorJson(e.message ?: "Failed to read metadata")
|
||||
}
|
||||
}
|
||||
result.success(response)
|
||||
|
||||
@@ -301,6 +301,13 @@ internal fun MainActivity.readAudioMetadataFromUri(
|
||||
obj.takeUnless { it.has("error") }
|
||||
}
|
||||
|
||||
internal fun MainActivity.readCompleteMetadataFromUri(
|
||||
uri: Uri,
|
||||
displayNameHint: String? = null,
|
||||
): JSONObject? = readMetadataFromUri(uri, displayNameHint) { path, name ->
|
||||
JSONObject(Gobackend.readFileMetadataWithHint(path, name)).takeUnless { it.has("error") }
|
||||
}
|
||||
|
||||
internal fun MainActivity.writeUriFromPath(uri: Uri, srcPath: String): Boolean {
|
||||
val srcFile = File(srcPath)
|
||||
if (!srcFile.exists()) return false
|
||||
|
||||
Reference in New Issue
Block a user