Implemented adding 40 tracks, next is to implement adding the rest of the tracks in the background #43
This commit is contained in:
+1
-2
@@ -17,7 +17,7 @@
|
||||
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
||||
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
|
||||
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
|
||||
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res;file://$MODULE_DIR$/build/generated/res/rs/debug" />
|
||||
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res;file://$MODULE_DIR$/build/generated/res/rs/debug;file://$MODULE_DIR$/build/generated/res/resValues/debug" />
|
||||
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
|
||||
</configuration>
|
||||
</facet>
|
||||
@@ -135,7 +135,6 @@
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant_run_split_apk_resources" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javac" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint_jar" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifest-checker" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/merged_assets" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/merged_manifests" />
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.example.mear.constants
|
||||
|
||||
object SongSearch {
|
||||
val INITIAL_SEARCH_AMOUNT = 40
|
||||
}
|
||||
@@ -8,8 +8,9 @@ import com.example.mear.constants.FileTypes
|
||||
|
||||
class MusicFiles (private val demoPath: File) {
|
||||
|
||||
fun demoSearch() {
|
||||
}
|
||||
var allSongs: MutableList<String>?= null
|
||||
|
||||
private val musicSongLimit = Int.MAX_VALUE
|
||||
|
||||
fun loadAllMusicPaths() {
|
||||
try {
|
||||
@@ -45,7 +46,6 @@ class MusicFiles (private val demoPath: File) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun searchForMp3Songs() {
|
||||
try {
|
||||
var pathList: MutableList<String>? = null
|
||||
@@ -56,11 +56,6 @@ class MusicFiles (private val demoPath: File) {
|
||||
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)
|
||||
}
|
||||
@@ -93,8 +88,4 @@ class MusicFiles (private val demoPath: File) {
|
||||
}
|
||||
return ignoreDirectory
|
||||
}
|
||||
|
||||
var allSongs: MutableList<String>?= null
|
||||
|
||||
private val musicSongLimit = Int.MAX_VALUE
|
||||
}
|
||||
@@ -6,13 +6,15 @@ import android.media.MediaMetadataRetriever
|
||||
import java.lang.Exception
|
||||
|
||||
import com.example.mear.constants.Filenames
|
||||
import com.example.mear.constants.SongSearch
|
||||
import com.example.mear.models.Track
|
||||
import com.example.mear.repositories.PlayCountRepository
|
||||
import com.example.mear.repositories.TrackRepository
|
||||
import com.example.mear.util.ConvertByteArray
|
||||
|
||||
class TrackManager(var allSongPath: MutableList<String>) {
|
||||
|
||||
private var songCount: Int? = null
|
||||
private var allTracks: MutableList<Track>? = null
|
||||
|
||||
fun configureTracks(ctx: Context): Int {
|
||||
var id = 0
|
||||
@@ -24,7 +26,7 @@ class TrackManager(var allSongPath: MutableList<String>) {
|
||||
val trackTitle = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE)
|
||||
val trackArtist = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST)
|
||||
val trackAlbum = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM)
|
||||
var trackLength: Int? = null
|
||||
var trackLength: Int?
|
||||
val trackLenghStr = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)
|
||||
trackLength = (trackLenghStr.toInt()/1000)
|
||||
|
||||
@@ -44,9 +46,48 @@ class TrackManager(var allSongPath: MutableList<String>) {
|
||||
catch (ex: Exception) {
|
||||
val exMsg = ex.message
|
||||
}
|
||||
TrackRepository(ctx).createSongCount((id ))
|
||||
TrackRepository(ctx).createSongCount(id)
|
||||
return id.dec()
|
||||
}
|
||||
fun addTracks(ctx: Context) {
|
||||
var initTracks = initialTracks()
|
||||
addToDatabase(ctx, initTracks)
|
||||
TrackRepository(ctx).createSongCount(songCount!!)
|
||||
}
|
||||
|
||||
private fun initialTracks(): MutableList<Track> {
|
||||
var tracks = mutableListOf<Track>()
|
||||
try {
|
||||
for (i in 0.. (SongSearch.INITIAL_SEARCH_AMOUNT - 1)) {
|
||||
var songPath = allSongPath[i]
|
||||
val track = configureTrack(songPath, i)
|
||||
tracks.add(track)
|
||||
}
|
||||
songCount = tracks.size
|
||||
}
|
||||
catch (ex: Exception) {
|
||||
val exMsg = ex.message
|
||||
}
|
||||
|
||||
return tracks
|
||||
}
|
||||
|
||||
private fun configureTrack(songPath: String, id: Int): Track {
|
||||
val metaData = MediaMetadataRetriever()
|
||||
metaData.setDataSource(songPath)
|
||||
|
||||
val title = metaData.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE)
|
||||
val artist = metaData.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST)
|
||||
val album = metaData.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM)
|
||||
val duration = (metaData.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION).toInt()) / 1000
|
||||
|
||||
return Track(id, title, artist, album, duration, ByteArray(0), songPath)
|
||||
}
|
||||
|
||||
private fun addToDatabase(ctx: Context, tracks: List<Track>) {
|
||||
TrackRepository(ctx).insertTracks(tracks)
|
||||
PlayCountRepository(ctx).insertPlayCounts(tracks)
|
||||
}
|
||||
private fun dumpToDatabase(ctx: Context, track: Track) {
|
||||
TrackRepository(ctx).insertTrack(track)
|
||||
PlayCountRepository(ctx).insertPlayCount(track)
|
||||
@@ -60,6 +101,4 @@ class TrackManager(var allSongPath: MutableList<String>) {
|
||||
it.write(fileContents)
|
||||
}
|
||||
}
|
||||
|
||||
var allTracks: MutableList<Track>? = null
|
||||
}
|
||||
@@ -282,7 +282,7 @@ class MusicService: Service() {
|
||||
mp3Paths.searchForMp3Songs()
|
||||
val paths = mp3Paths.allSongs
|
||||
val trackMgr = TrackManager(paths!!)
|
||||
trackMgr.configureTracks(this)
|
||||
trackMgr.addTracks(this)
|
||||
initializeShuffleMode()
|
||||
initializeRepeatMode()
|
||||
}
|
||||
@@ -367,14 +367,6 @@ class MusicService: Service() {
|
||||
if (trackCount!! < 1) {
|
||||
return true
|
||||
}
|
||||
when (trackCount) {
|
||||
null -> {
|
||||
return true
|
||||
}
|
||||
0 -> {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
@@ -382,10 +374,12 @@ class MusicService: Service() {
|
||||
private fun retrieveSongCount(): Int? {
|
||||
|
||||
try {
|
||||
//var db = DatabaseManager(this)
|
||||
val count = TrackRepository(this).getSongCount()
|
||||
TrackRepository(this).delete()
|
||||
|
||||
return count
|
||||
// TODO: Replace this with the local count varialbe when issue #43 is resolved
|
||||
// as well as remove the call to delete the Track table
|
||||
return 0
|
||||
}
|
||||
catch (ex: Exception) {
|
||||
val exMsg = ex.message
|
||||
|
||||
@@ -41,6 +41,17 @@ class PlayCountRepository(val context: Context) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun insertPlayCounts(tracks: List<Track>) = context.database.use {
|
||||
transaction {
|
||||
var i = 0
|
||||
for (track in tracks) {
|
||||
insert("PlayCount", "Id" to i++,
|
||||
"PlayCount" to 0, "TrackId" to track.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun insertPlayCount(track: Track) = context.database.use {
|
||||
insert("PlayCount",
|
||||
"Id" to track.id,
|
||||
|
||||
@@ -65,6 +65,17 @@ class TrackRepository {
|
||||
})
|
||||
}
|
||||
|
||||
fun insertTracks(tracks: List<Track>) = context!!.database.use {
|
||||
transaction {
|
||||
for (track in tracks) {
|
||||
insert("Track",
|
||||
"Id" to track.id, "Title" to track.title, "Album" to track.album,
|
||||
"Artist" to track.artist, "Duration" to track.length,
|
||||
"FilePath" to track.songPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun insertTrack(track: Track) = context!!.database.use {
|
||||
insert("Track",
|
||||
"Id" to track.id,
|
||||
|
||||
Reference in New Issue
Block a user