mirror of
https://github.com/zoriya/react-native-omni.git
synced 2026-08-16 02:44:51 +00:00
Implement view
This commit is contained in:
@@ -13,13 +13,16 @@ import org.videolan.libvlc.Media
|
||||
import org.videolan.libvlc.MediaPlayer
|
||||
import org.videolan.libvlc.interfaces.IMedia
|
||||
|
||||
class OmniPlayer() : HybridOmniPlayerSpec() {
|
||||
object VlcConst {
|
||||
val vlc = LibVLC(NitroModules.applicationContext ?: throw Error("No Context available!"))
|
||||
val player = MediaPlayer(vlc)
|
||||
}
|
||||
|
||||
class OmniPlayer() : HybridOmniPlayerSpec() {
|
||||
val player = MediaPlayer(VlcConst.vlc)
|
||||
|
||||
override var source: Source by deferredObservable { _, _, new ->
|
||||
val src = new.src.firstOrNull()?.uri ?: return@deferredObservable
|
||||
player.media = Media(vlc, Uri.parse(src))
|
||||
player.media = Media(VlcConst.vlc, Uri.parse(src))
|
||||
new.startTime?.let { start ->
|
||||
player.time = (start * 1000.0).toLong().coerceAtLeast(0L)
|
||||
}
|
||||
|
||||
@@ -1,22 +1,57 @@
|
||||
package dev.zoriya.omni
|
||||
|
||||
import android.graphics.Color
|
||||
import android.view.View
|
||||
import com.facebook.react.uimanager.ThemedReactContext
|
||||
import com.margelo.nitro.omni.HybridOmniPlayerSpec
|
||||
import com.margelo.nitro.omni.HybridOmniViewSpec
|
||||
import org.videolan.libvlc.util.VLCVideoLayout
|
||||
|
||||
class OmniView(val context: ThemedReactContext) : HybridOmniViewSpec() {
|
||||
// View
|
||||
override val view: View = View(context)
|
||||
private val videoLayout = VLCVideoLayout(context)
|
||||
private var viewsAttached = false
|
||||
private var boundPlayer: OmniPlayer? = null
|
||||
|
||||
// Props
|
||||
override var autoplay: Boolean?
|
||||
get() = TODO("Not yet implemented")
|
||||
set(value) {}
|
||||
override var showNotification: Boolean?
|
||||
get() = TODO("Not yet implemented")
|
||||
set(value) {}
|
||||
override var autoPip: Boolean?
|
||||
get() = TODO("Not yet implemented")
|
||||
set(value) {}
|
||||
override val view: View = videoLayout
|
||||
|
||||
override lateinit var player: HybridOmniPlayerSpec
|
||||
override var autoplay: Boolean? = true
|
||||
override var showNotification: Boolean? = true
|
||||
override var autoPip: Boolean? = true
|
||||
|
||||
override fun afterUpdate() {
|
||||
if (!::player.isInitialized) {
|
||||
throw IllegalStateException("Player is null in OmniView")
|
||||
}
|
||||
|
||||
val omniPlayer = player as? OmniPlayer
|
||||
?: throw IllegalStateException("Player is not an OmniPlayer in OmniView")
|
||||
val vout = omniPlayer.player.vlcVout
|
||||
|
||||
if (boundPlayer !== omniPlayer) {
|
||||
boundPlayer?.player?.detachViews()
|
||||
viewsAttached = false
|
||||
boundPlayer = omniPlayer
|
||||
}
|
||||
|
||||
if (!viewsAttached || !vout.areViewsAttached()) {
|
||||
omniPlayer.player.attachViews(videoLayout, null, false, false)
|
||||
viewsAttached = true
|
||||
}
|
||||
|
||||
if (autoplay == true && !omniPlayer.isPlaying) {
|
||||
omniPlayer.play()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDropView() {
|
||||
if (!::player.isInitialized) return
|
||||
|
||||
val omniPlayer = player as? OmniPlayer ?: return
|
||||
val vout = omniPlayer.player.vlcVout
|
||||
if (vout.areViewsAttached()) {
|
||||
omniPlayer.player.detachViews()
|
||||
}
|
||||
viewsAttached = false
|
||||
boundPlayer = null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user