Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct backgrounding behavior for both video and audio (does not work) #4162

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28"/>
<uses-permission android:name="android.permission.VIBRATE" /> <!-- For notifications -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WAKE_LOCK" /> <!-- For media player -->

<application
android:name=".TuskyApplication"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ class ViewMediaActivity : BaseActivity(), HasAndroidInjector, ViewImageFragment.
}
})

// Prevent this activity from dimming or sleeping the screen if it is playing video or audio
if (attachments!![binding.viewPager.currentItem].attachment.type != Attachment.Type.IMAGE) {
// Prevent this activity from dimming or sleeping the screen if it is playing video
// See also WAKE_MODE in ViewVideoFragment.kt
val attachmentType = attachments!![binding.viewPager.currentItem].attachment.type
if (attachmentType == Attachment.Type.VIDEO || attachmentType == Attachment.Type.GIFV) {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import android.widget.FrameLayout
import android.widget.LinearLayout
import androidx.annotation.OptIn
import androidx.core.view.GestureDetectorCompat
import androidx.media3.common.C.WAKE_MODE_LOCAL
import androidx.media3.common.MediaItem
import androidx.media3.common.PlaybackException
import androidx.media3.common.Player
Expand Down Expand Up @@ -340,6 +341,11 @@ class ViewVideoFragment : ViewMediaFragment(), Injectable {
addListener(mediaPlayerListener)
repeatMode = Player.REPEAT_MODE_ONE
playWhenReady = true
// When playing audio, allow the screen to sleep but not the CPU.
// See also KEEP_SCREEN_ON in ViewMediaActivity.kt.
if (isAudio) {
setWakeMode(WAKE_MODE_LOCAL)
}
seekTo(savedSeekPosition)
prepare()
player = this
Expand Down