Fix crashing for song info
This commit is contained in:
parent
c35d86bfd6
commit
53e3eb2f41
2 changed files with 16 additions and 11 deletions
|
@ -2,6 +2,7 @@ package code.name.monkey.retromusic.adapter.playlist
|
||||||
|
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
|
import android.text.TextUtils
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
@ -62,15 +63,15 @@ class PlaylistAdapter(
|
||||||
return createViewHolder(view)
|
return createViewHolder(view)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun createViewHolder(view: View): ViewHolder {
|
fun createViewHolder(view: View): ViewHolder {
|
||||||
return ViewHolder(view)
|
return ViewHolder(view)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun getPlaylistTitle(playlist: Playlist): String {
|
private fun getPlaylistTitle(playlist: Playlist): String {
|
||||||
return playlist.name
|
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))
|
return MusicUtil.getPlaylistInfoString(activity, getSongs(playlist))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,13 +75,17 @@ open class AbsMusicServiceFragment : Fragment(), MusicServiceEventListener {
|
||||||
fun getSongInfo(song: Song): String {
|
fun getSongInfo(song: Song): String {
|
||||||
val file = File(song.data)
|
val file = File(song.data)
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
val audioHeader = AudioFileIO.read(File(song.data)).audioHeader
|
return try {
|
||||||
val string: StringBuilder = StringBuilder()
|
val audioHeader = AudioFileIO.read(File(song.data)).audioHeader
|
||||||
val uriFile = Uri.fromFile(file)
|
val string: StringBuilder = StringBuilder()
|
||||||
string.append(getMimeType(uriFile.toString())).append(" • ")
|
val uriFile = Uri.fromFile(file)
|
||||||
string.append(audioHeader.bitRate).append(" kb/s").append(" • ")
|
string.append(getMimeType(uriFile.toString())).append(" • ")
|
||||||
string.append(RetroUtil.frequencyCount(audioHeader.sampleRate.toInt())).append(" kHz")
|
string.append(audioHeader.bitRate).append(" kb/s").append(" • ")
|
||||||
return string.toString()
|
string.append(RetroUtil.frequencyCount(audioHeader.sampleRate.toInt())).append(" kHz")
|
||||||
|
string.toString()
|
||||||
|
} catch (er: Exception) {
|
||||||
|
" - "
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return "-"
|
return "-"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue