Skip to content

Commit 61d4584

Browse files
committed
quality model
1 parent 56887ec commit 61d4584

File tree

12 files changed

+462
-662
lines changed

12 files changed

+462
-662
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.github.andreyasadchy.xtra.model
2+
3+
class VideoQuality(
4+
val name: String? = null,
5+
val codecs: String? = null,
6+
val url: String? = null,
7+
)

app/src/main/java/com/github/andreyasadchy/xtra/repository/PlayerRepository.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import com.github.andreyasadchy.xtra.graphql.StreamPlaybackAccessTokenQuery
1717
import com.github.andreyasadchy.xtra.graphql.type.BadgeImageSize
1818
import com.github.andreyasadchy.xtra.graphql.type.EmoteType
1919
import com.github.andreyasadchy.xtra.model.VideoPosition
20+
import com.github.andreyasadchy.xtra.model.VideoQuality
2021
import com.github.andreyasadchy.xtra.model.chat.CheerEmote
2122
import com.github.andreyasadchy.xtra.model.chat.Emote
2223
import com.github.andreyasadchy.xtra.model.chat.RecentEmote
@@ -351,7 +352,7 @@ class PlayerRepository @Inject constructor(
351352
}
352353
}
353354

354-
suspend fun loadClipUrls(networkLibrary: String?, gqlHeaders: Map<String, String>, clipId: String?, enableIntegrity: Boolean): Map<Pair<String, String?>, String>? = withContext(Dispatchers.IO) {
355+
suspend fun loadClipQualities(networkLibrary: String?, gqlHeaders: Map<String, String>, clipId: String?, enableIntegrity: Boolean): List<VideoQuality>? = withContext(Dispatchers.IO) {
355356
try {
356357
val response = graphQLRepository.loadClipUrls(networkLibrary, gqlHeaders, clipId)
357358
if (enableIntegrity) {
@@ -375,9 +376,9 @@ class PlayerRepository @Inject constructor(
375376
appendQueryParameter("sig", accessToken?.signature)
376377
appendQueryParameter("token", accessToken?.value)
377378
}.build().toString()
378-
Pair(name, quality.codecs) to url
379+
VideoQuality(name, quality.codecs, url)
379380
} else null
380-
}?.toMap()
381+
}
381382
}
382383
} catch (e: Exception) {
383384
if (e.message == "failed integrity check") throw e
@@ -403,9 +404,9 @@ class PlayerRepository @Inject constructor(
403404
appendQueryParameter("sig", accessToken?.signature)
404405
appendQueryParameter("token", accessToken?.value)
405406
}.build().toString()
406-
Pair(name, quality.codecs) to url
407+
VideoQuality(name, quality.codecs, url)
407408
} else null
408-
}?.toMap()
409+
}
409410
}
410411
}
411412
}

