Merge pull request #6739 from Bnyro/master

refactor: reimplement stats for nerds
This commit is contained in:
Bnyro 2024-11-17 20:21:56 +01:00 committed by GitHub
commit 383ca730ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 42 additions and 21 deletions

View File

@ -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
)
}"
val audioInfo = "${player.audioFormat?.codecs.orEmpty()} ${
TextUtils.formatBitrate(player.audioFormat?.bitrate)
}"
val videoQuality =
"${player.videoFormat?.width}x${player.videoFormat?.height} ${player.videoFormat?.frameRate?.toInt()}fps"
return VideoStats(videoId, videoInfo, videoQuality, audioInfo)
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)
}"
}
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)
}"
videoStats.videoQuality =
"${videoFormat.width}x${videoFormat.height} ${videoFormat.frameRate.toInt()}fps"
}
}
}
return videoStats
}
fun getPlayPauseActionIcon(player: Player) = when {

View File

@ -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

View File

@ -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) {