Skip to content

Commit

Permalink
feat: accept http headers from intent
Browse files Browse the repository at this point in the history
  • Loading branch information
abdallahmehiz committed Aug 17, 2024
1 parent 73ed40b commit 69687ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,7 @@ class PlayerActivity : AppCompatActivity() {
setupAudio()
setupSubtitles()
val uri = parsePathFromIntent(intent)
val videoUri = if (uri?.startsWith("content://") == true) {
openContentFd(Uri.parse(uri))
} else {
uri
}
val videoUri = if (uri?.startsWith("content://") == true) openContentFd(Uri.parse(uri)) else uri
player.playFile(videoUri!!)
setOrientation()
loadKoinModules(module { viewModel { viewModel } })
Expand Down Expand Up @@ -318,6 +314,17 @@ class PlayerActivity : AppCompatActivity() {
}

private fun parsePathFromIntent(intent: Intent): String? {
intent.getStringArrayExtra("headers")?.let { headers ->
if (headers[0].startsWith("User-Agent", true)) MPVLib.setPropertyString("user-agent", headers[1])
val headersString = headers
.asSequence()
.drop(2)
.chunked(2)
.associate { it[0] to it[1] }
.map { "${it.key}: ${it.value.replace(",", "\\,")}" }
.joinToString(",")
MPVLib.setPropertyString("http-header-fields", headersString)
}
val filepath: String? = when (intent.action) {
Intent.ACTION_VIEW -> intent.data?.let { resolveUri(it) }
Intent.ACTION_SEND -> intent.getStringExtra(Intent.EXTRA_TEXT)?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class PlayerViewModel(
private val _currentDecoder = MutableStateFlow(getDecoderFromValue(MPVLib.getPropertyString("hwdec")))
val currentDecoder = _currentDecoder.asStateFlow()

var mediaTitle = MutableStateFlow("")
val mediaTitle = MutableStateFlow("")

val isLoading = MutableStateFlow(true)

Expand Down

0 comments on commit 69687ba

Please sign in to comment.