Improve the Mp3 song search functionality to search throughout the external storage device and excluding Notification, Android, and Notifications directories #29
This commit is contained in:
committed by
amazing-username
parent
b2a70de4b2
commit
971da4b9d2
@@ -3,8 +3,13 @@ package com.example.mear.management
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.lang.Exception
|
import java.lang.Exception
|
||||||
|
|
||||||
|
import com.example.mear.constants.DirectoryIgnore
|
||||||
|
import com.example.mear.constants.FileTypes
|
||||||
|
|
||||||
class MusicFiles (private val demoPath: File) {
|
class MusicFiles (private val demoPath: File) {
|
||||||
|
|
||||||
|
fun demoSearch() {
|
||||||
|
}
|
||||||
|
|
||||||
fun loadAllMusicPaths() {
|
fun loadAllMusicPaths() {
|
||||||
try {
|
try {
|
||||||
@@ -41,6 +46,53 @@ class MusicFiles (private val demoPath: File) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var allSongs: MutableList<String>?= null
|
fun searchForMp3Songs() {
|
||||||
val musicSongLimit = Int.MAX_VALUE
|
try {
|
||||||
|
var pathList: MutableList<String>? = null
|
||||||
|
pathList = mutableListOf()
|
||||||
|
|
||||||
|
var fileSearch = File(demoPath.absolutePath)
|
||||||
|
fileSearch.walkTopDown().forEach {
|
||||||
|
println(it.absolutePath)
|
||||||
|
if (!ignoreThisDirectory(it.absolutePath)) {
|
||||||
|
if (it.isFile) {
|
||||||
|
if (it.endsWith(FileTypes.Mp3)) {
|
||||||
|
pathList.add(it.absolutePath)
|
||||||
|
}
|
||||||
|
if (it.extension.toString().equals(FileTypes.Mp3)) {
|
||||||
|
pathList.add(it.absolutePath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
allSongs = pathList
|
||||||
|
}
|
||||||
|
catch (ex: Exception) {
|
||||||
|
val exMsg = ex.message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun ignoreThisDirectory(path: String): Boolean {
|
||||||
|
var ignoreDirectory = false
|
||||||
|
try {
|
||||||
|
if (path.contains(DirectoryIgnore.Android_Root)) {
|
||||||
|
ignoreDirectory = true
|
||||||
|
}
|
||||||
|
if (path.contains(DirectoryIgnore.Notifications)) {
|
||||||
|
ignoreDirectory = true
|
||||||
|
}
|
||||||
|
if (path.contains(DirectoryIgnore.Ringtones)) {
|
||||||
|
ignoreDirectory = true
|
||||||
|
}
|
||||||
|
return ignoreDirectory
|
||||||
|
}
|
||||||
|
catch (ex: Exception) {
|
||||||
|
val exMsg = ex.message
|
||||||
|
}
|
||||||
|
return ignoreDirectory
|
||||||
|
}
|
||||||
|
|
||||||
|
var allSongs: MutableList<String>?= null
|
||||||
|
|
||||||
|
private val musicSongLimit = Int.MAX_VALUE
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user