From 53e3eb2f419ee6bf84b09885a89ebd03e1e16acc Mon Sep 17 00:00:00 2001 From: h4h13 Date: Sat, 1 Feb 2020 23:44:04 +0530 Subject: [PATCH] Fix crashing for song info --- .../adapter/playlist/PlaylistAdapter.kt | 9 +++++---- .../fragments/base/AbsMusicServiceFragment.kt | 18 +++++++++++------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/playlist/PlaylistAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/playlist/PlaylistAdapter.kt index 70395660..28f11ab3 100755 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/playlist/PlaylistAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/adapter/playlist/PlaylistAdapter.kt @@ -2,6 +2,7 @@ package code.name.monkey.retromusic.adapter.playlist import android.graphics.Color import android.graphics.drawable.Drawable +import android.text.TextUtils import android.view.LayoutInflater import android.view.MenuItem import android.view.View @@ -62,15 +63,15 @@ class PlaylistAdapter( return createViewHolder(view) } - protected fun createViewHolder(view: View): ViewHolder { + fun createViewHolder(view: View): ViewHolder { return ViewHolder(view) } - protected fun getPlaylistTitle(playlist: Playlist): String { - return playlist.name + private fun getPlaylistTitle(playlist: Playlist): String { + return if (TextUtils.isEmpty(playlist.name)) "-" else playlist.name } - protected fun getPlaylistText(playlist: Playlist): String { + private fun getPlaylistText(playlist: Playlist): String { return MusicUtil.getPlaylistInfoString(activity, getSongs(playlist)) } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsMusicServiceFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsMusicServiceFragment.kt index 710e5fa8..12573abb 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsMusicServiceFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsMusicServiceFragment.kt @@ -75,13 +75,17 @@ open class AbsMusicServiceFragment : Fragment(), MusicServiceEventListener { fun getSongInfo(song: Song): String { val file = File(song.data) if (file.exists()) { - val audioHeader = AudioFileIO.read(File(song.data)).audioHeader - val string: StringBuilder = StringBuilder() - val uriFile = Uri.fromFile(file) - string.append(getMimeType(uriFile.toString())).append(" • ") - string.append(audioHeader.bitRate).append(" kb/s").append(" • ") - string.append(RetroUtil.frequencyCount(audioHeader.sampleRate.toInt())).append(" kHz") - return string.toString() + return try { + val audioHeader = AudioFileIO.read(File(song.data)).audioHeader + val string: StringBuilder = StringBuilder() + val uriFile = Uri.fromFile(file) + string.append(getMimeType(uriFile.toString())).append(" • ") + string.append(audioHeader.bitRate).append(" kb/s").append(" • ") + string.append(RetroUtil.frequencyCount(audioHeader.sampleRate.toInt())).append(" kHz") + string.toString() + } catch (er: Exception) { + " - " + } } return "-" }