mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-05-25 02:52:14 +02:00
Allow configuring stability threshold time and ensure there is no more than 1 job active at a time for SimpleOrientationListener.
This commit is contained in:
parent
f20a708b36
commit
0f4e4a7d97
@ -478,18 +478,22 @@ class Settings : FragmentedStorageFileJson() {
|
|||||||
@DropdownFieldOptionsId(R.array.rotation_zone)
|
@DropdownFieldOptionsId(R.array.rotation_zone)
|
||||||
var rotationZone: Int = 2;
|
var rotationZone: Int = 2;
|
||||||
|
|
||||||
@FormField(R.string.full_autorotate_lock, FieldForm.TOGGLE, R.string.full_autorotate_lock_description, 16)
|
@FormField(R.string.stability_threshold_time, FieldForm.DROPDOWN, R.string.stability_threshold_time_description, 16)
|
||||||
|
@DropdownFieldOptionsId(R.array.rotation_threshold_time)
|
||||||
|
var stabilityThresholdTime: Int = 1;
|
||||||
|
|
||||||
|
@FormField(R.string.full_autorotate_lock, FieldForm.TOGGLE, R.string.full_autorotate_lock_description, 17)
|
||||||
var fullAutorotateLock: Boolean = false;
|
var fullAutorotateLock: Boolean = false;
|
||||||
|
|
||||||
@FormField(R.string.prefer_webm, FieldForm.TOGGLE, R.string.prefer_webm_description, 17)
|
@FormField(R.string.prefer_webm, FieldForm.TOGGLE, R.string.prefer_webm_description, 18)
|
||||||
var preferWebmVideo: Boolean = false;
|
var preferWebmVideo: Boolean = false;
|
||||||
@FormField(R.string.prefer_webm_audio, FieldForm.TOGGLE, R.string.prefer_webm_audio_description, 18)
|
@FormField(R.string.prefer_webm_audio, FieldForm.TOGGLE, R.string.prefer_webm_audio_description, 19)
|
||||||
var preferWebmAudio: Boolean = false;
|
var preferWebmAudio: Boolean = false;
|
||||||
|
|
||||||
@FormField(R.string.allow_under_cutout, FieldForm.TOGGLE, R.string.allow_under_cutout_description, 19)
|
@FormField(R.string.allow_under_cutout, FieldForm.TOGGLE, R.string.allow_under_cutout_description, 20)
|
||||||
var allowVideoToGoUnderCutout: Boolean = true;
|
var allowVideoToGoUnderCutout: Boolean = true;
|
||||||
|
|
||||||
@FormField(R.string.autoplay, FieldForm.TOGGLE, R.string.autoplay, 20)
|
@FormField(R.string.autoplay, FieldForm.TOGGLE, R.string.autoplay, 21)
|
||||||
var autoplay: Boolean = false;
|
var autoplay: Boolean = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import com.futo.platformplayer.constructs.Event1
|
|||||||
import com.futo.platformplayer.logging.Logger
|
import com.futo.platformplayer.logging.Logger
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@ -17,13 +18,23 @@ class SimpleOrientationListener(
|
|||||||
) {
|
) {
|
||||||
private var lastOrientation: Int = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
private var lastOrientation: Int = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
||||||
private var lastStableOrientation: Int = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
private var lastStableOrientation: Int = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
||||||
private val stabilityThresholdTime = 500L
|
private var _currentJob: Job? = null
|
||||||
|
|
||||||
val onOrientationChanged = Event1<Int>()
|
val onOrientationChanged = Event1<Int>()
|
||||||
|
|
||||||
private val orientationListener = object : OrientationEventListener(activity, SensorManager.SENSOR_DELAY_UI) {
|
private val orientationListener = object : OrientationEventListener(activity, SensorManager.SENSOR_DELAY_UI) {
|
||||||
override fun onOrientationChanged(orientation: Int) {
|
override fun onOrientationChanged(orientation: Int) {
|
||||||
//val rotationZone = 45
|
//val rotationZone = 45
|
||||||
|
val stabilityThresholdTime = when (Settings.instance.playback.stabilityThresholdTime) {
|
||||||
|
0 -> 100L
|
||||||
|
1 -> 500L
|
||||||
|
2 -> 750L
|
||||||
|
3 -> 1000L
|
||||||
|
4 -> 1500L
|
||||||
|
5 -> 2000L
|
||||||
|
else -> 500L
|
||||||
|
}
|
||||||
|
|
||||||
val rotationZone = when (Settings.instance.playback.rotationZone) {
|
val rotationZone = when (Settings.instance.playback.rotationZone) {
|
||||||
0 -> 15
|
0 -> 15
|
||||||
1 -> 30
|
1 -> 30
|
||||||
@ -42,7 +53,8 @@ class SimpleOrientationListener(
|
|||||||
if (newOrientation != lastStableOrientation) {
|
if (newOrientation != lastStableOrientation) {
|
||||||
lastStableOrientation = newOrientation
|
lastStableOrientation = newOrientation
|
||||||
|
|
||||||
lifecycleScope.launch(Dispatchers.Main) {
|
_currentJob?.cancel()
|
||||||
|
_currentJob = lifecycleScope.launch(Dispatchers.Main) {
|
||||||
try {
|
try {
|
||||||
delay(stabilityThresholdTime)
|
delay(stabilityThresholdTime)
|
||||||
if (newOrientation == lastStableOrientation) {
|
if (newOrientation == lastStableOrientation) {
|
||||||
@ -63,6 +75,8 @@ class SimpleOrientationListener(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun stopListening() {
|
fun stopListening() {
|
||||||
|
_currentJob?.cancel()
|
||||||
|
_currentJob = null
|
||||||
orientationListener.disable()
|
orientationListener.disable()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,6 +377,8 @@
|
|||||||
<string name="reverse_portrait_description">Allow app to flip into reverse portrait</string>
|
<string name="reverse_portrait_description">Allow app to flip into reverse portrait</string>
|
||||||
<string name="rotation_zone">Rotation zone</string>
|
<string name="rotation_zone">Rotation zone</string>
|
||||||
<string name="rotation_zone_description">Specify the sensitivity of rotation zones (decrease to make less sensitive)</string>
|
<string name="rotation_zone_description">Specify the sensitivity of rotation zones (decrease to make less sensitive)</string>
|
||||||
|
<string name="stability_threshold_time">Stability threshold time</string>
|
||||||
|
<string name="stability_threshold_time_description">Specify the duration the orientation needs to be the same to trigger a rotation</string>
|
||||||
<string name="prefer_webm">Prefer Webm Video Codecs</string>
|
<string name="prefer_webm">Prefer Webm Video Codecs</string>
|
||||||
<string name="prefer_webm_description">If player should prefer Webm codecs (vp9/opus) over mp4 codecs (h264/AAC), may result in worse compatibility.</string>
|
<string name="prefer_webm_description">If player should prefer Webm codecs (vp9/opus) over mp4 codecs (h264/AAC), may result in worse compatibility.</string>
|
||||||
<string name="full_autorotate_lock">Full auto rotate lock</string>
|
<string name="full_autorotate_lock">Full auto rotate lock</string>
|
||||||
@ -968,4 +970,12 @@
|
|||||||
<item>30</item>
|
<item>30</item>
|
||||||
<item>45</item>
|
<item>45</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
<string-array name="rotation_threshold_time">
|
||||||
|
<item>100</item>
|
||||||
|
<item>500</item>
|
||||||
|
<item>750</item>
|
||||||
|
<item>1000</item>
|
||||||
|
<item>1500</item>
|
||||||
|
<item>2000</item>
|
||||||
|
</string-array>
|
||||||
</resources>
|
</resources>
|
Loading…
x
Reference in New Issue
Block a user