Skip to content

Commit

Permalink
fix Sithira#83: java.lang.IllegalStateException: Handler
Browse files Browse the repository at this point in the history
  • Loading branch information
bossly committed Mar 30, 2024
1 parent 7497484 commit 5d8aa6e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class FlutterRadioPlayerPlugin : FlutterPlugin, ActivityAware, MethodChannel.Met

override fun onDetachedFromActivity() {
if (isBound) {
frpRadioPlayerService.onDestroy()
frpRadioPlayerService.stop()
}
EventBus.getDefault().unregister(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class FRPCoreService : Service(), PlayerNotificationManager.NotificationListener

if (exoPlayer != null) {
exoPlayer?.release()
exoPlayer = null
}

mediaSessionConnector?.setPlayer(null)
Expand Down Expand Up @@ -268,31 +269,36 @@ class FRPCoreService : Service(), PlayerNotificationManager.NotificationListener
}
}

private fun postCurrentPlayingEvent() {
exoPlayer?.currentMediaItemIndex?.let {
if (it < mediaSourceList.count()) {
eventBus.post(FRPPlayerEvent(currentSource = updateCurrentPlaying(mediaSourceList[it])))
}
}
}

fun nextMediaItem() {
Log.i(TAG, "Seeking to next media item...")
exoPlayer?.seekToNext()
exoPlayer?.prepare()
exoPlayer?.play()
val currentMedia = mediaSourceList[exoPlayer?.currentMediaItemIndex!!]
eventBus.post(FRPPlayerEvent(currentSource = updateCurrentPlaying(currentMedia)))
postCurrentPlayingEvent()
}

fun prevMediaItem() {
Log.i(TAG, "Seeking to prev media item...")
exoPlayer?.seekToPrevious()
exoPlayer?.prepare()
exoPlayer?.play()
val currentMedia = mediaSourceList[exoPlayer?.currentMediaItemIndex!!]
eventBus.post(FRPPlayerEvent(currentSource = updateCurrentPlaying(currentMedia)))
postCurrentPlayingEvent()
}

fun seekToMediaItem(index: Int, playIfReady: Boolean) {
exoPlayer?.seekToDefaultPosition(index)
exoPlayer?.apply {
playWhenReady = playIfReady
}
val currentMedia = mediaSourceList[exoPlayer?.currentMediaItemIndex!!]
eventBus.post(FRPPlayerEvent(currentSource = updateCurrentPlaying(currentMedia)))
postCurrentPlayingEvent()
}

fun setVolume(volume: Float) {
Expand Down

0 comments on commit 5d8aa6e

Please sign in to comment.