mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 22:00:30 +05:30
Merge pull request #6739 from Bnyro/master
refactor: reimplement stats for nerds
This commit is contained in:
commit
383ca730ab
@ -815,18 +815,38 @@ object PlayerHelper {
|
||||
}
|
||||
|
||||
@OptIn(androidx.media3.common.util.UnstableApi::class)
|
||||
fun getVideoStats(player: ExoPlayer, videoId: String): VideoStats {
|
||||
val videoInfo = "${player.videoFormat?.codecs.orEmpty()} ${
|
||||
TextUtils.formatBitrate(
|
||||
player.videoFormat?.bitrate
|
||||
)
|
||||
fun getVideoStats(tracks: Tracks, videoId: String): VideoStats {
|
||||
val videoStats = VideoStats(videoId, "", "", "")
|
||||
|
||||
for (group in tracks.groups) {
|
||||
if (!group.isSelected || group.length == 0) continue
|
||||
|
||||
when (group.type) {
|
||||
C.TRACK_TYPE_AUDIO -> {
|
||||
val audioFormat = (0..group.length).firstOrNull { index ->
|
||||
group.isTrackSelected(index)
|
||||
}?.let { index -> group.getTrackFormat(index) } ?: continue
|
||||
|
||||
videoStats.audioInfo = "${audioFormat.codecs.orEmpty()} ${
|
||||
TextUtils.formatBitrate(audioFormat.bitrate)
|
||||
}"
|
||||
val audioInfo = "${player.audioFormat?.codecs.orEmpty()} ${
|
||||
TextUtils.formatBitrate(player.audioFormat?.bitrate)
|
||||
}
|
||||
|
||||
C.TRACK_TYPE_VIDEO -> {
|
||||
val videoFormat = (0..group.length).firstOrNull { index ->
|
||||
group.isTrackSelected(index)
|
||||
}?.let { index -> group.getTrackFormat(index) } ?: continue
|
||||
|
||||
videoStats.videoInfo = "${videoFormat.codecs.orEmpty()} ${
|
||||
TextUtils.formatBitrate(videoFormat.bitrate)
|
||||
}"
|
||||
val videoQuality =
|
||||
"${player.videoFormat?.width}x${player.videoFormat?.height} ${player.videoFormat?.frameRate?.toInt()}fps"
|
||||
return VideoStats(videoId, videoInfo, videoQuality, audioInfo)
|
||||
videoStats.videoQuality =
|
||||
"${videoFormat.width}x${videoFormat.height} ${videoFormat.frameRate.toInt()}fps"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return videoStats
|
||||
}
|
||||
|
||||
fun getPlayPauseActionIcon(player: Player) = when {
|
||||
|
@ -6,7 +6,7 @@ import kotlinx.parcelize.Parcelize
|
||||
@Parcelize
|
||||
data class VideoStats(
|
||||
val videoId: String,
|
||||
val videoInfo: String,
|
||||
val videoQuality: String,
|
||||
val audioInfo: String
|
||||
var videoInfo: String,
|
||||
var videoQuality: String,
|
||||
var audioInfo: String
|
||||
) : Parcelable
|
||||
|
@ -106,6 +106,7 @@ import com.github.libretube.ui.models.CommonPlayerViewModel
|
||||
import com.github.libretube.ui.models.PlayerViewModel
|
||||
import com.github.libretube.ui.sheets.BaseBottomSheet
|
||||
import com.github.libretube.ui.sheets.CommentsSheet
|
||||
import com.github.libretube.ui.sheets.StatsSheet
|
||||
import com.github.libretube.util.OnlineTimeFrameReceiver
|
||||
import com.github.libretube.util.PauseableTimer
|
||||
import com.github.libretube.util.PlayingQueue
|
||||
@ -153,7 +154,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
// if null, use same quality as fullscreen
|
||||
private var noFullscreenResolution: Int? = null
|
||||
|
||||
private var selectedAudioLanguageAndRoleFlags: Pair<String?, @C. RoleFlags Int>? = null
|
||||
private var selectedAudioLanguageAndRoleFlags: Pair<String?, @C.RoleFlags Int>? = null
|
||||
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
|
||||
@ -1421,11 +1422,11 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
|
||||
override fun onStatsClicked() {
|
||||
if (!this::streams.isInitialized) return
|
||||
// TODO: reimplement video stats
|
||||
// val videoStats = getVideoStats(playerController, videoId)
|
||||
// StatsSheet()
|
||||
// .apply { arguments = bundleOf(IntentData.videoStats to videoStats) }
|
||||
// .show(childFragmentManager)
|
||||
|
||||
val videoStats = PlayerHelper.getVideoStats(playerController.currentTracks, videoId)
|
||||
StatsSheet()
|
||||
.apply { arguments = bundleOf(IntentData.videoStats to videoStats) }
|
||||
.show(childFragmentManager)
|
||||
}
|
||||
|
||||
override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean) {
|
||||
|
Loading…
Reference in New Issue
Block a user