@@ -20,6 +20,7 @@ class Playlist{
20
20
lateinit var createdBy: String
21
21
lateinit var createdOn: String
22
22
}
23
+
23
24
class MusicPlaylist {
24
25
var ref: ArrayList <Playlist > = ArrayList ()
25
26
}
@@ -30,11 +31,13 @@ fun formatDuration(duration: Long):String{
30
31
minutes* TimeUnit .SECONDS .convert(1 , TimeUnit .MINUTES ))
31
32
return String .format(" %02d:%02d" , minutes, seconds)
32
33
}
34
+
33
35
fun getImgArt (path : String ): ByteArray? {
34
36
val retriever = MediaMetadataRetriever ()
35
37
retriever.setDataSource(path)
36
38
return retriever.embeddedPicture
37
39
}
40
+
38
41
fun setSongPosition (increment : Boolean ){
39
42
if (! PlayerActivity .repeat){
40
43
if (increment)
@@ -49,6 +52,7 @@ fun setSongPosition(increment: Boolean){
49
52
}
50
53
}
51
54
}
55
+
52
56
fun exitApplication (){
53
57
if (PlayerActivity .musicService != null ){
54
58
PlayerActivity .musicService!! .audioManager.abandonAudioFocus(PlayerActivity .musicService)
@@ -68,13 +72,17 @@ fun favouriteChecker(id: String): Int{
68
72
}
69
73
return - 1
70
74
}
75
+
71
76
fun checkPlaylist (playlist : ArrayList <Music >): ArrayList <Music >{
77
+ val indicesToRemove = mutableListOf<Int >()
78
+
72
79
playlist.forEachIndexed { index, music ->
73
- val file = File (music.path)
74
- if (! file.exists())
75
- playlist.removeAt(index)
80
+ if (! File (music.path).exists()) indicesToRemove.add(index)
76
81
}
77
- return playlist
82
+
83
+ indicesToRemove.sortDescending()
84
+ indicesToRemove.forEach { index -> playlist.removeAt(index) }
85
+ return playlist
78
86
}
79
87
80
88
fun setDialogBtnBackground (context : Context , dialog : AlertDialog ){
@@ -100,4 +108,4 @@ fun checkPlaylist(playlist: ArrayList<Music>): ArrayList<Music>{
100
108
val color = newImg.getPixel(0 , 0 )
101
109
newImg.recycle()
102
110
return color
103
- }
111
+ }
0 commit comments