mirror of
https://github.com/Michatec/Radio.git
synced 2026-06-15 15:23:21 +02:00
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:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user