From 5271a279f38fddfb092426ef29708062486f58d6 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 30 Jul 2022 13:09:57 +0200 Subject: [PATCH 1/5] indicate that a video is live --- app/build.gradle | 13 +++++------ .../libretube/fragments/PlayerFragment.kt | 13 ++++++++++- .../layout/exo_styled_player_control_view.xml | 23 +++++++++++++++++++ 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 319469cab..9067f4ccd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,3 +1,5 @@ +import java.time.Instant + plugins { id 'com.android.application' id 'kotlin-android' @@ -25,9 +27,8 @@ android { // use the date as version for debug builds if (variant.name == 'debug') { variant.outputs.each { output -> - def date = getDate() - output.versionCodeOverride = date - output.versionNameOverride = date + output.versionCodeOverride = getUnixTime() + output.versionNameOverride = getUnixTime() } } } @@ -104,8 +105,6 @@ dependencies { implementation libs.coil } -static def getDate() { - def date = new Date() - def formattedDate = date.format('yyyyMMddHH') - return Integer.parseInt(formattedDate) +static def getUnixTime() { + return Instant.now().getEpochSecond() } \ No newline at end of file diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index 31d7a2cdf..410edf4da 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -118,6 +118,7 @@ class PlayerFragment : Fragment() { private var playlistId: String? = null private var channelId: String? = null private var isSubscribed: Boolean = false + private var isLive = false /** * for the transition @@ -522,7 +523,6 @@ class PlayerFragment : Fragment() { val playbackSpeedValues = context?.resources?.getStringArray(R.array.playbackSpeedValues)!! exoPlayer.setPlaybackSpeed(playbackSpeed.toFloat()) - Log.e(TAG, playbackSpeed) val speedIndex = playbackSpeedValues.indexOf(playbackSpeed) playerBinding.speedText.text = playbackSpeeds[speedIndex] @@ -769,6 +769,12 @@ class PlayerFragment : Fragment() { // save related streams for autoplay relatedStreams = response.relatedStreams + // duration that's not greater than 0 indicates that the video is live + if (!(response.duration!! > 0)) { + isLive = true + handleLiveVideo() + } + runOnUiThread { // set media sources for the player setResolutionAndSubtitles(response) @@ -793,6 +799,11 @@ class PlayerFragment : Fragment() { run() } + private fun handleLiveVideo() { + playerBinding.exoTime.visibility = View.GONE + playerBinding.liveLL.visibility = View.VISIBLE + } + private fun seekToWatchPosition() { // seek to saved watch position if available val watchPositions = PreferenceHelper.getWatchPositions() diff --git a/app/src/main/res/layout/exo_styled_player_control_view.xml b/app/src/main/res/layout/exo_styled_player_control_view.xml index d7cdd9e77..90ecdcc1c 100644 --- a/app/src/main/res/layout/exo_styled_player_control_view.xml +++ b/app/src/main/res/layout/exo_styled_player_control_view.xml @@ -185,6 +185,29 @@ + + + + + + + + + + Date: Sat, 30 Jul 2022 13:20:11 +0200 Subject: [PATCH 2/5] switch back to 1x speed on live stream end --- .../com/github/libretube/fragments/PlayerFragment.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index 410edf4da..da2697bdd 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -957,7 +957,8 @@ class PlayerFragment : Fragment() { binding.apply { playerViewsInfo.text = context?.getString(R.string.views, response.views.formatShort()) + - " • " + response.uploadDate + if (!isLive) " • " + response.uploadDate else "" + textLike.text = response.likes.formatShort() textDislike.text = response.dislikes.formatShort() ConnectionHelper.loadImage(response.uploaderAvatar, binding.playerChannelImage) @@ -1018,8 +1019,13 @@ class PlayerFragment : Fragment() { !playWhenReady ) + // switch back to normal speed when on the end of live stream + if (isLive && (exoPlayer.duration - exoPlayer.duration < 0.5)) { + exoPlayer.setPlaybackSpeed(1F) + playerBinding.speedText.text = "1x" + } // check if video has ended, next video is available and autoplay is enabled. - if ( + else if ( playbackState == Player.STATE_ENDED && nextStreamId != null && !transitioning && From 3dfd0ba56259ca27f6b28d5208cc5af525387e13 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 30 Jul 2022 13:36:06 +0200 Subject: [PATCH 3/5] indicate time difference --- .../com/github/libretube/fragments/PlayerFragment.kt | 12 +++++++++++- .../res/layout/exo_styled_player_control_view.xml | 9 +++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index da2697bdd..93baf7997 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -19,6 +19,7 @@ import android.os.PowerManager import android.support.v4.media.session.MediaSessionCompat import android.text.Html import android.text.TextUtils +import android.text.format.DateUtils import android.util.Log import android.view.LayoutInflater import android.view.MotionEvent @@ -1020,9 +1021,18 @@ class PlayerFragment : Fragment() { ) // switch back to normal speed when on the end of live stream - if (isLive && (exoPlayer.duration - exoPlayer.duration < 0.5)) { + Log.e(exoPlayer.duration.toString(), exoPlayer.currentPosition.toString()) + if (isLive && (exoPlayer.duration - exoPlayer.currentPosition < 10000)) { exoPlayer.setPlaybackSpeed(1F) playerBinding.speedText.text = "1x" + playerBinding.liveSeparator.visibility = View.GONE + playerBinding.liveDiff.text = "" + } else if (isLive) { + Log.e(TAG, "changing the time") + // live stream but not watching at the end/live position + playerBinding.liveSeparator.visibility = View.VISIBLE + val diffText = DateUtils.formatElapsedTime((exoPlayer.duration - exoPlayer.currentPosition) / 1000) + playerBinding.liveDiff.text = "-$diffText" } // check if video has ended, next video is available and autoplay is enabled. else if ( diff --git a/app/src/main/res/layout/exo_styled_player_control_view.xml b/app/src/main/res/layout/exo_styled_player_control_view.xml index 90ecdcc1c..0edb73433 100644 --- a/app/src/main/res/layout/exo_styled_player_control_view.xml +++ b/app/src/main/res/layout/exo_styled_player_control_view.xml @@ -195,16 +195,17 @@ + style="@style/ExoStyledControls.TimeText.Duration" /> - + style="@style/ExoStyledControls.TimeText.Position" /> From 8e72180057dafad7b764e47241da56564002b9db Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 30 Jul 2022 13:47:45 +0200 Subject: [PATCH 4/5] layout improvements --- .../layout/exo_styled_player_control_view.xml | 22 ++++++++++++------- app/src/main/res/values/style.xml | 11 ++++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/app/src/main/res/layout/exo_styled_player_control_view.xml b/app/src/main/res/layout/exo_styled_player_control_view.xml index 0edb73433..049ec09da 100644 --- a/app/src/main/res/layout/exo_styled_player_control_view.xml +++ b/app/src/main/res/layout/exo_styled_player_control_view.xml @@ -1,5 +1,6 @@ - + style="@style/TimeString" /> - + + style="@style/TimeString" /> @@ -195,17 +199,19 @@ + style="@style/TimeString" /> + style="@style/TimeString" + android:text=" • " + android:visibility="gone" + tools:ignore="HardcodedText" /> + style="@style/TimeString" /> diff --git a/app/src/main/res/values/style.xml b/app/src/main/res/values/style.xml index c7209624d..95315b1f2 100644 --- a/app/src/main/res/values/style.xml +++ b/app/src/main/res/values/style.xml @@ -135,5 +135,16 @@ + \ No newline at end of file From 2946887e21c3ef1bbdb4d901f97a609e15320fab Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 30 Jul 2022 13:53:41 +0200 Subject: [PATCH 5/5] fixes --- .../libretube/fragments/PlayerFragment.kt | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index 93baf7997..3ca26ffe6 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -803,6 +803,29 @@ class PlayerFragment : Fragment() { private fun handleLiveVideo() { playerBinding.exoTime.visibility = View.GONE playerBinding.liveLL.visibility = View.VISIBLE + refreshLiveStatus() + } + + private fun refreshLiveStatus() { + // switch back to normal speed when on the end of live stream + Log.e(exoPlayer.duration.toString(), exoPlayer.currentPosition.toString()) + if (isLive && (exoPlayer.duration - exoPlayer.currentPosition < 10000)) { + exoPlayer.setPlaybackSpeed(1F) + playerBinding.speedText.text = "1x" + playerBinding.liveSeparator.visibility = View.GONE + playerBinding.liveDiff.text = "" + } else if (isLive) { + Log.e(TAG, "changing the time") + // live stream but not watching at the end/live position + playerBinding.liveSeparator.visibility = View.VISIBLE + val diffText = DateUtils.formatElapsedTime( + (exoPlayer.duration - exoPlayer.currentPosition) / 1000 + ) + playerBinding.liveDiff.text = "-$diffText" + } + // call it again + Handler(Looper.getMainLooper()) + .postDelayed(this@PlayerFragment::refreshLiveStatus, 100) } private fun seekToWatchPosition() { @@ -1020,22 +1043,8 @@ class PlayerFragment : Fragment() { !playWhenReady ) - // switch back to normal speed when on the end of live stream - Log.e(exoPlayer.duration.toString(), exoPlayer.currentPosition.toString()) - if (isLive && (exoPlayer.duration - exoPlayer.currentPosition < 10000)) { - exoPlayer.setPlaybackSpeed(1F) - playerBinding.speedText.text = "1x" - playerBinding.liveSeparator.visibility = View.GONE - playerBinding.liveDiff.text = "" - } else if (isLive) { - Log.e(TAG, "changing the time") - // live stream but not watching at the end/live position - playerBinding.liveSeparator.visibility = View.VISIBLE - val diffText = DateUtils.formatElapsedTime((exoPlayer.duration - exoPlayer.currentPosition) / 1000) - playerBinding.liveDiff.text = "-$diffText" - } // check if video has ended, next video is available and autoplay is enabled. - else if ( + if ( playbackState == Player.STATE_ENDED && nextStreamId != null && !transitioning &&