Merge pull request #209 from janisslsm/quality-seek

Seek back to last position and added Audio Focus to Exo Player
This commit is contained in:
Kavin 2022-05-15 04:37:04 +01:00 committed by GitHub
commit 9033390e2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -36,11 +36,13 @@ import com.github.libretube.adapters.CommentsAdapter
import com.github.libretube.adapters.TrendingAdapter
import com.github.libretube.obj.PipedStream
import com.github.libretube.obj.Subscribe
import com.google.android.exoplayer2.C
import com.google.android.exoplayer2.ExoPlayer
import com.google.android.exoplayer2.MediaItem
import com.google.android.exoplayer2.MediaItem.SubtitleConfiguration
import com.google.android.exoplayer2.MediaItem.fromUri
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.audio.AudioAttributes
import com.google.android.exoplayer2.ext.cronet.CronetDataSource
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory
import com.google.android.exoplayer2.source.MediaSource
@ -323,6 +325,10 @@ class PlayerFragment : Fragment() {
cronetDataSourceFactory
)
val audioAttributes = AudioAttributes.Builder()
.setUsage(C.USAGE_MEDIA)
.setContentType(C.CONTENT_TYPE_MOVIE)
.build()
exoPlayer = ExoPlayer.Builder(view.context)
.setMediaSourceFactory(DefaultMediaSourceFactory(dataSourceFactory))
@ -335,6 +341,7 @@ class PlayerFragment : Fragment() {
exoPlayerView.setRepeatToggleModes(RepeatModeUtil.REPEAT_TOGGLE_MODE_ALL);
// exoPlayerView.controllerShowTimeoutMs = 1500
exoPlayerView.controllerHideOnTouch = true
exoPlayer.setAudioAttributes(audioAttributes,true);
exoPlayerView.player = exoPlayer
val sharedPreferences =
PreferenceManager.getDefaultSharedPreferences(requireContext())
@ -435,6 +442,7 @@ class PlayerFragment : Fragment() {
val builder: AlertDialog.Builder? = activity?.let {
AlertDialog.Builder(it)
}
var lastPosition = exoPlayer.currentPosition
builder!!.setTitle(R.string.choose_quality_dialog)
.setItems(
videosNameArray,
@ -484,6 +492,7 @@ class PlayerFragment : Fragment() {
MergingMediaSource(videoSource, audioSource)
exoPlayer.setMediaSource(mergeSource)
}
exoPlayer.seekTo(lastPosition);
view.findViewById<TextView>(R.id.quality_text).text =
videosNameArray[which]
}

View File

@ -4,8 +4,4 @@ import android.app.Application
class myApp : Application() {
companion object {
@JvmField
var seekTo : Long? = 0
}
}