Fix crashing for song info

This commit is contained in:
h4h13 2020-02-01 23:44:04 +05:30
parent c35d86bfd6
commit 53e3eb2f41
2 changed files with 16 additions and 11 deletions

View file

@ -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))
}

View file

@ -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 "-"
}