app/src/main/java/com/github/andreyasadchy/xtra/ui/common/RadioButtonDialogFragment.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialogFragment
2323
class RadioButtonDialogFragment : BottomSheetDialogFragment() {
2424

2525
interface OnSortOptionChanged {
26-
fun onChange(requestCode: Int, index: Int, text: CharSequence, tag: Int?)
26+
fun onChange(requestCode: Int, index: Int, text: CharSequence, tag: String?)
2727
}
2828

2929
companion object {
@@ -33,7 +33,7 @@ class RadioButtonDialogFragment : BottomSheetDialogFragment() {
3333
private const val TAGS = "tags"
3434
private const val CHECKED = "checked"
3535

36-
fun newInstance(requestCode: Int, labels: Collection<CharSequence>, tags: IntArray? = null, checkedIndex: Int): RadioButtonDialogFragment {
36+
fun newInstance(requestCode: Int, labels: Collection<CharSequence>, tags: Array<String>? = null, checkedIndex: Int): RadioButtonDialogFragment {
3737
return RadioButtonDialogFragment().apply {
3838
arguments = bundleOf(REQUEST_CODE to requestCode, LABELS to ArrayList(labels), TAGS to tags, CHECKED to checkedIndex)
3939
}
@@ -61,11 +61,11 @@ class RadioButtonDialogFragment : BottomSheetDialogFragment() {
6161
val clickListener = View.OnClickListener { v ->
6262
val clickedId = v.id
6363
if (clickedId != checkedId) {
64-
listenerSort.onChange(arguments.getInt(REQUEST_CODE), clickedId, (v as RadioButton).text, v.tag as Int?)
64+
listenerSort.onChange(arguments.getInt(REQUEST_CODE), clickedId, (v as RadioButton).text, v.tag as String?)
6565
}
6666
dismiss()
6767
}
68-
val tags = arguments.getIntArray(TAGS)
68+
val tags = arguments.getStringArray(TAGS)
6969
arguments.getCharSequenceArrayList(LABELS)?.forEachIndexed { index, label ->
7070
val button = AppCompatRadioButton(context).apply {
7171
id = index

app/src/main/java/com/github/andreyasadchy/xtra/ui/download/DownloadDialog.kt

Lines changed: 73 additions & 38 deletions
Large diffs are not rendered by default.

app/src/main/java/com/github/andreyasadchy/xtra/ui/download/DownloadViewModel.kt

Lines changed: 48 additions & 166 deletions
Large diffs are not rendered by default.

app/src/main/java/com/github/andreyasadchy/xtra/ui/player/ExoPlayerFragment.kt

Lines changed: 59 additions & 99 deletions
Large diffs are not rendered by default.

app/src/main/java/com/github/andreyasadchy/xtra/ui/player/Media3Fragment.kt

Lines changed: 59 additions & 82 deletions
Large diffs are not rendered by default.

app/src/main/java/com/github/andreyasadchy/xtra/ui/player/MediaPlayerFragment.kt

Lines changed: 85 additions & 141 deletions
Large diffs are not rendered by default.

app/src/main/java/com/github/andreyasadchy/xtra/ui/player/PlaybackService.kt

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import androidx.media3.session.MediaSessionService
3939
import androidx.media3.session.SessionCommand
4040
import androidx.media3.session.SessionResult
4141
import com.github.andreyasadchy.xtra.model.VideoPosition
42+
import com.github.andreyasadchy.xtra.model.VideoQuality
4243
import com.github.andreyasadchy.xtra.player.lowlatency.CronetDataSource
4344
import com.github.andreyasadchy.xtra.player.lowlatency.HlsPlaylistParser
4445
import com.github.andreyasadchy.xtra.player.lowlatency.HttpEngineDataSource
@@ -528,7 +529,7 @@ class PlaybackService : MediaSessionService() {
528529
endTime != null && (it.id.startsWith("stitched-ad-") ||
529530
it.clientDefinedAttributes.find { it.name == "CLASS" }?.textValue == "twitch-stitched-ad" ||
530531
it.clientDefinedAttributes.find { it.name.startsWith("X-TV-TWITCH-AD-") } != null)
531-
&& (startTime <= segmentStartTime && segmentStartTime < endTime)
532+
&& segmentStartTime in startTime..endTime
532533
} != null
533534
}
534535
Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS, bundleOf(
@@ -537,23 +538,17 @@ class PlaybackService : MediaSessionService() {
537538
}
538539
GET_QUALITIES -> {
539540
val playlist = (session.player.currentManifest as? HlsManifest)?.multivariantPlaylist
540-
val names = playlist?.variants?.mapNotNull { it.format.label }?.toTypedArray()
541-
if (!names.isNullOrEmpty()) {
542-
Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS, bundleOf(
543-
NAMES to names,
544-
CODECS to playlist.variants.map { it.format.codecs }.toTypedArray(),
545-
URLS to playlist.variants.map { it.url.toString() }.toTypedArray(),
546-
)))
547-
} else {
548-
val variants = playlist?.variants?.mapNotNull { variant ->
549-
playlist.videos.find { it.groupId == variant.videoGroupId }?.name?.let { variant to it }
550-
}
551-
Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS, bundleOf(
552-
NAMES to variants?.map { it.second }?.toTypedArray(),
553-
CODECS to variants?.map { it.first.format.codecs }?.toTypedArray(),
554-
URLS to variants?.map { it.first.url.toString() }?.toTypedArray(),
555-
)))
541+
val list = playlist?.variants?.mapIndexedNotNull { index, variant ->
542+
val name = variant.format.label?.takeIf { it.isNotBlank() }
543+
?: playlist.videos.find { it.groupId == variant.videoGroupId }?.name?.takeIf { it.isNotBlank() }
544+
?: index.toString()
545+
VideoQuality(name, variant.format.codecs, variant.url.toString())
556546
}
547+
Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS, bundleOf(
548+
NAMES to list?.map { it.name.toString() }?.toTypedArray(),
549+
CODECS to list?.map { it.codecs.toString() }?.toTypedArray(),
550+
URLS to list?.map { it.url.toString() }?.toTypedArray(),
551+
)))
557552
}
558553
GET_DURATION -> {
559554
Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS, bundleOf(

0 commit comments

Comments
 (0)