mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
Fix that the info in the audio player doesn't update
This commit is contained in:
parent
10383c8ba6
commit
6d90c7d69c
@ -94,6 +94,7 @@ class OnlinePlayerService : LifecycleService() {
|
||||
* Listener for passing playback state changes to the AudioPlayerFragment
|
||||
*/
|
||||
var onIsPlayingChanged: ((isPlaying: Boolean) -> Unit)? = null
|
||||
var onNewVideo: ((streams: Streams, videoId: String) -> Unit)? = null
|
||||
|
||||
/**
|
||||
* Setting the required [Notification] for running as a foreground service
|
||||
@ -203,6 +204,7 @@ class OnlinePlayerService : LifecycleService() {
|
||||
streams?.thumbnailUrl,
|
||||
)
|
||||
nowPlayingNotification.updatePlayerNotification(videoId, playerNotificationData)
|
||||
streams?.let { onNewVideo?.invoke(it, videoId) }
|
||||
|
||||
player?.apply {
|
||||
playWhenReady = playWhenReadyPlayer
|
||||
|
@ -53,9 +53,6 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
|
||||
private var sId: Int = 0
|
||||
private var eId: Int = 0
|
||||
|
||||
private val onTrackChangeListener: (StreamItem) -> Unit = {
|
||||
updateStreamInfo()
|
||||
}
|
||||
private var handler = Handler(Looper.getMainLooper())
|
||||
private var isPaused: Boolean = false
|
||||
|
||||
@ -170,9 +167,6 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
|
||||
val listener = AudioPlayerThumbnailListener(requireContext(), this)
|
||||
binding.thumbnail.setOnTouchListener(listener)
|
||||
|
||||
// Listen for track changes due to autoplay or the notification
|
||||
PlayingQueue.addOnTrackChangedListener(onTrackChangeListener)
|
||||
|
||||
binding.playPause.setOnClickListener {
|
||||
if (isPaused) playerService?.play() else playerService?.pause()
|
||||
}
|
||||
@ -233,9 +227,8 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
|
||||
/**
|
||||
* Load the information from a new stream into the UI
|
||||
*/
|
||||
private fun updateStreamInfo() {
|
||||
val current = PlayingQueue.getCurrent()
|
||||
current ?: return
|
||||
private fun updateStreamInfo(stream: StreamItem? = null) {
|
||||
val current = stream ?: PlayingQueue.getCurrent() ?: return
|
||||
|
||||
binding.title.text = current.title
|
||||
binding.miniPlayerTitle.text = current.title
|
||||
@ -307,6 +300,9 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
|
||||
binding.miniPlayerPause.setImageResource(iconResource)
|
||||
isPaused = !isPlaying
|
||||
}
|
||||
playerService?.onNewVideo = { streams, videoId ->
|
||||
updateStreamInfo(streams.toStreamItem(videoId))
|
||||
}
|
||||
initializeSeekBar()
|
||||
}
|
||||
|
||||
@ -321,7 +317,6 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
|
||||
runCatching {
|
||||
activity?.unbindService(connection)
|
||||
}
|
||||
PlayingQueue.removeOnTrackChangedListener(onTrackChangeListener)
|
||||
|
||||
super.onDestroy()
|
||||
}
|
||||
|
@ -20,10 +20,6 @@ object PlayingQueue {
|
||||
*/
|
||||
private var onQueueTapListener: (StreamItem) -> Unit = {}
|
||||
|
||||
/**
|
||||
* Listener that gets called when the current playing video changes
|
||||
*/
|
||||
private val onTrackChangedListeners: MutableList<(StreamItem) -> Unit> = mutableListOf()
|
||||
var repeatQueue: Boolean = false
|
||||
|
||||
fun clear() = queue.clear()
|
||||
@ -61,11 +57,6 @@ object PlayingQueue {
|
||||
|
||||
fun updateCurrent(streamItem: StreamItem) {
|
||||
currentStream = streamItem
|
||||
onTrackChangedListeners.forEach {
|
||||
runCatching {
|
||||
it.invoke(streamItem)
|
||||
}
|
||||
}
|
||||
if (!contains(streamItem)) queue.add(0, streamItem)
|
||||
}
|
||||
|
||||
@ -173,17 +164,8 @@ object PlayingQueue {
|
||||
onQueueTapListener = listener
|
||||
}
|
||||
|
||||
fun addOnTrackChangedListener(listener: (StreamItem) -> Unit) {
|
||||
onTrackChangedListeners.add(listener)
|
||||
}
|
||||
|
||||
fun removeOnTrackChangedListener(listener: (StreamItem) -> Unit) {
|
||||
onTrackChangedListeners.remove(listener)
|
||||
}
|
||||
|
||||
fun resetToDefaults() {
|
||||
repeatQueue = false
|
||||
onQueueTapListener = {}
|
||||
onTrackChangedListeners.clear()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user