Skip to content

Commit

Permalink
Improve readLocalSongMetadata and LoudnessEnhancer creation error
Browse files Browse the repository at this point in the history
Improve error message on readLocalSongMetadata failure #244
Improve error message on failure to create LoudnessEnhancer #240
  • Loading branch information
toasterofbread committed Mar 3, 2024
1 parent 335ae3d commit 0c71665
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ actual val LocalSongMetadataProcessor: MetadataProcessor =
}
}
catch (e: Throwable) {
e.printStackTrace()
throw e
val error: Throwable = RuntimeException("Reading metadata failed for $file ${file.uri}", e)
error.printStackTrace()
throw error
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ actual class PlatformPlayerService: MediaSessionService(), PlayerService {
}

private val player_listener: Player.Listener = object : Player.Listener {
private fun createLoudnessEnhancer(): LoudnessEnhancer {
loudness_enhancer?.also {
return it
}

try {
loudness_enhancer = LoudnessEnhancer(player.audioSessionId)
return loudness_enhancer!!
}
catch (e: Throwable) {
throw RuntimeException("Creating loudness enhancer failed ${player.audioSessionId}", e)
}
}

override fun onMediaItemTransition(media_item: MediaItem?, reason: Int) {
val song: Song? = media_item?.getSong()
if (song?.id == current_song?.id) {
Expand All @@ -168,16 +182,12 @@ actual class PlatformPlayerService: MediaSessionService(), PlayerService {
current_song = song
updatePlayerCustomActions()

if (loudness_enhancer == null) {
loudness_enhancer = LoudnessEnhancer(player.audioSessionId)
}

loudness_enhancer?.update(song)
createLoudnessEnhancer().update(song)
}

override fun onAudioSessionIdChanged(audioSessionId: Int) {
loudness_enhancer?.release()
loudness_enhancer = LoudnessEnhancer(audioSessionId).apply {
createLoudnessEnhancer().apply {
update(current_song)
enabled = true
}
Expand Down

0 comments on commit 0c71665

Please sign in to comment.