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..3ca26ffe6 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 @@ -118,6 +119,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 +524,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 +770,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 +800,34 @@ class PlayerFragment : Fragment() { run() } + 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() { // seek to saved watch position if available val watchPositions = PreferenceHelper.getWatchPositions() @@ -946,7 +981,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) 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..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" /> + + + + + + + + + + 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