add artist and album to audios and videos if available

This commit is contained in:
tibbi 2016-10-16 23:44:46 +02:00
parent 85a6507641
commit 72ac444ceb
8 changed files with 32 additions and 1 deletions

View File

@ -41,9 +41,13 @@ class PropertiesDialog() {
addProperty(R.string.resolution, file.getImageResolution())
} else if (file.isAudio()) {
addProperty(R.string.duration, file.getDuration())
addProperty(R.string.artist, file.getArtist())
addProperty(R.string.album, file.getAlbum())
} else if (file.isVideo()) {
addProperty(R.string.duration, file.getDuration())
addProperty(R.string.resolution, file.getVideoResolution())
addProperty(R.string.artist, file.getArtist())
addProperty(R.string.album, file.getAlbum())
}
AlertDialog.Builder(context)
@ -76,7 +80,10 @@ class PropertiesDialog() {
.show()
}
private fun addProperty(labelId: Int, value: String) {
private fun addProperty(labelId: Int, value: String?) {
if (value == null)
return
val view = mInflater.inflate(R.layout.property_item, mPropertyView, false)
view.property_label.text = mResources.getString(labelId)
view.property_value.text = value

View File

@ -36,6 +36,18 @@ fun File.getDuration(): String {
return getFormattedDuration((timeInMillisec / 1000).toInt())
}
fun File.getArtist(): String? {
val retriever = MediaMetadataRetriever()
retriever.setDataSource(path)
return retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST)
}
fun File.getAlbum(): String? {
val retriever = MediaMetadataRetriever()
retriever.setDataSource(path)
return retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM)
}
fun File.getVideoResolution(): String {
try {
val retriever = MediaMetadataRetriever()

View File

@ -44,6 +44,8 @@
<string name="files_count">Total files count</string>
<string name="resolution">Resolution</string>
<string name="duration">Duration</string>
<string name="artist">Artist</string>
<string name="album">Album</string>
<plurals name="items_deleted">
<item quantity="one">1 Datei/Ordner gelöscht</item>

View File

@ -44,6 +44,8 @@
<string name="files_count">Total files count</string>
<string name="resolution">Resolution</string>
<string name="duration">Duration</string>
<string name="artist">Artist</string>
<string name="album">Album</string>
<plurals name="items_deleted">
<item quantity="one">1 elemento eliminato</item>

View File

@ -44,6 +44,8 @@
<string name="files_count">Total files count</string>
<string name="resolution">Resolution</string>
<string name="duration">Duration</string>
<string name="artist">Artist</string>
<string name="album">Album</string>
<plurals name="items_deleted">
<item quantity="one">1 アイテムを削除しました</item>

View File

@ -44,6 +44,8 @@
<string name="files_count">Total files count</string>
<string name="resolution">Resolution</string>
<string name="duration">Duration</string>
<string name="artist">Artist</string>
<string name="album">Album</string>
<plurals name="items_deleted">
<item quantity="one">1 item eliminado</item>

View File

@ -44,6 +44,8 @@
<string name="files_count">Total files count</string>
<string name="resolution">Resolution</string>
<string name="duration">Duration</string>
<string name="artist">Artist</string>
<string name="album">Album</string>
<plurals name="items_deleted">
<item quantity="one">1 objekt borttagen</item>

View File

@ -44,6 +44,8 @@
<string name="files_count">Total files count</string>
<string name="resolution">Resolution</string>
<string name="duration">Duration</string>
<string name="artist">Artist</string>
<string name="album">Album</string>
<plurals name="items_deleted">
<item quantity="one">1 item deleted</item>