Skip to content

Commit 3bea30c

Browse files
authored
Merge pull request #567 from naveensingh/crash_quick_fix
Avoid using Java 8 `ConcurrentHashmap.newKeySet()`
2 parents 9a3e835 + 06962c2 commit 3bea30c

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/SimpleMediaScanner.kt

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import com.simplemobiletools.musicplayer.models.Playlist
1919
import com.simplemobiletools.musicplayer.models.Track
2020
import java.io.File
2121
import java.io.FileInputStream
22-
import java.util.Arrays
23-
import java.util.concurrent.ConcurrentHashMap
2422

2523
/**
2624
* This singleton class manages the process of querying [MediaStore] for new audio files, manually scanning storage for missing audio files, and removing outdated
@@ -315,13 +313,11 @@ class SimpleMediaScanner(private val context: Application) {
315313
return arrayListOf()
316314
}
317315

318-
val tracksSet = ConcurrentHashMap.newKeySet<Track>()
319-
val paths = audioFilePaths.toTypedArray()
320-
val totalPaths = paths.size
316+
val tracks = arrayListOf<Track>()
317+
val totalPaths = audioFilePaths.size
321318
var pathsScanned = 0
322319

323-
// running metadata retriever in parallel significantly reduces the required time
324-
Arrays.stream(paths).parallel().forEach { path ->
320+
audioFilePaths.forEach { path ->
325321
pathsScanned += 1
326322
maybeShowScanProgress(
327323
pathBeingScanned = path,
@@ -364,7 +360,7 @@ class SimpleMediaScanner(private val context: Application) {
364360
val track = Track(0, id, title, artist, path, duration, album, "", 0, trackId, folderName, 0, 0, year, dateAdded, FLAG_MANUAL_CACHE)
365361
// use hashCode() as id for tracking purposes, there's a very slim chance of collision
366362
track.mediaStoreId = track.hashCode().toLong()
367-
tracksSet.add(track)
363+
tracks.add(track)
368364
}
369365

370366
try {
@@ -374,11 +370,6 @@ class SimpleMediaScanner(private val context: Application) {
374370
}
375371
}
376372

377-
val tracks = arrayListOf<Track>()
378-
tracksSet.stream().forEach {
379-
tracks.add(it)
380-
}
381-
382373
maybeRescanPaths(audioFilePaths)
383374
return tracks
384375
}
@@ -486,7 +477,6 @@ class SimpleMediaScanner(private val context: Application) {
486477
context.audioHelper.deleteArtists(invalidArtists)
487478
}
488479

489-
@Synchronized
490480
private fun maybeShowScanProgress(pathBeingScanned: String = "", progress: Int = 0, max: Int = 0) {
491481
if (!showProgress) {
492482
return

0 commit comments

Comments
 (0)