mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
Close video player when entering audio mode
This commit is contained in:
parent
641754c82c
commit
0d932426e4
@ -4,8 +4,11 @@ import android.app.ActivityManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.commit
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.services.BackgroundMode
|
||||
import com.github.libretube.ui.activities.MainActivity
|
||||
import com.github.libretube.ui.fragments.PlayerFragment
|
||||
|
||||
/**
|
||||
* Helper for starting a new Instance of the [BackgroundMode]
|
||||
@ -22,8 +25,18 @@ object BackgroundHelper {
|
||||
position: Long? = null,
|
||||
playlistId: String? = null,
|
||||
channelId: String? = null,
|
||||
keepQueue: Boolean? = null
|
||||
keepQueue: Boolean? = null,
|
||||
keepVideoPlayerAlive: Boolean = false
|
||||
) {
|
||||
// close the previous video player if open
|
||||
if (!keepVideoPlayerAlive) {
|
||||
(context as? MainActivity)?.supportFragmentManager?.let { fragmentManager ->
|
||||
fragmentManager.fragments.firstOrNull { it is PlayerFragment }?.let {
|
||||
fragmentManager.commit { remove(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// create an intent for the background mode service
|
||||
val intent = Intent(context, BackgroundMode::class.java)
|
||||
intent.putExtra(IntentData.videoId, videoId)
|
||||
|
@ -71,6 +71,7 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
audioHelper = AudioHelper(requireContext())
|
||||
Intent(activity, BackgroundMode::class.java).also { intent ->
|
||||
activity?.bindService(intent, connection, Context.BIND_AUTO_CREATE)
|
||||
|
@ -466,7 +466,8 @@ class PlayerFragment : Fragment(R.layout.fragment_player), OnlinePlayerOptions {
|
||||
exoPlayer.currentPosition,
|
||||
playlistId,
|
||||
channelId,
|
||||
true
|
||||
keepQueue = true,
|
||||
keepVideoPlayerAlive = true
|
||||
)
|
||||
handler.postDelayed(500) {
|
||||
NavigationHelper.startAudioPlayer(requireContext())
|
||||
|
Loading…
Reference in New Issue
Block a user