Merge pull request #2702 from Bnyro/master

Remove unused radio buttons from download dialog
This commit is contained in:
Bnyro 2023-01-14 20:02:24 +01:00 committed by GitHub
commit 18190c33b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 64 deletions

View File

@ -20,17 +20,22 @@ import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
import com.github.libretube.db.DatabaseHolder.Companion.Database import com.github.libretube.db.DatabaseHolder.Companion.Database
import com.github.libretube.enums.FileType import com.github.libretube.enums.FileType
import com.github.libretube.extensions.awaitQuery import com.github.libretube.extensions.awaitQuery
import com.github.libretube.extensions.updateParameters
import com.github.libretube.ui.base.BaseActivity import com.github.libretube.ui.base.BaseActivity
import com.github.libretube.ui.extensions.setAspectRatio import com.github.libretube.ui.extensions.setAspectRatio
import com.github.libretube.ui.models.PlayerViewModel import com.github.libretube.ui.models.PlayerViewModel
import com.github.libretube.util.PlayerHelper import com.github.libretube.util.PlayerHelper
import com.google.android.exoplayer2.C
import com.google.android.exoplayer2.ExoPlayer import com.google.android.exoplayer2.ExoPlayer
import com.google.android.exoplayer2.MediaItem import com.google.android.exoplayer2.MediaItem
import com.google.android.exoplayer2.MediaItem.SubtitleConfiguration
import com.google.android.exoplayer2.Player import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.source.MergingMediaSource import com.google.android.exoplayer2.source.MergingMediaSource
import com.google.android.exoplayer2.source.ProgressiveMediaSource import com.google.android.exoplayer2.source.ProgressiveMediaSource
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector
import com.google.android.exoplayer2.ui.StyledPlayerView import com.google.android.exoplayer2.ui.StyledPlayerView
import com.google.android.exoplayer2.upstream.FileDataSource import com.google.android.exoplayer2.upstream.FileDataSource
import com.google.android.exoplayer2.util.MimeTypes
import java.io.File import java.io.File
class OfflinePlayerActivity : BaseActivity() { class OfflinePlayerActivity : BaseActivity() {
@ -38,6 +43,8 @@ class OfflinePlayerActivity : BaseActivity() {
private lateinit var videoId: String private lateinit var videoId: String
private lateinit var player: ExoPlayer private lateinit var player: ExoPlayer
private lateinit var playerView: StyledPlayerView private lateinit var playerView: StyledPlayerView
private lateinit var trackSelector: DefaultTrackSelector
private lateinit var playerBinding: ExoStyledPlayerControlViewBinding private lateinit var playerBinding: ExoStyledPlayerControlViewBinding
private val playerViewModel: PlayerViewModel by viewModels() private val playerViewModel: PlayerViewModel by viewModels()
@ -60,8 +67,11 @@ class OfflinePlayerActivity : BaseActivity() {
} }
private fun initializePlayer() { private fun initializePlayer() {
trackSelector = DefaultTrackSelector(this)
player = ExoPlayer.Builder(this) player = ExoPlayer.Builder(this)
.setHandleAudioBecomingNoisy(true) .setHandleAudioBecomingNoisy(true)
.setTrackSelector(trackSelector)
.build().apply { .build().apply {
addListener(object : Player.Listener { addListener(object : Player.Listener {
override fun onEvents(player: Player, events: Player.Events) { override fun onEvents(player: Player, events: Player.Events) {
@ -75,9 +85,9 @@ class OfflinePlayerActivity : BaseActivity() {
} }
playerView = binding.player playerView = binding.player
playerView.setShowSubtitleButton(true)
playerView.subtitleView?.visibility = View.VISIBLE
playerView.player = player playerView.player = player
playerBinding = binding.player.binding playerBinding = binding.player.binding
playerBinding.fullscreen.visibility = View.GONE playerBinding.fullscreen.visibility = View.GONE
@ -85,11 +95,13 @@ class OfflinePlayerActivity : BaseActivity() {
finish() finish()
} }
PlayerHelper.applyCaptionsStyle(this, playerView.subtitleView)
binding.player.initialize( binding.player.initialize(
null, null,
binding.doubleTapOverlay.binding, binding.doubleTapOverlay.binding,
binding.playerGestureControlsView.binding, binding.playerGestureControlsView.binding,
null trackSelector
) )
} }
@ -110,40 +122,59 @@ class OfflinePlayerActivity : BaseActivity() {
val audioUri = audio?.path?.let { File(it).toUri() } val audioUri = audio?.path?.let { File(it).toUri() }
val subtitleUri = subtitle?.path?.let { File(it).toUri() } val subtitleUri = subtitle?.path?.let { File(it).toUri() }
setMediaSource( setMediaSource(videoUri, audioUri, subtitleUri)
videoUri,
audioUri trackSelector.updateParameters {
) setPreferredTextRoleFlags(C.ROLE_FLAG_CAPTION)
setPreferredTextLanguage("en")
}
player.prepare() player.prepare()
player.play() player.play()
} }
private fun setMediaSource(videoUri: Uri?, audioUri: Uri?) { private fun setMediaSource(videoUri: Uri?, audioUri: Uri?, subtitleUri: Uri?) {
val subtitle = subtitleUri?.let {
SubtitleConfiguration.Builder(it)
.setMimeType(MimeTypes.APPLICATION_SUBRIP)
.build()
}
subtitle?.id
when { when {
videoUri != null && audioUri != null -> { videoUri != null && audioUri != null -> {
val videoItem = MediaItem.Builder()
.setUri(videoUri)
.apply {
if (subtitle != null) setSubtitleConfigurations(listOf(subtitle))
}
.build()
val videoSource = ProgressiveMediaSource.Factory(FileDataSource.Factory()) val videoSource = ProgressiveMediaSource.Factory(FileDataSource.Factory())
.createMediaSource( .createMediaSource(videoItem)
MediaItem.fromUri(videoUri)
)
val audioSource = ProgressiveMediaSource.Factory(FileDataSource.Factory()) val audioSource = ProgressiveMediaSource.Factory(FileDataSource.Factory())
.createMediaSource( .createMediaSource(MediaItem.fromUri(audioUri))
MediaItem.fromUri(audioUri)
)
val mediaSource = MergingMediaSource( val mediaSource = MergingMediaSource(audioSource, videoSource)
audioSource,
videoSource
)
player.setMediaSource(mediaSource) player.setMediaSource(mediaSource)
} }
videoUri != null -> player.setMediaItem( videoUri != null -> player.setMediaItem(
MediaItem.fromUri(videoUri) MediaItem.Builder()
.setUri(videoUri)
.apply {
if (subtitle != null) setSubtitleConfigurations(listOf(subtitle))
}
.build()
) )
audioUri != null -> player.setMediaItem( audioUri != null -> player.setMediaItem(
MediaItem.fromUri(audioUri) MediaItem.Builder()
.setUri(audioUri)
.apply {
if (subtitle != null) setSubtitleConfigurations(listOf(subtitle))
}
.build()
) )
} }
} }

View File

@ -31,14 +31,6 @@ class DownloadDialog(
fetchAvailableSources() fetchAvailableSources()
binding.audioRadio.setOnClickListener {
binding.videoSpinner.visibility = View.GONE
}
binding.videoRadio.setOnClickListener {
binding.videoSpinner.visibility = View.VISIBLE
}
binding.fileName.filters += InputFilter { source, start, end, _, _, _ -> binding.fileName.filters += InputFilter { source, start, end, _, _, _ ->
if (source.isNullOrBlank()) { if (source.isNullOrBlank()) {
return@InputFilter null return@InputFilter null

View File

@ -103,9 +103,7 @@ import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.audio.AudioAttributes import com.google.android.exoplayer2.audio.AudioAttributes
import com.google.android.exoplayer2.ext.cronet.CronetDataSource import com.google.android.exoplayer2.ext.cronet.CronetDataSource
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory import com.google.android.exoplayer2.source.DefaultMediaSourceFactory
import com.google.android.exoplayer2.text.Cue.TEXT_SIZE_TYPE_ABSOLUTE
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector import com.google.android.exoplayer2.trackselection.DefaultTrackSelector
import com.google.android.exoplayer2.ui.CaptionStyleCompat
import com.google.android.exoplayer2.ui.StyledPlayerView import com.google.android.exoplayer2.ui.StyledPlayerView
import com.google.android.exoplayer2.upstream.DefaultDataSource import com.google.android.exoplayer2.upstream.DefaultDataSource
import com.google.android.exoplayer2.util.MimeTypes import com.google.android.exoplayer2.util.MimeTypes
@ -816,7 +814,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
private fun prepareExoPlayerView() { private fun prepareExoPlayerView() {
exoPlayerView.apply { exoPlayerView.apply {
setShowSubtitleButton(true) setShowSubtitleButton(false)
setShowNextButton(false) setShowNextButton(false)
setShowPreviousButton(false) setShowPreviousButton(false)
// controllerShowTimeoutMs = 1500 // controllerShowTimeoutMs = 1500
@ -827,18 +825,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
playerBinding.exoProgress.setPlayer(exoPlayer) playerBinding.exoProgress.setPlayer(exoPlayer)
applyCaptionStyle() PlayerHelper.applyCaptionsStyle(requireContext(), exoPlayerView.subtitleView)
}
private fun applyCaptionStyle() {
val captionStyle = PlayerHelper.getCaptionStyle(requireContext())
exoPlayerView.subtitleView?.apply {
setApplyEmbeddedFontSizes(false)
setFixedTextSize(TEXT_SIZE_TYPE_ABSOLUTE, PlayerHelper.captionsTextSize)
if (!PlayerHelper.useSystemCaptionStyle) return
setApplyEmbeddedStyles(captionStyle == CaptionStyleCompat.DEFAULT)
setStyle(captionStyle)
}
} }
private fun localizedDate(date: String?): String? { private fun localizedDate(date: String?): String? {

View File

@ -16,7 +16,9 @@ import com.github.libretube.api.obj.PipedStream
import com.github.libretube.constants.PreferenceKeys import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.enums.AudioQuality import com.github.libretube.enums.AudioQuality
import com.github.libretube.enums.PlayerEvent import com.github.libretube.enums.PlayerEvent
import com.google.android.exoplayer2.text.Cue
import com.google.android.exoplayer2.ui.CaptionStyleCompat import com.google.android.exoplayer2.ui.CaptionStyleCompat
import com.google.android.exoplayer2.ui.SubtitleView
import com.google.android.exoplayer2.video.VideoSize import com.google.android.exoplayer2.video.VideoSize
import kotlin.math.roundToInt import kotlin.math.roundToInt
@ -442,4 +444,18 @@ object PlayerHelper {
) )
return actions return actions
} }
/**
* Load the captions style according to the users preferences
*/
fun applyCaptionsStyle(context: Context, subtitleView: SubtitleView?) {
val captionStyle = getCaptionStyle(context)
subtitleView?.apply {
setApplyEmbeddedFontSizes(false)
setFixedTextSize(Cue.TEXT_SIZE_TYPE_ABSOLUTE, captionsTextSize)
if (!useSystemCaptionStyle) return
setApplyEmbeddedStyles(captionStyle == CaptionStyleCompat.DEFAULT)
setStyle(captionStyle)
}
}
} }

View File

@ -25,27 +25,6 @@
android:inputType="text" /> android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checkedButton="@id/video_radio"
android:orientation="horizontal">
<RadioButton
android:id="@+id/video_radio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/video" />
<RadioButton
android:id="@+id/audio_radio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="@string/audio" />
</RadioGroup>
<Spinner <Spinner
android:id="@+id/video_spinner" android:id="@+id/video_spinner"
android:layout_width="match_parent" android:layout_width="match_parent"