feat: improve metadata parsing and visualizer stability

- Enhance metadata extraction in `AudioHelper` by adding `VorbisComment` support and improving "Artist - Title" parsing for Icy streams.
- Implement thread safety in `ExtrasHelper` using a synchronization lock for native visualization and surface lifecycle management.
- Refactor visualizer update logic in `VisualizerFragment` to improve performance and error resilience.
- Remove redundant buffer position calls in `NativeAudioProcessor`.
- Clean up `AudioHelper` logic using Kotlin idiomatic patterns for string building and property access.
This commit is contained in:
2026-06-07 13:22:11 +02:00
parent 1b9858fc4d
commit 5644c97c4c
4 changed files with 64 additions and 41 deletions
@@ -27,12 +27,17 @@ class ExtrasHelper {
@JvmStatic
private external fun visualize(surface: Surface, data: FloatArray)
fun render(surface: Surface, data: FloatArray) {
if (!surface.isValid) return
try {
visualize(surface, data)
} catch (e: Exception) {
Log.e(TAG, "Native visualize failed", e)
private val renderLock = Any()
fun render(surface: Surface?, data: FloatArray) {
if (surface == null) return
synchronized(renderLock) {
if (!surface.isValid) return
try {
visualize(surface, data)
} catch (e: Exception) {
Log.e(TAG, "Native visualize failed", e)
}
}
}
}
@@ -97,22 +102,25 @@ class ExtrasHelper {
}
fun update(data: FloatArray) {
val s = surface
if (s != null && s.isValid) {
render(s, data)
}
render(surface, data)
}
override fun surfaceCreated(holder: SurfaceHolder) {
surface = holder.surface
synchronized(renderLock) {
surface = holder.surface
}
}
override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
surface = holder.surface
synchronized(renderLock) {
surface = holder.surface
}
}
override fun surfaceDestroyed(holder: SurfaceHolder) {
surface = null
synchronized(renderLock) {
surface = null
}
}
}
}