player stuff and fixes

This commit is contained in:
LagradOst 2021-10-27 21:45:15 +02:00
parent 84b850fd15
commit 2dabc111cd
10 changed files with 231 additions and 186 deletions

View file

@ -34,8 +34,8 @@ android {
applicationId "com.lagradost.cloudstream3"
minSdkVersion 21
targetSdkVersion 31
versionCode 30
versionName "2.1.1"
versionCode 31
versionName "2.1.2"
resValue "string", "app_version",
"${defaultConfig.versionName}${versionNameSuffix ?: ""}"

View file

@ -137,12 +137,27 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
}
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
println("Keycode: $keyCode")
//println("Keycode: $keyCode")
//showToast(
// this,
// "Got Keycode $keyCode | ${KeyEvent.keyCodeToString(keyCode)} \n ${event?.action}",
// Toast.LENGTH_LONG
//)
// Tested keycodes on remote:
// KeyEvent.KEYCODE_MEDIA_FAST_FORWARD
// KeyEvent.KEYCODE_MEDIA_REWIND
// KeyEvent.KEYCODE_MENU
// KeyEvent.KEYCODE_MEDIA_NEXT
// KeyEvent.KEYCODE_MEDIA_PREVIOUS
// KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE
// 149 keycode_numpad 5
when (keyCode) {
KeyEvent.KEYCODE_FORWARD, KeyEvent.KEYCODE_D, KeyEvent.KEYCODE_MEDIA_SKIP_FORWARD -> {
KeyEvent.KEYCODE_FORWARD, KeyEvent.KEYCODE_D, KeyEvent.KEYCODE_MEDIA_SKIP_FORWARD, KeyEvent.KEYCODE_MEDIA_FAST_FORWARD -> {
PlayerEventType.SeekForward
}
KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_A, KeyEvent.KEYCODE_MEDIA_SKIP_BACKWARD -> {
KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_A, KeyEvent.KEYCODE_MEDIA_SKIP_BACKWARD, KeyEvent.KEYCODE_MEDIA_REWIND -> {
PlayerEventType.SeekBack
}
KeyEvent.KEYCODE_MEDIA_NEXT -> {
@ -157,15 +172,24 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
KeyEvent.KEYCODE_MEDIA_PLAY -> {
PlayerEventType.Play
}
KeyEvent.KEYCODE_L -> {
KeyEvent.KEYCODE_L, KeyEvent.KEYCODE_NUMPAD_7 -> {
PlayerEventType.Lock
}
KeyEvent.KEYCODE_H -> {
KeyEvent.KEYCODE_H, KeyEvent.KEYCODE_MENU -> {
PlayerEventType.ToggleHide
}
KeyEvent.KEYCODE_M -> {
KeyEvent.KEYCODE_M, KeyEvent.KEYCODE_VOLUME_MUTE -> {
PlayerEventType.ToggleMute
}
KeyEvent.KEYCODE_S, KeyEvent.KEYCODE_NUMPAD_9 -> {
PlayerEventType.ShowMirrors
}
KeyEvent.KEYCODE_E, KeyEvent.KEYCODE_NUMPAD_3 -> {
PlayerEventType.ShowSpeed
}
KeyEvent.KEYCODE_R, KeyEvent.KEYCODE_NUMPAD_0 -> {
PlayerEventType.Resize
}
KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, KeyEvent.KEYCODE_P, KeyEvent.KEYCODE_SPACE -> { // space is not captured due to navigation
PlayerEventType.PlayPauseToggle
}

View file

@ -223,7 +223,7 @@ class HomeFragment : Fragment() {
Pair(R.string.anime, listOf(TvType.Anime, TvType.ONA, TvType.AnimeMovie)),
Pair(R.string.torrent, listOf(TvType.Torrent)),
).filter { item -> currentApi.supportedTypes.any { type -> item.second.contains(type) } }
home_provider_meta_info?.text = typeChoices.joinToString(separator = " ") { getString(it.first) }
home_provider_meta_info?.text = typeChoices.joinToString(separator = ", ") { getString(it.first) }
home_provider_meta_info?.isVisible = true
}
}

View file

@ -136,6 +136,9 @@ enum class PlayerEventType(val value: Int) {
ToggleMute(8),
Lock(9),
ToggleHide(10),
ShowSpeed(11),
ShowMirrors(12),
Resize(13),
}
/*
@ -404,7 +407,7 @@ class PlayerFragment : Fragment() {
private fun onClickChange() {
isShowing = !isShowing
activity?.hideSystemUI()
updateClick()
}
@ -821,11 +824,19 @@ class PlayerFragment : Fragment() {
private var localData: LoadResponse? = null
private fun toggleLock() {
if(!isShowing) {
if (!isShowing) {
onClickChange()
}
isLocked = !isLocked
if(isLocked && isShowing) {
player_pause_holder?.postDelayed({
if (isLocked && isShowing) {
onClickChange()
}
}, 200)
}
//if(isShowing) {
val fadeTo = if (isLocked) 0f else 1f
@ -1015,6 +1026,9 @@ class PlayerFragment : Fragment() {
skipToNextEpisode()
}
}
PlayerEventType.PrevEpisode.value -> {
//TODO PrevEpisode
}
PlayerEventType.Lock.value -> {
toggleLock()
}
@ -1031,6 +1045,128 @@ class PlayerFragment : Fragment() {
exoPlayer.volume = 0f
}
}
PlayerEventType.Resize.value -> {
resizeMode = (resizeMode + 1) % resizeModes.size
context?.setKey(RESIZE_MODE_KEY, resizeMode)
player_view?.resizeMode = resizeModes[resizeMode].first
showToast(activity, resizeModes[resizeMode].second, LENGTH_SHORT)
}
PlayerEventType.ShowSpeed.value -> {
val speedsText = listOf("0.5x", "0.75x", "1x", "1.25x", "1.5x", "1.75x", "2x")
val speedsNumbers = listOf(0.5f, 0.75f, 1f, 1.25f, 1.5f, 1.75f, 2f)
val speedIndex = speedsNumbers.indexOf(playbackSpeed)
context?.let { ctx ->
ctx.showDialog(speedsText, speedIndex, ctx.getString(R.string.player_speed), false, {
activity?.hideSystemUI()
}) { index ->
playbackSpeed = speedsNumbers[index]
requireContext().setKey(PLAYBACK_SPEED_KEY, playbackSpeed)
val param = PlaybackParameters(playbackSpeed)
exoPlayer.playbackParameters = param
player_speed_text?.text =
getString(R.string.player_speed_text_format).format(playbackSpeed).replace(".0x", "x")
}
}
}
PlayerEventType.ShowMirrors.value -> {
if (!this::exoPlayer.isInitialized) return
context?.let { ctx ->
//val isPlaying = exoPlayer.isPlaying
exoPlayer.pause()
val currentSubtitles = activeSubtitles
val sourceBuilder = AlertDialog.Builder(ctx, R.style.AlertDialogCustomBlack)
.setView(R.layout.player_select_source_and_subs)
val sourceDialog = sourceBuilder.create()
sourceDialog.show()
// bottomSheetDialog.setContentView(R.layout.sort_bottom_sheet)
val providerList = sourceDialog.findViewById<ListView>(R.id.sort_providers)!!
val subtitleList = sourceDialog.findViewById<ListView>(R.id.sort_subtitles)!!
val applyButton = sourceDialog.findViewById<MaterialButton>(R.id.apply_btt)!!
val cancelButton = sourceDialog.findViewById<MaterialButton>(R.id.cancel_btt)!!
val subsSettings = sourceDialog.findViewById<View>(R.id.subs_settings)!!
subsSettings.setOnClickListener {
saveArguments()
SubtitlesFragment.push(activity)
sourceDialog.dismiss()
}
var sourceIndex = 0
var startSource = 0
var sources: List<ExtractorLink> = emptyList()
val nonSortedUrls = getUrls()
if (nonSortedUrls.isNullOrEmpty()) {
sourceDialog.findViewById<LinearLayout>(R.id.sort_sources_holder)?.visibility = GONE
} else {
sources = sortUrls(nonSortedUrls)
startSource = sources.indexOf(getCurrentUrl())
sourceIndex = startSource
val sourcesArrayAdapter =
ArrayAdapter<String>(ctx, R.layout.sort_bottom_single_choice)
sourcesArrayAdapter.addAll(sources.map { it.name })
providerList.choiceMode = AbsListView.CHOICE_MODE_SINGLE
providerList.adapter = sourcesArrayAdapter
providerList.setSelection(sourceIndex)
providerList.setItemChecked(sourceIndex, true)
providerList.setOnItemClickListener { _, _, which, _ ->
sourceIndex = which
providerList.setItemChecked(which, true)
}
sourceDialog.setOnDismissListener {
activity?.hideSystemUI()
}
}
val startIndexFromMap =
currentSubtitles.map { it.removeSuffix(" ") }
.indexOf(preferredSubtitles.removeSuffix(" ")) + 1
var subtitleIndex = startIndexFromMap
if (currentSubtitles.isEmpty()) {
sourceDialog.findViewById<LinearLayout>(R.id.sort_subtitles_holder)?.visibility = GONE
} else {
val subsArrayAdapter =
ArrayAdapter<String>(ctx, R.layout.sort_bottom_single_choice)
subsArrayAdapter.add(getString(R.string.no_subtitles))
subsArrayAdapter.addAll(currentSubtitles)
subtitleList.adapter = subsArrayAdapter
subtitleList.choiceMode = AbsListView.CHOICE_MODE_SINGLE
subtitleList.setSelection(subtitleIndex)
subtitleList.setItemChecked(subtitleIndex, true)
subtitleList.setOnItemClickListener { _, _, which, _ ->
subtitleIndex = which
subtitleList.setItemChecked(which, true)
}
}
cancelButton.setOnClickListener {
sourceDialog.dismiss()
}
applyButton.setOnClickListener {
if (sourceIndex != startSource) {
playbackPosition = if (this::exoPlayer.isInitialized) exoPlayer.currentPosition else 0
setMirrorId(sources[sourceIndex].getId())
initPlayer(getCurrentUrl())
}
if (subtitleIndex != startIndexFromMap) {
setPreferredSubLanguage(if (subtitleIndex <= 0) null else currentSubtitles[subtitleIndex - 1])
}
sourceDialog.dismiss()
}
}
}
}
} catch (e: Exception) {
logError(e)
@ -1367,7 +1503,7 @@ class PlayerFragment : Fragment() {
}
lock_player?.setOnClickListener {
toggleLock()
handlePlayerEvent(PlayerEventType.Lock)
}
class Listener : DoubleClickListener(this) {
@ -1386,8 +1522,7 @@ class PlayerFragment : Fragment() {
}
override fun onSingleClick() {
onClickChange()
activity?.hideSystemUI()
handlePlayerEvent(PlayerEventType.ToggleHide)
}
override fun onMotionEvent(event: MotionEvent) {
@ -1415,132 +1550,18 @@ class PlayerFragment : Fragment() {
playback_speed_btt?.isVisible = playBackSpeedEnabled
playback_speed_btt?.setOnClickListener {
val speedsText = listOf("0.5x", "0.75x", "1x", "1.25x", "1.5x", "1.75x", "2x")
val speedsNumbers = listOf(0.5f, 0.75f, 1f, 1.25f, 1.5f, 1.75f, 2f)
val speedIndex = speedsNumbers.indexOf(playbackSpeed)
context?.showDialog(speedsText, speedIndex, getString(R.string.player_speed), false, {
activity?.hideSystemUI()
}) { index ->
playbackSpeed = speedsNumbers[index]
requireContext().setKey(PLAYBACK_SPEED_KEY, playbackSpeed)
val param = PlaybackParameters(playbackSpeed)
exoPlayer.playbackParameters = param
player_speed_text?.text =
getString(R.string.player_speed_text_format).format(playbackSpeed).replace(".0x", "x")
}
handlePlayerEvent(PlayerEventType.ShowSpeed)
}
sources_btt.setOnClickListener {
if (!this::exoPlayer.isInitialized) return@setOnClickListener
//val isPlaying = exoPlayer.isPlaying
exoPlayer.pause()
val currentSubtitles = activeSubtitles
val sourceBuilder = AlertDialog.Builder(view.context, R.style.AlertDialogCustomBlack)
.setView(R.layout.player_select_source_and_subs)
val sourceDialog = sourceBuilder.create()
sourceDialog.show()
// bottomSheetDialog.setContentView(R.layout.sort_bottom_sheet)
val providerList = sourceDialog.findViewById<ListView>(R.id.sort_providers)!!
val subtitleList = sourceDialog.findViewById<ListView>(R.id.sort_subtitles)!!
val applyButton = sourceDialog.findViewById<MaterialButton>(R.id.apply_btt)!!
val cancelButton = sourceDialog.findViewById<MaterialButton>(R.id.cancel_btt)!!
val subsSettings = sourceDialog.findViewById<View>(R.id.subs_settings)!!
subsSettings.setOnClickListener {
saveArguments()
SubtitlesFragment.push(activity)
sourceDialog.dismiss()
}
var sourceIndex = 0
var startSource = 0
var sources: List<ExtractorLink> = emptyList()
val nonSortedUrls = getUrls()
if (nonSortedUrls.isNullOrEmpty()) {
sourceDialog.findViewById<LinearLayout>(R.id.sort_sources_holder)?.visibility = GONE
} else {
sources = sortUrls(nonSortedUrls)
startSource = sources.indexOf(getCurrentUrl())
sourceIndex = startSource
val sourcesArrayAdapter = ArrayAdapter<String>(view.context, R.layout.sort_bottom_single_choice)
sourcesArrayAdapter.addAll(sources.map { it.name })
providerList.choiceMode = AbsListView.CHOICE_MODE_SINGLE
providerList.adapter = sourcesArrayAdapter
providerList.setSelection(sourceIndex)
providerList.setItemChecked(sourceIndex, true)
providerList.setOnItemClickListener { _, _, which, _ ->
sourceIndex = which
providerList.setItemChecked(which, true)
}
sourceDialog.setOnDismissListener {
activity?.hideSystemUI()
}
}
val startIndexFromMap =
currentSubtitles.map { it.removeSuffix(" ") }.indexOf(preferredSubtitles.removeSuffix(" ")) + 1
var subtitleIndex = startIndexFromMap
if (currentSubtitles.isEmpty()) {
sourceDialog.findViewById<LinearLayout>(R.id.sort_subtitles_holder)?.visibility = GONE
} else {
val subsArrayAdapter = ArrayAdapter<String>(view.context, R.layout.sort_bottom_single_choice)
subsArrayAdapter.add(getString(R.string.no_subtitles))
subsArrayAdapter.addAll(currentSubtitles)
subtitleList.adapter = subsArrayAdapter
subtitleList.choiceMode = AbsListView.CHOICE_MODE_SINGLE
subtitleList.setSelection(subtitleIndex)
subtitleList.setItemChecked(subtitleIndex, true)
subtitleList.setOnItemClickListener { _, _, which, _ ->
subtitleIndex = which
subtitleList.setItemChecked(which, true)
}
}
cancelButton.setOnClickListener {
sourceDialog.dismiss()
}
applyButton.setOnClickListener {
if (sourceIndex != startSource) {
playbackPosition = if (this::exoPlayer.isInitialized) exoPlayer.currentPosition else 0
setMirrorId(sources[sourceIndex].getId())
initPlayer(getCurrentUrl())
} /*else {
if (isPlaying) {
// exoPlayer.play()
}
}*/
if (subtitleIndex != startIndexFromMap) {
setPreferredSubLanguage(if (subtitleIndex <= 0) null else currentSubtitles[subtitleIndex - 1])
}
sourceDialog.dismiss()
}
handlePlayerEvent(PlayerEventType.ShowMirrors)
}
player_view?.resizeMode = resizeModes[resizeMode].first
if (playerResizeEnabled) {
resize_player?.visibility = VISIBLE
resize_player?.setOnClickListener {
resizeMode = (resizeMode + 1) % resizeModes.size
requireContext().setKey(RESIZE_MODE_KEY, resizeMode)
player_view?.resizeMode = resizeModes[resizeMode].first
activity?.let { act ->
showToast(act, resizeModes[resizeMode].second, LENGTH_SHORT)
}
//exoPlayer.videoScalingMode = C.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING
handlePlayerEvent(PlayerEventType.Resize)
}
} else {
resize_player?.visibility = GONE
@ -1551,9 +1572,7 @@ class PlayerFragment : Fragment() {
}
skip_episode?.setOnClickListener {
if (hasNextEpisode()) {
skipToNextEpisode()
}
handlePlayerEvent(PlayerEventType.NextEpisode)
}
changeSkip()

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="?attr/colorControlActivated"/>
<item android:color="?attr/grayTextColor"/>
</selector>

View file

@ -219,7 +219,8 @@
android:text="@string/home_play"
app:icon="@drawable/ic_baseline_play_arrow_24"
android:layout_width="120dp">
android:minWidth="120dp"
android:layout_width="wrap_content">
</com.google.android.material.button.MaterialButton>
<com.google.android.material.button.MaterialButton
android:nextFocusLeft="@id/home_main_play"
@ -236,7 +237,9 @@
android:id="@+id/home_main_info"
android:clickable="true"
android:focusable="true"
android:layout_width="120dp">
android:minWidth="120dp"
android:layout_width="wrap_content">
</com.google.android.material.button.MaterialButton>
</LinearLayout>
</LinearLayout>
@ -261,12 +264,7 @@
<TextView
android:layout_gravity="center_vertical"
android:id="@+id/home_watch_parent_item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?attr/textColor"
android:gravity="center_vertical"
android:textSize="18sp"
android:textStyle="bold"
style="@style/WatchHeaderText"
android:text="@string/continue_watching"
/>
<ImageView
@ -321,12 +319,7 @@
android:layout_gravity="center_vertical"
android:layout_marginStart="40dp"
android:id="@+id/home_bookmarked_parent_item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?attr/textColor"
android:gravity="center_vertical"
android:textSize="18sp"
android:textStyle="bold"
style="@style/WatchHeaderText"
tools:text="Bookmarked"
/>
<ImageView

View file

@ -18,12 +18,7 @@
<requestFocus/>
<TextView
android:id="@+id/home_expanded_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?attr/textColor"
android:gravity="center_vertical"
android:textSize="18sp"
android:textStyle="bold"
style="@style/WatchHeaderText"
tools:text="Trending"
/>
<ImageView

View file

@ -17,12 +17,7 @@
android:layout_height="wrap_content">
<TextView
android:id="@+id/home_parent_item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?attr/textColor"
android:gravity="center_vertical"
android:textSize="18sp"
android:textStyle="bold"
style="@style/WatchHeaderText"
tools:text="Trending"
/>
<ImageView

View file

@ -1,12 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="?attr/primaryBlackBackground"
android:layout_height="match_parent">
<!--
app:thumbTint="@color/toggle_selector"
app:trackTint="@color/toggle_selector"-->
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/toggle1"
@ -15,6 +18,7 @@
android:paddingEnd="20dp"
android:textStyle="bold"
android:textSize="20sp"
app:useMaterialThemeColors="false"
android:textColor="?attr/textColor"
tools:text="Search"

View file

@ -150,6 +150,16 @@
<item name="drawableEndCompat">@drawable/ic_baseline_keyboard_arrow_right_24</item>
</style>
<style name="WatchHeaderText">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">?attr/textColor</item>
<item name="android:gravity">center_vertical</item>
<item name="android:textSize">18sp</item>
<item name="android:layout_marginEnd">50dp</item>
<item name="android:textStyle">bold</item>
</style>
<style name="NiceButton">
<item name="android:padding">5dp</item>
<item name="android:layout_marginStart">5dp</item>