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" applicationId "com.lagradost.cloudstream3"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 31 targetSdkVersion 31
versionCode 30 versionCode 31
versionName "2.1.1" versionName "2.1.2"
resValue "string", "app_version", resValue "string", "app_version",
"${defaultConfig.versionName}${versionNameSuffix ?: ""}" "${defaultConfig.versionName}${versionNameSuffix ?: ""}"

View file

@ -137,12 +137,27 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
} }
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean { 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) { 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 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 PlayerEventType.SeekBack
} }
KeyEvent.KEYCODE_MEDIA_NEXT -> { KeyEvent.KEYCODE_MEDIA_NEXT -> {
@ -157,15 +172,24 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
KeyEvent.KEYCODE_MEDIA_PLAY -> { KeyEvent.KEYCODE_MEDIA_PLAY -> {
PlayerEventType.Play PlayerEventType.Play
} }
KeyEvent.KEYCODE_L -> { KeyEvent.KEYCODE_L, KeyEvent.KEYCODE_NUMPAD_7 -> {
PlayerEventType.Lock PlayerEventType.Lock
} }
KeyEvent.KEYCODE_H -> { KeyEvent.KEYCODE_H, KeyEvent.KEYCODE_MENU -> {
PlayerEventType.ToggleHide PlayerEventType.ToggleHide
} }
KeyEvent.KEYCODE_M -> { KeyEvent.KEYCODE_M, KeyEvent.KEYCODE_VOLUME_MUTE -> {
PlayerEventType.ToggleMute 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 KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, KeyEvent.KEYCODE_P, KeyEvent.KEYCODE_SPACE -> { // space is not captured due to navigation
PlayerEventType.PlayPauseToggle 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.anime, listOf(TvType.Anime, TvType.ONA, TvType.AnimeMovie)),
Pair(R.string.torrent, listOf(TvType.Torrent)), Pair(R.string.torrent, listOf(TvType.Torrent)),
).filter { item -> currentApi.supportedTypes.any { type -> item.second.contains(type) } } ).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 home_provider_meta_info?.isVisible = true
} }
} }

View file

