musikr: fix cover file reads
Turns out they were coming from the wrong place.
This commit is contained in:
parent
5fae4601de
commit
76eb98c3af
1 changed files with 3 additions and 4 deletions
|
@ -26,6 +26,7 @@ import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import timber.log.Timber as L
|
||||||
|
|
||||||
internal interface CoverFiles {
|
internal interface CoverFiles {
|
||||||
suspend fun read(id: String): InputStream?
|
suspend fun read(id: String): InputStream?
|
||||||
|
@ -34,12 +35,11 @@ internal interface CoverFiles {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun from(context: Context, path: String, format: CoverFormat): CoverFiles =
|
fun from(context: Context, path: String, format: CoverFormat): CoverFiles =
|
||||||
CoverFilesImpl(context, File(context.filesDir, path).also { it.mkdirs() }, format)
|
CoverFilesImpl(File(context.filesDir, path).also { it.mkdirs() }, format)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class CoverFilesImpl(
|
private class CoverFilesImpl(
|
||||||
private val context: Context,
|
|
||||||
private val dir: File,
|
private val dir: File,
|
||||||
private val coverFormat: CoverFormat
|
private val coverFormat: CoverFormat
|
||||||
) : CoverFiles {
|
) : CoverFiles {
|
||||||
|
@ -53,7 +53,7 @@ private class CoverFilesImpl(
|
||||||
override suspend fun read(id: String): InputStream? =
|
override suspend fun read(id: String): InputStream? =
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
context.openFileInput(getTargetFilePath(id))
|
File(dir, getTargetFilePath(id)).inputStream()
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,6 @@ private class CoverFilesImpl(
|
||||||
|
|
||||||
try {
|
try {
|
||||||
tempFile.outputStream().use { coverFormat.transcodeInto(data, it) }
|
tempFile.outputStream().use { coverFormat.transcodeInto(data, it) }
|
||||||
|
|
||||||
tempFile.renameTo(targetFile)
|
tempFile.renameTo(targetFile)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
tempFile.delete()
|
tempFile.delete()
|
||||||
|
|
Loading…
Reference in a new issue