Skip to content

Commit

Permalink
fix: when file name has "#" or other similar character, the app crash
Browse files Browse the repository at this point in the history
  • Loading branch information
ZTFtrue committed Feb 4, 2024
1 parent d02fcb1 commit 0861170
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions app/src/main/java/com/ztftrue/music/play/PlayService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import android.support.v4.media.session.MediaControllerCompat
import android.support.v4.media.session.MediaSessionCompat
import android.support.v4.media.session.PlaybackStateCompat
import android.widget.Toast
import androidx.core.net.toUri
import androidx.media.MediaBrowserServiceCompat
import androidx.media3.common.AudioAttributes
import androidx.media3.common.BuildConfig
Expand Down Expand Up @@ -43,25 +44,26 @@ import com.ztftrue.music.sqlData.model.MainTab
import com.ztftrue.music.sqlData.model.MusicItem
import com.ztftrue.music.sqlData.model.PlayConfig
import com.ztftrue.music.utils.AlbumList
import com.ztftrue.music.utils.trackManager.AlbumManager
import com.ztftrue.music.utils.AnyListBase
import com.ztftrue.music.utils.ArtistList
import com.ztftrue.music.utils.trackManager.ArtistManager
import com.ztftrue.music.utils.FolderList
import com.ztftrue.music.utils.trackManager.GenreManager
import com.ztftrue.music.utils.GenresList
import com.ztftrue.music.utils.MusicPlayList
import com.ztftrue.music.utils.PlayListType
import com.ztftrue.music.utils.stringToEnumForPlayListType
import com.ztftrue.music.utils.trackManager.AlbumManager
import com.ztftrue.music.utils.trackManager.ArtistManager
import com.ztftrue.music.utils.trackManager.GenreManager
import com.ztftrue.music.utils.trackManager.PlaylistManager
import com.ztftrue.music.utils.trackManager.TracksManager
import com.ztftrue.music.utils.stringToEnumForPlayListType
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import java.io.File

/**
* playList
Expand Down Expand Up @@ -692,11 +694,11 @@ class PlayService : MediaBrowserServiceCompat() {
if (!exoPlayer.isPlaying) {
exoPlayer.playWhenReady = false
}
exoPlayer.addMediaItem(index, MediaItem.fromUri(musicItem.path))
exoPlayer.addMediaItem(index, MediaItem.fromUri(File(musicItem.path).toUri()))
} else if (musicItems != null) {
val list = ArrayList<MediaItem>()
musicItems.forEach {
list.add(MediaItem.fromUri(it.path))
list.add(MediaItem.fromUri(File(it.path).toUri()))
}
playListCurrent = null
CoroutineScope(Dispatchers.IO).launch {
Expand Down Expand Up @@ -1131,7 +1133,7 @@ class PlayService : MediaBrowserServiceCompat() {
val t1 = ArrayList<MediaItem>()
var currentIndex = 0
musicQueue.forEachIndexed { index, it ->
t1.add(MediaItem.fromUri(it.path))
t1.add(MediaItem.fromUri(File(it.path).toUri()))
if (it.id == currentPlayTrack?.id) {
currentIndex = index
}
Expand Down Expand Up @@ -1326,7 +1328,7 @@ class PlayService : MediaBrowserServiceCompat() {
bundle.putParcelableArrayList("queue", musicQueue)
mediaSession?.setExtras(bundle)
musicQueue.forEach {
t1.add(MediaItem.fromUri(it.path))
t1.add(MediaItem.fromUri(File(it.path).toUri()))
}
exoPlayer.setMediaItems(t1)
CoroutineScope(Dispatchers.IO).launch {
Expand Down

0 comments on commit 0861170

Please sign in to comment.