improve artist fetching in Properties
This commit is contained in:
parent
ae6c8762be
commit
db334fcc4a
3 changed files with 31 additions and 3 deletions
|
@ -113,13 +113,13 @@ class PropertiesDialog() {
|
|||
fileDirItem.path.isAudioSlow() -> {
|
||||
fileDirItem.getDuration(activity)?.let { addProperty(R.string.duration, it) }
|
||||
fileDirItem.getTitle(activity)?.let { addProperty(R.string.song_title, it) }
|
||||
fileDirItem.getArtist()?.let { addProperty(R.string.artist, it) }
|
||||
fileDirItem.getArtist(activity)?.let { addProperty(R.string.artist, it) }
|
||||
fileDirItem.getAlbum()?.let { addProperty(R.string.album, it) }
|
||||
}
|
||||
fileDirItem.path.isVideoSlow() -> {
|
||||
fileDirItem.getDuration(activity)?.let { addProperty(R.string.duration, it) }
|
||||
fileDirItem.getResolution(activity)?.let { addProperty(R.string.resolution, it.formatAsResolution()) }
|
||||
fileDirItem.getArtist()?.let { addProperty(R.string.artist, it) }
|
||||
fileDirItem.getArtist(activity)?.let { addProperty(R.string.artist, it) }
|
||||
fileDirItem.getAlbum()?.let { addProperty(R.string.album, it) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -759,6 +759,34 @@ fun Context.getTitle(path: String): String? {
|
|||
}
|
||||
}
|
||||
|
||||
fun Context.getArtist(path: String): String? {
|
||||
val projection = arrayOf(
|
||||
Audio.Media.ARTIST
|
||||
)
|
||||
|
||||
val uri = getFileUri(path)
|
||||
val selection = if (path.startsWith("content://")) "${BaseColumns._ID} = ?" else "${MediaColumns.DATA} = ?"
|
||||
val selectionArgs = if (path.startsWith("content://")) arrayOf(path.substringAfterLast("/")) else arrayOf(path)
|
||||
|
||||
try {
|
||||
val cursor = contentResolver.query(uri, projection, selection, selectionArgs, null)
|
||||
cursor?.use {
|
||||
if (cursor.moveToFirst()) {
|
||||
return cursor.getStringValue(Audio.Media.ARTIST)
|
||||
}
|
||||
}
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
|
||||
return try {
|
||||
val retriever = MediaMetadataRetriever()
|
||||
retriever.setDataSource(path)
|
||||
retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST)
|
||||
} catch (ignored: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.getStringsPackageName() = getString(R.string.package_name)
|
||||
|
||||
fun Context.getFontSizeText() = getString(when (baseConfig.fontSize) {
|
||||
|
|
|
@ -117,7 +117,7 @@ open class FileDirItem(val path: String, val name: String = "", var isDirectory:
|
|||
|
||||
fun getFileDurationSeconds(context: Context) = context.getDuration(path)
|
||||
|
||||
fun getArtist() = path.getFileArtist()
|
||||
fun getArtist(context: Context) = context.getArtist(path)
|
||||
|
||||
fun getAlbum() = path.getFileAlbum()
|
||||
|
||||
|
|
Loading…
Reference in a new issue