Merge pull request #3227 from Bnyro/master

Close video player when entering audio mode
This commit is contained in:
Bnyro 2023-03-03 17:26:41 +01:00 committed by GitHub
commit 3db3457d58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 2 deletions

View File

@ -4,8 +4,11 @@ import android.app.ActivityManager
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.fragment.app.commit
import com.github.libretube.constants.IntentData import com.github.libretube.constants.IntentData
import com.github.libretube.services.BackgroundMode 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] * Helper for starting a new Instance of the [BackgroundMode]
@ -22,8 +25,18 @@ object BackgroundHelper {
position: Long? = null, position: Long? = null,
playlistId: String? = null, playlistId: String? = null,
channelId: 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 // create an intent for the background mode service
val intent = Intent(context, BackgroundMode::class.java) val intent = Intent(context, BackgroundMode::class.java)
intent.putExtra(IntentData.videoId, videoId) intent.putExtra(IntentData.videoId, videoId)

View File

@ -71,6 +71,7 @@ class AudioPlayerFragment : Fragment(), AudioPlayerOptions {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
audioHelper = AudioHelper(requireContext()) audioHelper = AudioHelper(requireContext())
Intent(activity, BackgroundMode::class.java).also { intent -> Intent(activity, BackgroundMode::class.java).also { intent ->
activity?.bindService(intent, connection, Context.BIND_AUTO_CREATE) activity?.bindService(intent, connection, Context.BIND_AUTO_CREATE)

View File

@ -465,7 +465,8 @@ class PlayerFragment : Fragment(R.layout.fragment_player), OnlinePlayerOptions {
exoPlayer.currentPosition, exoPlayer.currentPosition,
playlistId, playlistId,
channelId, channelId,
true keepQueue = true,
keepVideoPlayerAlive = true
) )
handler.postDelayed(500) { handler.postDelayed(500) {
NavigationHelper.startAudioPlayer(requireContext()) NavigationHelper.startAudioPlayer(requireContext())