Skip to content

Commit 9d2057c

Browse files
committed
fix flac artwork bug
1 parent 0ce9617 commit 9d2057c

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

app/src/main/java/dev/secam/simpletag/ui/editor/EditorViewModel.kt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import dev.secam.simpletag.data.MusicData
3737
import dev.secam.simpletag.data.SimpleTagField
3838
import dev.secam.simpletag.data.preferences.PreferencesRepo
3939
import dev.secam.simpletag.data.preferences.UserPreferences
40+
import dev.secam.simpletag.util.setArtworkField
4041
import kotlinx.coroutines.CoroutineExceptionHandler
4142
import kotlinx.coroutines.Deferred
4243
import kotlinx.coroutines.Dispatchers
@@ -91,10 +92,10 @@ class EditorViewModel @Inject constructor(
9192
}!!
9293
}
9394

94-
fun isCompatible(ext: String): Boolean {
95-
val types = listOf("mp3", "wav", "wave", "dsf", "aiff", "aif", "aifc", "wma", "ogg", "mp4", "m4a", "m4p", "flac")
96-
return types.contains(ext)
97-
}
95+
// fun isCompatible(ext: String): Boolean {
96+
// val types = listOf("mp3", "wav", "wave", "dsf", "aiff", "aif", "aifc", "wma", "ogg", "mp4", "m4a", "m4p", "flac")
97+
// return types.contains(ext)
98+
// }
9899
fun getArtworkFromUri(contentResolver: ContentResolver, uri: Uri): Artwork?{
99100
var path: String? = null
100101
val projection = arrayOf(
@@ -127,7 +128,13 @@ class EditorViewModel @Inject constructor(
127128
}
128129
val tag = file.tag
129130
tag.deleteArtworkField()
130-
if (artwork != null) tag.setField(artwork)
131+
if (artwork != null) {
132+
if(tag.javaClass == FlacTag().javaClass) {
133+
(tag as FlacTag).setArtworkField(artwork)
134+
}
135+
else tag.setField(artwork)
136+
137+
}
131138

132139
for (field in fields) {
133140
tag.setField(field.key.fieldKey, field.value.text as String)
@@ -252,6 +259,7 @@ class EditorViewModel @Inject constructor(
252259
_uiState.update { it.copy(artworkChanged = artworkChanged) }
253260
}
254261

262+
255263
}
256264

257265
data class EditorUiState(
@@ -263,4 +271,5 @@ data class EditorUiState(
263271
val showBackDialog: Boolean = false,
264272
val showSaveDialog: Boolean = false,
265273
val savedFields: List<String> = listOf()
266-
)
274+
)
275+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (C) 2025 Sergio Camacho
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package dev.secam.simpletag.util
19+
20+
import org.jaudiotagger.tag.flac.FlacTag
21+
import org.jaudiotagger.tag.images.Artwork
22+
import org.jaudiotagger.tag.reference.PictureTypes
23+
24+
fun FlacTag.setArtworkField(artwork: Artwork) {
25+
setField(
26+
createArtworkField(
27+
/* imageData = */ artwork.binaryData,
28+
/* pictureType = */ PictureTypes.DEFAULT_ID,
29+
/* mimeType = */ artwork.mimeType,
30+
/* description = */ "cover",
31+
/* width = */ artwork.width,
32+
/* height = */ artwork.height,
33+
/* colourDepth = */ 24,
34+
/* indexedColouredCount = */ 0
35+
)
36+
)
37+
}

0 commit comments

Comments
 (0)