From f81e8e42cc601abd5fcb1c397004290b68d073a9 Mon Sep 17 00:00:00 2001 From: Zion Huang Date: Mon, 11 Apr 2022 10:35:15 +0800 Subject: [PATCH] [Fix] create media and artwork folder if not exist --- .../main/java/com/zionhuang/music/repos/SongRepository.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/zionhuang/music/repos/SongRepository.kt b/app/src/main/java/com/zionhuang/music/repos/SongRepository.kt index fabbf94cc..c021cf2de 100644 --- a/app/src/main/java/com/zionhuang/music/repos/SongRepository.kt +++ b/app/src/main/java/com/zionhuang/music/repos/SongRepository.kt @@ -103,11 +103,15 @@ object SongRepository : LocalRepository { } override fun getSongFile(songId: String): File { - return context.getExternalFilesDir(null)!! / "media" / md5(songId) + val mediaDir = context.getExternalFilesDir(null)!! / "media" + if (!mediaDir.isDirectory) mediaDir.mkdirs() + return mediaDir / md5(songId) } override fun getSongArtworkFile(songId: String): File { - return context.getExternalFilesDir(null)!! / "artwork" / md5(songId) + val artworkDir = context.getExternalFilesDir(null)!! / "artwork" + if (!artworkDir.isDirectory) artworkDir.mkdirs() + return artworkDir / md5(songId) }