This commit is contained in:
Mateusz Gruszczyński committed 2026-11-17 16:47:14 +01:00
commit 4cb9717db2
97 files changed
+5946

No files matched your search

@@ -0,0 +1,76 @@
package io.simplydvb.tv.ui
import android.app.Activity
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.WindowManager
import android.widget.Toast
import androidx.annotation.OptIn
import androidx.media3.common.MediaItem
import androidx.media3.common.MimeTypes
import androidx.media3.common.PlaybackException
import androidx.media3.common.Player
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.ui.PlayerView
import io.simplydvb.tv.R
import io.simplydvb.tv.Server
import io.simplydvb.tv.player.Players
import kotlin.concurrent.thread
/** Plays a recording from the server (seeking with the remote's arrows). */
class PlayerActivity : Activity() {
private val main = Handler(Looper.getMainLooper())
private var player: ExoPlayer? = null
@OptIn(UnstableApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_player)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
val dvrId = intent.getLongExtra(DVR_ID, -1)
val p = Players.create(this, live = false, tunneling = Players.tunneling(this))
player = p
val view = findViewById<PlayerView>(R.id.player)
view.player = p
view.setShowFastForwardButton(true)
view.setShowRewindButton(true)
view.requestFocus()
p.addListener(object : Player.Listener {
override fun onPlayerError(error: PlaybackException) {
Toast.makeText(this@PlayerActivity, getString(R.string.error, error.errorCodeName), Toast.LENGTH_LONG).show()
}
})
thread(name = "ticket") {
try {
val url = Server.session(this) { Server.ticketUrl(this, it, dvrId = dvrId) }
main.post {
p.setMediaItem(MediaItem.Builder().setUri(url).setMimeType(MimeTypes.VIDEO_MP2T).build())
p.prepare()
p.playWhenReady = true
}
} catch (e: Exception) {
main.post {
Toast.makeText(this, getString(R.string.error, e.message), Toast.LENGTH_LONG).show()
finish()
}
}
}
}
override fun onStop() {
super.onStop()
player?.playWhenReady = false
}
override fun onDestroy() {
super.onDestroy()
player?.release()
player = null
}
companion object {
const val DVR_ID = "dvr_id"
}
}