From c68075a23346e00379c4c529a05da8306061fd0f Mon Sep 17 00:00:00 2001 From: Anil Kumar Beesetti Date: Sat, 14 Dec 2024 10:47:53 +0530 Subject: [PATCH 1/7] set seamless resize enabled for pip --- .../anilbeesetti/nextplayer/feature/player/PlayerActivity.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt index bec2fffb8..63a53551d 100644 --- a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt +++ b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt @@ -381,6 +381,7 @@ class PlayerActivity : AppCompatActivity() { } } + @SuppressLint("NewApi") override fun onUserLeaveHint() { super.onUserLeaveHint() if (Build.VERSION.SDK_INT in Build.VERSION_CODES.O..= Build.VERSION_CODES.S) { + setSeamlessResizeEnabled(playerPreferences.autoPip && enableAutoEnter) setAutoEnterEnabled(playerPreferences.autoPip && enableAutoEnter) } }.build().also { setPictureInPictureParams(it) } From 49836437a7e8efb8c7b6160762c4a796b7cc0228 Mon Sep 17 00:00:00 2001 From: Anil Kumar Beesetti Date: Sat, 14 Dec 2024 11:02:24 +0530 Subject: [PATCH 2/7] update drawables of next and previous buttons --- feature/player/src/main/res/values/drawables.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/feature/player/src/main/res/values/drawables.xml b/feature/player/src/main/res/values/drawables.xml index f50bbce9b..a9fd86e5e 100644 --- a/feature/player/src/main/res/values/drawables.xml +++ b/feature/player/src/main/res/values/drawables.xml @@ -2,4 +2,6 @@ @drawable/ic_play @drawable/ic_pause + @drawable/ic_skip_next + @drawable/ic_skip_prev \ No newline at end of file From f1352da4556cc2630854fb5d6e933a987508e73b Mon Sep 17 00:00:00 2001 From: Anil Kumar Beesetti Date: Sat, 14 Dec 2024 11:25:02 +0530 Subject: [PATCH 3/7] add pip actions --- .../feature/player/PlayerActivity.kt | 117 +++++++++++++++--- 1 file changed, 102 insertions(+), 15 deletions(-) diff --git a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt index 63a53551d..a6a155b16 100644 --- a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt +++ b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt @@ -3,16 +3,21 @@ package dev.anilbeesetti.nextplayer.feature.player import android.annotation.SuppressLint import android.app.Activity import android.app.AppOpsManager +import android.app.PendingIntent import android.app.PictureInPictureParams +import android.app.RemoteAction +import android.content.BroadcastReceiver import android.content.ComponentName import android.content.Context import android.content.Intent +import android.content.IntentFilter import android.content.pm.ActivityInfo import android.content.pm.PackageManager import android.content.res.Configuration import android.graphics.Color import android.graphics.Rect import android.graphics.Typeface +import android.graphics.drawable.Icon import android.media.AudioManager import android.media.audiofx.LoudnessEnhancer import android.net.Uri @@ -35,6 +40,7 @@ import android.widget.Toast import androidx.activity.addCallback import androidx.activity.result.contract.ActivityResultContracts.OpenDocument import androidx.activity.viewModels +import androidx.annotation.DrawableRes import androidx.annotation.RequiresApi import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatDelegate @@ -64,7 +70,6 @@ import dev.anilbeesetti.nextplayer.core.common.extensions.isDeviceTvBox import dev.anilbeesetti.nextplayer.core.model.ControlButtonsPosition import dev.anilbeesetti.nextplayer.core.model.ThemeConfig import dev.anilbeesetti.nextplayer.core.model.VideoZoom -import dev.anilbeesetti.nextplayer.core.ui.R as coreUiR import dev.anilbeesetti.nextplayer.feature.player.databinding.ActivityPlayerBinding import dev.anilbeesetti.nextplayer.feature.player.dialogs.PlaybackSpeedControlsDialogFragment import dev.anilbeesetti.nextplayer.feature.player.dialogs.TrackSelectionDialogFragment @@ -100,6 +105,7 @@ import kotlinx.coroutines.guava.await import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import timber.log.Timber +import dev.anilbeesetti.nextplayer.core.ui.R as coreUiR @SuppressLint("UnsafeOptInUsageError") @AndroidEntryPoint @@ -139,6 +145,7 @@ class PlayerActivity : AppCompatActivity() { private lateinit var volumeManager: VolumeManager private lateinit var brightnessManager: BrightnessManager var loudnessEnhancer: LoudnessEnhancer? = null + private var pipBroadcastReceiver: BroadcastReceiver? = null /** * Listeners @@ -403,11 +410,32 @@ class PlayerActivity : AppCompatActivity() { if (isInPictureInPictureMode) { binding.playerView.subtitleView?.setFractionalTextSize(SubtitleView.DEFAULT_TEXT_SIZE_FRACTION) playerUnlockControls.visibility = View.INVISIBLE + pipBroadcastReceiver = object : BroadcastReceiver() { + override fun onReceive(context: Context?, intent: Intent?) { + if (intent == null || intent.action != PIP_INTENT_ACTION) return + when (intent.getIntExtra(PIP_INTENT_ACTION_CODE, 0)) { + PIP_ACTION_PLAY -> mediaController?.play() + PIP_ACTION_PAUSE -> mediaController?.pause() + PIP_ACTION_NEXT -> mediaController?.seekToNext() + PIP_ACTION_PREVIOUS -> mediaController?.seekToPrevious() + } + updatePictureInPictureParams() + } + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + registerReceiver(pipBroadcastReceiver, IntentFilter(PIP_INTENT_ACTION), RECEIVER_NOT_EXPORTED) + } else { + registerReceiver(pipBroadcastReceiver, IntentFilter(PIP_INTENT_ACTION)) + } } else { binding.playerView.subtitleView?.setFixedTextSize(TypedValue.COMPLEX_UNIT_SP, playerPreferences.subtitleTextSize.toFloat()) if (!isControlsLocked) { playerUnlockControls.visibility = View.VISIBLE } + pipBroadcastReceiver?.let { + unregisterReceiver(it) + pipBroadcastReceiver = null + } } super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig) } @@ -427,6 +455,38 @@ class PlayerActivity : AppCompatActivity() { setSeamlessResizeEnabled(playerPreferences.autoPip && enableAutoEnter) setAutoEnterEnabled(playerPreferences.autoPip && enableAutoEnter) } + + setActions( + listOf( + createPipAction( + context = this@PlayerActivity, + "skip to previous", + coreUiR.drawable.ic_skip_prev, + PIP_ACTION_PREVIOUS, + ), + if (mediaController?.isPlaying == true) { + createPipAction( + context = this@PlayerActivity, + "pause", + coreUiR.drawable.ic_pause, + PIP_ACTION_PAUSE, + ) + } else { + createPipAction( + context = this@PlayerActivity, + "play", + coreUiR.drawable.ic_play, + PIP_ACTION_PLAY, + ) + }, + createPipAction( + context = this@PlayerActivity, + "skip to next", + coreUiR.drawable.ic_skip_next, + PIP_ACTION_NEXT, + ), + ), + ) }.build().also { setPictureInPictureParams(it) } } @@ -434,12 +494,10 @@ class PlayerActivity : AppCompatActivity() { return binding.playerView.player?.videoSize?.let { videoSize -> if (videoSize.width == 0 || videoSize.height == 0) return@let null - val minAspectRatio = 0.5f // 1:2 aspect ratio - val maxAspectRatio = 2.39f // 21:9 aspect ratio Rational( - videoSize.width.coerceIn((videoSize.height * minAspectRatio).toInt(), (videoSize.height * maxAspectRatio).toInt()), - videoSize.height.coerceIn((videoSize.width * minAspectRatio).toInt(), (videoSize.width * maxAspectRatio).toInt()), - ) + videoSize.width, + videoSize.height, + ).takeIf { it.toFloat() in 0.5f..2.39f } } } @@ -736,7 +794,7 @@ class PlayerActivity : AppCompatActivity() { when (keyCode) { KeyEvent.KEYCODE_VOLUME_UP, KeyEvent.KEYCODE_DPAD_UP, - -> { + -> { if (!binding.playerView.isControllerFullyVisible || keyCode == KeyEvent.KEYCODE_VOLUME_UP) { volumeManager.increaseVolume(playerPreferences.showSystemVolumePanel) showVolumeGestureLayout() @@ -746,7 +804,7 @@ class PlayerActivity : AppCompatActivity() { KeyEvent.KEYCODE_VOLUME_DOWN, KeyEvent.KEYCODE_DPAD_DOWN, - -> { + -> { if (!binding.playerView.isControllerFullyVisible || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { volumeManager.decreaseVolume(playerPreferences.showSystemVolumePanel) showVolumeGestureLayout() @@ -758,7 +816,7 @@ class PlayerActivity : AppCompatActivity() { KeyEvent.KEYCODE_MEDIA_PAUSE, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, KeyEvent.KEYCODE_BUTTON_SELECT, - -> { + -> { when { keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE -> mediaController?.pause() keyCode == KeyEvent.KEYCODE_MEDIA_PLAY -> mediaController?.play() @@ -771,7 +829,7 @@ class PlayerActivity : AppCompatActivity() { KeyEvent.KEYCODE_BUTTON_START, KeyEvent.KEYCODE_BUTTON_A, KeyEvent.KEYCODE_SPACE, - -> { + -> { if (!binding.playerView.isControllerFullyVisible) { binding.playerView.togglePlayPause() return true @@ -781,7 +839,7 @@ class PlayerActivity : AppCompatActivity() { KeyEvent.KEYCODE_DPAD_LEFT, KeyEvent.KEYCODE_BUTTON_L2, KeyEvent.KEYCODE_MEDIA_REWIND, - -> { + -> { if (!binding.playerView.isControllerFullyVisible || keyCode == KeyEvent.KEYCODE_MEDIA_REWIND) { mediaController?.run { if (scrubStartPosition == -1L) { @@ -801,7 +859,7 @@ class PlayerActivity : AppCompatActivity() { KeyEvent.KEYCODE_DPAD_RIGHT, KeyEvent.KEYCODE_BUTTON_R2, KeyEvent.KEYCODE_MEDIA_FAST_FORWARD, - -> { + -> { if (!binding.playerView.isControllerFullyVisible || keyCode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD) { mediaController?.run { if (scrubStartPosition == -1L) { @@ -822,7 +880,7 @@ class PlayerActivity : AppCompatActivity() { KeyEvent.KEYCODE_ENTER, KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_NUMPAD_ENTER, - -> { + -> { if (!binding.playerView.isControllerFullyVisible) { binding.playerView.showController() return true @@ -845,7 +903,7 @@ class PlayerActivity : AppCompatActivity() { KeyEvent.KEYCODE_VOLUME_DOWN, KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_DPAD_DOWN, - -> { + -> { hideVolumeGestureLayout() return true } @@ -856,7 +914,7 @@ class PlayerActivity : AppCompatActivity() { KeyEvent.KEYCODE_DPAD_RIGHT, KeyEvent.KEYCODE_BUTTON_R2, KeyEvent.KEYCODE_MEDIA_FAST_FORWARD, - -> { + -> { hidePlayerInfo() return true } @@ -999,5 +1057,34 @@ class PlayerActivity : AppCompatActivity() { companion object { const val HIDE_DELAY_MILLIS = 1000L + const val PIP_INTENT_ACTION = "pip_action" + const val PIP_INTENT_ACTION_CODE = "pip_action_code" + const val PIP_ACTION_PLAY = 1 + const val PIP_ACTION_PAUSE = 2 + const val PIP_ACTION_NEXT = 3 + const val PIP_ACTION_PREVIOUS = 4 } } + +@RequiresApi(Build.VERSION_CODES.O) +fun createPipAction( + context: Context, + title: String, + @DrawableRes icon: Int, + actionCode: Int, +): RemoteAction { + return RemoteAction( + Icon.createWithResource(context, icon), + title, + title, + PendingIntent.getBroadcast( + context, + actionCode, + Intent(PlayerActivity.PIP_INTENT_ACTION).apply { + putExtra(PlayerActivity.PIP_INTENT_ACTION_CODE, actionCode) + setPackage(context.packageName) + }, + PendingIntent.FLAG_IMMUTABLE, + ), + ) +} From 567eade1a63b7f691912438d7c12b751b18f0055 Mon Sep 17 00:00:00 2001 From: Anil Kumar Beesetti Date: Sat, 14 Dec 2024 11:27:44 +0530 Subject: [PATCH 4/7] fix issue with close notification button not working --- .../nextplayer/feature/player/service/PlayerService.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/service/PlayerService.kt b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/service/PlayerService.kt index 15b157f95..adb267996 100644 --- a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/service/PlayerService.kt +++ b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/service/PlayerService.kt @@ -295,7 +295,10 @@ class PlayerService : MediaSessionService() { } CustomCommands.STOP_PLAYER_SESSION -> { - stopSelf() + mediaSession?.run { + player.clearMediaItems() + player.stop() + } ?: stopSelf() return@future SessionResult(SessionResult.RESULT_SUCCESS) } } From 682bf491d329c906978a7df3eed152271d0c9bf9 Mon Sep 17 00:00:00 2001 From: Anil Kumar Beesetti Date: Sat, 14 Dec 2024 13:44:37 +0530 Subject: [PATCH 5/7] fix issue with selected video not played after closing pip --- .../feature/player/PlayerActivity.kt | 14 ++++------ .../feature/player/PlayerViewModel.kt | 2 +- .../feature/player/extensions/Activity.kt | 26 ------------------- .../feature/player/extensions/VideoSize.kt | 5 +--- 4 files changed, 7 insertions(+), 40 deletions(-) diff --git a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt index a6a155b16..324f78372 100644 --- a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt +++ b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt @@ -78,7 +78,6 @@ import dev.anilbeesetti.nextplayer.feature.player.dialogs.nameRes import dev.anilbeesetti.nextplayer.feature.player.extensions.audioSessionId import dev.anilbeesetti.nextplayer.feature.player.extensions.isPortrait import dev.anilbeesetti.nextplayer.feature.player.extensions.next -import dev.anilbeesetti.nextplayer.feature.player.extensions.prettyPrintIntent import dev.anilbeesetti.nextplayer.feature.player.extensions.seekBack import dev.anilbeesetti.nextplayer.feature.player.extensions.seekForward import dev.anilbeesetti.nextplayer.feature.player.extensions.setImageDrawable @@ -205,7 +204,6 @@ class PlayerActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - prettyPrintIntent() AppCompatDelegate.setDefaultNightMode( when (applicationPreferences.themeConfig) { @@ -346,7 +344,7 @@ class PlayerActivity : AppCompatActivity() { volumeManager.loudnessEnhancer = loudnessEnhancer if (intent.data != null && intent.data.toString() != currentMediaItem?.mediaId) { - playVideo(uri = viewModel.currentMediaItem?.localConfiguration?.uri ?: intent.data!!) + playVideo(uri = viewModel.currentMediaItemUri ?: intent.data!!) } } subtitleFileLauncherLaunchedForMediaItem = null @@ -686,7 +684,7 @@ class PlayerActivity : AppCompatActivity() { private fun playbackStateListener() = object : Player.Listener { override fun onMediaItemTransition(mediaItem: MediaItem?, reason: Int) { super.onMediaItemTransition(mediaItem, reason) - viewModel.currentMediaItem = mediaItem + viewModel.currentMediaItemUri = mediaItem?.localConfiguration?.uri isMediaItemReady = false } @@ -721,11 +719,11 @@ class PlayerActivity : AppCompatActivity() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && isPipSupported) { updatePictureInPictureParams() } + setOrientation() } lifecycleScope.launch { val videoScale = mediaController?.currentMediaItem?.mediaId?.let { viewModel.getVideoState(it)?.videoScale } ?: 1f applyVideoScale(videoScale = videoScale) - setOrientation() } } @@ -783,10 +781,8 @@ class PlayerActivity : AppCompatActivity() { override fun onNewIntent(intent: Intent) { super.onNewIntent(intent) if (intent.data != null) { - mediaController?.clearMediaItems() - setIntent(intent) - prettyPrintIntent() - playVideo(intent.data!!) + currentOrientation = null + viewModel.currentMediaItemUri = intent.data } } diff --git a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerViewModel.kt b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerViewModel.kt index 66bb075cb..888e30294 100644 --- a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerViewModel.kt +++ b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerViewModel.kt @@ -25,7 +25,7 @@ class PlayerViewModel @Inject constructor( private val getSortedPlaylistUseCase: GetSortedPlaylistUseCase, ) : ViewModel() { - var currentMediaItem: MediaItem? = null + var currentMediaItemUri: Uri? = null var playWhenReady: Boolean = true var skipSilenceEnabled: Boolean = false diff --git a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/extensions/Activity.kt b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/extensions/Activity.kt index 5a50aae7f..805ff490d 100644 --- a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/extensions/Activity.kt +++ b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/extensions/Activity.kt @@ -34,29 +34,3 @@ val Activity.currentBrightness: Float in WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_OFF..WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_FULL -> brightness else -> Settings.System.getFloat(contentResolver, Settings.System.SCREEN_BRIGHTNESS) / 255 } - -@Suppress("DEPRECATION") -fun Activity.prettyPrintIntent() { - try { - Timber.apply { - d("* action: ${intent.action}") - d("* data: ${intent.data}") - d("* type: ${intent.type}") - d("* package: ${intent.`package`}") - d("* component: ${intent.component}") - d("* flags: ${intent.flags}") - intent.extras?.let { bundle -> - d("=== Extras ===") - bundle.keySet().forEachIndexed { i, key -> - buildString { - append("${i + 1}) $key: ") - bundle.get(key).let { append(if (it is Array<*>) Arrays.toString(it) else it) } - }.also { d(it) } - } - } - } - } catch (e: Exception) { - Timber.e(e) - e.printStackTrace() - } -} diff --git a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/extensions/VideoSize.kt b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/extensions/VideoSize.kt index c2f135d17..f5e8ab222 100644 --- a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/extensions/VideoSize.kt +++ b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/extensions/VideoSize.kt @@ -3,7 +3,4 @@ package dev.anilbeesetti.nextplayer.feature.player.extensions import androidx.media3.common.VideoSize val VideoSize.isPortrait: Boolean - get() { - val isRotated = this.unappliedRotationDegrees == 90 || this.unappliedRotationDegrees == 270 - return if (isRotated) this.width > this.height else this.height > this.width - } + get() = this.height > this.width From 0d5fa1126800f48392f41c94a5983a6c7744873d Mon Sep 17 00:00:00 2001 From: Anil Kumar Beesetti Date: Sat, 14 Dec 2024 13:44:56 +0530 Subject: [PATCH 6/7] run ktlintFormat --- .../feature/player/PlayerActivity.kt | 20 +++++++++---------- .../feature/player/PlayerViewModel.kt | 1 - .../feature/player/extensions/Activity.kt | 2 -- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt index 324f78372..b5d8ca5d9 100644 --- a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt +++ b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt @@ -70,6 +70,7 @@ import dev.anilbeesetti.nextplayer.core.common.extensions.isDeviceTvBox import dev.anilbeesetti.nextplayer.core.model.ControlButtonsPosition import dev.anilbeesetti.nextplayer.core.model.ThemeConfig import dev.anilbeesetti.nextplayer.core.model.VideoZoom +import dev.anilbeesetti.nextplayer.core.ui.R as coreUiR import dev.anilbeesetti.nextplayer.feature.player.databinding.ActivityPlayerBinding import dev.anilbeesetti.nextplayer.feature.player.dialogs.PlaybackSpeedControlsDialogFragment import dev.anilbeesetti.nextplayer.feature.player.dialogs.TrackSelectionDialogFragment @@ -104,7 +105,6 @@ import kotlinx.coroutines.guava.await import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import timber.log.Timber -import dev.anilbeesetti.nextplayer.core.ui.R as coreUiR @SuppressLint("UnsafeOptInUsageError") @AndroidEntryPoint @@ -790,7 +790,7 @@ class PlayerActivity : AppCompatActivity() { when (keyCode) { KeyEvent.KEYCODE_VOLUME_UP, KeyEvent.KEYCODE_DPAD_UP, - -> { + -> { if (!binding.playerView.isControllerFullyVisible || keyCode == KeyEvent.KEYCODE_VOLUME_UP) { volumeManager.increaseVolume(playerPreferences.showSystemVolumePanel) showVolumeGestureLayout() @@ -800,7 +800,7 @@ class PlayerActivity : AppCompatActivity() { KeyEvent.KEYCODE_VOLUME_DOWN, KeyEvent.KEYCODE_DPAD_DOWN, - -> { + -> { if (!binding.playerView.isControllerFullyVisible || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { volumeManager.decreaseVolume(playerPreferences.showSystemVolumePanel) showVolumeGestureLayout() @@ -812,7 +812,7 @@ class PlayerActivity : AppCompatActivity() { KeyEvent.KEYCODE_MEDIA_PAUSE, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, KeyEvent.KEYCODE_BUTTON_SELECT, - -> { + -> { when { keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE -> mediaController?.pause() keyCode == KeyEvent.KEYCODE_MEDIA_PLAY -> mediaController?.play() @@ -825,7 +825,7 @@ class PlayerActivity : AppCompatActivity() { KeyEvent.KEYCODE_BUTTON_START, KeyEvent.KEYCODE_BUTTON_A, KeyEvent.KEYCODE_SPACE, - -> { + -> { if (!binding.playerView.isControllerFullyVisible) { binding.playerView.togglePlayPause() return true @@ -835,7 +835,7 @@ class PlayerActivity : AppCompatActivity() { KeyEvent.KEYCODE_DPAD_LEFT, KeyEvent.KEYCODE_BUTTON_L2, KeyEvent.KEYCODE_MEDIA_REWIND, - -> { + -> { if (!binding.playerView.isControllerFullyVisible || keyCode == KeyEvent.KEYCODE_MEDIA_REWIND) { mediaController?.run { if (scrubStartPosition == -1L) { @@ -855,7 +855,7 @@ class PlayerActivity : AppCompatActivity() { KeyEvent.KEYCODE_DPAD_RIGHT, KeyEvent.KEYCODE_BUTTON_R2, KeyEvent.KEYCODE_MEDIA_FAST_FORWARD, - -> { + -> { if (!binding.playerView.isControllerFullyVisible || keyCode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD) { mediaController?.run { if (scrubStartPosition == -1L) { @@ -876,7 +876,7 @@ class PlayerActivity : AppCompatActivity() { KeyEvent.KEYCODE_ENTER, KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_NUMPAD_ENTER, - -> { + -> { if (!binding.playerView.isControllerFullyVisible) { binding.playerView.showController() return true @@ -899,7 +899,7 @@ class PlayerActivity : AppCompatActivity() { KeyEvent.KEYCODE_VOLUME_DOWN, KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_DPAD_DOWN, - -> { + -> { hideVolumeGestureLayout() return true } @@ -910,7 +910,7 @@ class PlayerActivity : AppCompatActivity() { KeyEvent.KEYCODE_DPAD_RIGHT, KeyEvent.KEYCODE_BUTTON_R2, KeyEvent.KEYCODE_MEDIA_FAST_FORWARD, - -> { + -> { hidePlayerInfo() return true } diff --git a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerViewModel.kt b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerViewModel.kt index 888e30294..503e1b47a 100644 --- a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerViewModel.kt +++ b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerViewModel.kt @@ -3,7 +3,6 @@ package dev.anilbeesetti.nextplayer.feature.player import android.net.Uri import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import androidx.media3.common.MediaItem import dagger.hilt.android.lifecycle.HiltViewModel import dev.anilbeesetti.nextplayer.core.data.models.VideoState import dev.anilbeesetti.nextplayer.core.data.repository.MediaRepository diff --git a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/extensions/Activity.kt b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/extensions/Activity.kt index 805ff490d..404ae267f 100644 --- a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/extensions/Activity.kt +++ b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/extensions/Activity.kt @@ -6,8 +6,6 @@ import android.view.WindowManager import androidx.core.view.WindowCompat import androidx.core.view.WindowInsetsCompat.Type import androidx.core.view.WindowInsetsControllerCompat -import java.util.Arrays -import timber.log.Timber /** * Must call this function after any configuration done to activity to keep system bars behaviour From 65c484301829b80594aa6acdc557b0a8c9331f13 Mon Sep 17 00:00:00 2001 From: Anil Kumar Beesetti Date: Sun, 15 Dec 2024 09:32:46 +0530 Subject: [PATCH 7/7] fix issue with selected video not played while playing an another video in pip --- .../anilbeesetti/nextplayer/feature/player/PlayerActivity.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt index b5d8ca5d9..c4604709c 100644 --- a/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt +++ b/feature/player/src/main/java/dev/anilbeesetti/nextplayer/feature/player/PlayerActivity.kt @@ -783,6 +783,9 @@ class PlayerActivity : AppCompatActivity() { if (intent.data != null) { currentOrientation = null viewModel.currentMediaItemUri = intent.data + if (mediaController != null) { + playVideo(intent.data!!) + } } }