@ -136,6 +136,9 @@ enum class PlayerEventType(val value: Int) {
ToggleMute(8), ToggleMute(8),
Lock(9), Lock(9),
ToggleHide(10), ToggleHide(10),
ShowSpeed(11),
ShowMirrors(12),
Resize(13),
} }
/* /*
@ -404,7 +407,7 @@ class PlayerFragment : Fragment() {
private fun onClickChange() { private fun onClickChange() {
isShowing = !isShowing isShowing = !isShowing
activity?.hideSystemUI()
updateClick() updateClick()
} }
@ -826,6 +829,14 @@ class PlayerFragment : Fragment() {
} }
isLocked = !isLocked isLocked = !isLocked
if(isLocked && isShowing) {
player_pause_holder?.postDelayed({
if (isLocked && isShowing) {
onClickChange()
}
}, 200)
}
//if(isShowing) { //if(isShowing) {
val fadeTo = if (isLocked) 0f else 1f val fadeTo = if (isLocked) 0f else 1f
@ -1015,6 +1026,9 @@ class PlayerFragment : Fragment() {
skipToNextEpisode() skipToNextEpisode()
} }
} }
PlayerEventType.PrevEpisode.value -> {
//TODO PrevEpisode
}
PlayerEventType.Lock.value -> { PlayerEventType.Lock.value -> {
toggleLock() toggleLock()
} }
@ -1031,6 +1045,128 @@ class PlayerFragment : Fragment() {
exoPlayer.volume = 0f 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) { } catch (e: Exception) {
logError(e) logError(e)
@ -1367,7 +1503,7 @@ class PlayerFragment : Fragment() {
} }
lock_player?.setOnClickListener { lock_player?.setOnClickListener {
toggleLock() handlePlayerEvent(PlayerEventType.Lock)
} }
class Listener : DoubleClickListener(this) { class Listener : DoubleClickListener(this) {
@ -1386,8 +1522,7 @@ class PlayerFragment : Fragment() {
} }
override fun onSingleClick() { override fun onSingleClick() {
onClickChange() handlePlayerEvent(PlayerEventType.ToggleHide)
activity?.hideSystemUI()
} }
override fun onMotionEvent(event: MotionEvent) { override fun onMotionEvent(event: MotionEvent) {
@ -1415,132 +1550,18 @@ class PlayerFragment : Fragment() {
playback_speed_btt?.isVisible = playBackSpeedEnabled playback_speed_btt?.isVisible = playBackSpeedEnabled
playback_speed_btt?.setOnClickListener { playback_speed_btt?.setOnClickListener {
val speedsText = listOf("0.5x", "0.75x", "1x", "1.25x", "1.5x", "1.75x", "2x") handlePlayerEvent(PlayerEventType.ShowSpeed)
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")
}
} }
sources_btt.setOnClickListener { sources_btt.setOnClickListener {
if (!this::exoPlayer.isInitialized) return@setOnClickListener handlePlayerEvent(PlayerEventType.ShowMirrors)
//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()
}
} }
player_view?.resizeMode = resizeModes[resizeMode].first player_view?.resizeMode = resizeModes[resizeMode].first
if (playerResizeEnabled) { if (playerResizeEnabled) {
resize_player?.visibility = VISIBLE resize_player?.visibility = VISIBLE
resize_player?.setOnClickListener { resize_player?.setOnClickListener {
resizeMode = (resizeMode + 1) % resizeModes.size handlePlayerEvent(PlayerEventType.Resize)
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
} }
} else { } else {
resize_player?.visibility = GONE resize_player?.visibility = GONE
@ -1551,9 +1572,7 @@ class PlayerFragment : Fragment() {
} }
skip_episode?.setOnClickListener { skip_episode?.setOnClickListener {
if (hasNextEpisode()) { handlePlayerEvent(PlayerEventType.NextEpisode)
skipToNextEpisode()
}
} }
changeSkip() 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" android:text="@string/home_play"
app:icon="@drawable/ic_baseline_play_arrow_24" 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>
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:nextFocusLeft="@id/home_main_play" android:nextFocusLeft="@id/home_main_play"
@ -236,7 +237,9 @@
android:id="@+id/home_main_info" android:id="@+id/home_main_info"
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:layout_width="120dp">
android:minWidth="120dp"
android:layout_width="wrap_content">
</com.google.android.material.button.MaterialButton> </com.google.android.material.button.MaterialButton>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
@ -261,12 +264,7 @@
<TextView <TextView
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:id="@+id/home_watch_parent_item_title" android:id="@+id/home_watch_parent_item_title"
android:layout_width="wrap_content" style="@style/WatchHeaderText"
android:layout_height="wrap_content"
android:textColor="?attr/textColor"
android:gravity="center_vertical"
android:textSize="18sp"
android:textStyle="bold"
android:text="@string/continue_watching" android:text="@string/continue_watching"
/> />
<ImageView <ImageView
@ -321,12 +319,7 @@
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginStart="40dp" android:layout_marginStart="40dp"
android:id="@+id/home_bookmarked_parent_item_title" android:id="@+id/home_bookmarked_parent_item_title"
android:layout_width="wrap_content" style="@style/WatchHeaderText"
android:layout_height="wrap_content"
android:textColor="?attr/textColor"
android:gravity="center_vertical"
android:textSize="18sp"
android:textStyle="bold"
tools:text="Bookmarked" tools:text="Bookmarked"
/> />
<ImageView <ImageView

View file

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

View file

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

View file

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

View file

@ -150,6 +150,16 @@
<item name="drawableEndCompat">@drawable/ic_baseline_keyboard_arrow_right_24</item> <item name="drawableEndCompat">@drawable/ic_baseline_keyboard_arrow_right_24</item>
</style> </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"> <style name="NiceButton">
<item name="android:padding">5dp</item> <item name="android:padding">5dp</item>
<item name="android:layout_marginStart">5dp</item> <item name="android:layout_marginStart">5dp</item>