|
@@ -9,30 +9,31 @@ import java.io.File
|
|
|
|
|
|
object DataParser {
|
|
|
|
|
|
- fun parseMusicSource(contentResolver: ContentResolver, packagePath: String):MusicSource{
|
|
|
+ fun parseMusicSource(contentResolver: ContentResolver,libraryPaths:List<String>):MusicSource{
|
|
|
val musicSource = MusicSource()
|
|
|
- musicSource.library = parseMusic(packagePath)
|
|
|
- musicSource.device = parseMusic(contentResolver, packagePath)
|
|
|
+ musicSource.library = parseMusic(libraryPaths)
|
|
|
+ musicSource.device = parseMusic(contentResolver,libraryPaths)
|
|
|
return musicSource
|
|
|
}
|
|
|
|
|
|
- fun parseMusic(packagePath: String): ArrayList<Music> {
|
|
|
+ private fun parseMusic(paths: List<String>): ArrayList<Music> {
|
|
|
val mediaMetadataRetriever = MediaMetadataRetriever()
|
|
|
-
|
|
|
val musics = ArrayList<Music>()
|
|
|
- val files = File(packagePath)
|
|
|
- for (file in files.listFiles()) {
|
|
|
- mediaMetadataRetriever.setDataSource(file.path)
|
|
|
+
|
|
|
+ for (path in paths) {
|
|
|
+ val file = File(path)
|
|
|
+ mediaMetadataRetriever.setDataSource(path)
|
|
|
+
|
|
|
val music = Music()
|
|
|
music.name = file.name
|
|
|
- music.path = file.path
|
|
|
+ music.path = path
|
|
|
music.duration = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION).toLong()
|
|
|
musics.add(music)
|
|
|
}
|
|
|
return musics
|
|
|
}
|
|
|
|
|
|
- fun parseMusic(contentResolver: ContentResolver, packagePath: String): ArrayList<Music> {
|
|
|
+ private fun parseMusic(contentResolver: ContentResolver,paths: List<String>): ArrayList<Music>{
|
|
|
val selection = MediaStore.Audio.Media.IS_MUSIC + " != 0"
|
|
|
val projection = arrayOf(
|
|
|
MediaStore.Audio.Media.TITLE,
|
|
@@ -53,7 +54,7 @@ object DataParser {
|
|
|
music.path = cursor.getString(1)
|
|
|
music.duration = cursor.getString(2).toLong()
|
|
|
val file = File(music.path)
|
|
|
- if (file.parent != packagePath) {
|
|
|
+ if (!paths.contains(file.path)) {
|
|
|
musics.add(music)
|
|
|
}
|
|
|
}
|