mirror of
https://github.com/cmclark00/RetroMusicPlayer.git
synced 2025-05-17 23:55:21 +01:00
Improved tag editor code
This commit is contained in:
parent
4e5ff47324
commit
e62ff2696e
1 changed files with 24 additions and 4 deletions
|
@ -74,9 +74,16 @@ class TagWriter {
|
|||
val audioFile = AudioFileIO.read(File(filePath))
|
||||
val tag = audioFile.tagOrCreateAndSetDefault
|
||||
if (info.fieldKeyValueMap != null) {
|
||||
for ((key, value) in info.fieldKeyValueMap) {
|
||||
for ((key, newValue) in info.fieldKeyValueMap) {
|
||||
try {
|
||||
tag.setField(key, value)
|
||||
val currentValue = tag.getFirst(key)
|
||||
if (currentValue != newValue) {
|
||||
if (newValue.isEmpty()) {
|
||||
tag.deleteField(key)
|
||||
} else {
|
||||
tag.setField(key, newValue)
|
||||
}
|
||||
}
|
||||
} catch (e: FieldDataInvalidException) {
|
||||
withContext(Dispatchers.Main) {
|
||||
context.showToast(R.string.could_not_write_tags_to_file)
|
||||
|
@ -127,6 +134,7 @@ class TagWriter {
|
|||
val cacheFiles = mutableListOf<File>()
|
||||
var artwork: Artwork? = null
|
||||
var albumArtFile: File? = null
|
||||
|
||||
if (info.artworkInfo?.artwork != null) {
|
||||
try {
|
||||
albumArtFile = createAlbumArtFile(context).canonicalFile
|
||||
|
@ -140,24 +148,36 @@ class TagWriter {
|
|||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
var wroteArtwork = false
|
||||
var deletedArtwork = false
|
||||
|
||||
for (filePath in info.filePaths!!) {
|
||||
try {
|
||||
val originFile = File(filePath)
|
||||
val cacheFile = File(context.cacheDir, originFile.name)
|
||||
cacheFiles.add(cacheFile)
|
||||
|
||||
originFile.inputStream().use { input ->
|
||||
cacheFile.outputStream().use { output ->
|
||||
input.copyTo(output)
|
||||
}
|
||||
}
|
||||
|
||||
val audioFile = AudioFileIO.read(cacheFile)
|
||||
val tag = audioFile.tagOrCreateAndSetDefault
|
||||
|
||||
if (info.fieldKeyValueMap != null) {
|
||||
for ((key, value) in info.fieldKeyValueMap) {
|
||||
for ((key, newValue) in info.fieldKeyValueMap) {
|
||||
try {
|
||||
tag.setField(key, value)
|
||||
val currentValue = tag.getFirst(key)
|
||||
if (currentValue != newValue) {
|
||||
if (newValue.isEmpty()) {
|
||||
tag.deleteField(key)
|
||||
} else {
|
||||
tag.setField(key, newValue)
|
||||
}
|
||||
}
|
||||
} catch (e: FieldDataInvalidException) {
|
||||
withContext(Dispatchers.Main) {
|
||||
context.showToast(R.string.could_not_write_tags_to_file)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue