@g9tm/lynxcontrols-native 2.5.9 → 2.5.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/android/src/main/java/com/g9lynx/g9native/video/G9VideoFilePlayer.kt +146 -0
- package/android/src/main/java/com/g9lynx/g9native/video/G9VideoTracks.kt +36 -0
- package/android/src/main/java/com/g9lynx/g9native/video/G9VideoUI.kt +133 -79
- package/catalog/cards/G9TrackVideo.md +14 -0
- package/catalog/cards/G9VideoPlayer.md +17 -0
- package/catalog/catalog.json +354 -3
- package/catalog/index.md +3 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/media.d.ts +80 -2
- package/dist/media.d.ts.map +1 -1
- package/dist/media.jsx +176 -4
- package/ios/g9lynx-native-swift.podspec +1 -1
- package/ios/g9lynx-native.podspec +1 -1
- package/ios/src/G9LCVideoUI.h +25 -0
- package/ios/src/G9LCVideoUI.m +119 -0
- package/ios/swift/shared/G9LCImages.swift +34 -6
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -105,3 +105,10 @@ Since 2.5.8 the Swift views (`G9LCRichTextView`, `G9LCCanvasView`, `G9LCBlurhash
|
|
|
105
105
|
|
|
106
106
|
Host integration: [`docs/integration/android.md`](../../docs/integration/android.md) and
|
|
107
107
|
[`docs/integration/ios.md`](../../docs/integration/ios.md) (reference hosts: `apps/android-host`, `apps/ios-host`).
|
|
108
|
+
|
|
109
|
+
Calls and recordings (2.5.10–2.5.11, `@g9tm/lynxcontrols-native/media`): `G9TrackVideo` shows a live RTC track in
|
|
110
|
+
`<g9-video track>` (the host registers the engine's renderer; see the skill's `references/hosting.md`), and
|
|
111
|
+
`G9VideoPlayer` is a recording with play / pause, ±10 s, a seek bar, the time and mute over the element's `progress`
|
|
112
|
+
event and `seek` method — the same on Android, iOS and the web. Android keeps `<g9-video track>` in a host built with
|
|
113
|
+
`g9native.media3=false`.
|
|
114
|
+
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
package com.g9lynx.g9native.video
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.os.Handler
|
|
5
|
+
import android.os.Looper
|
|
6
|
+
import android.view.TextureView
|
|
7
|
+
import androidx.media3.common.MediaItem
|
|
8
|
+
import androidx.media3.common.PlaybackException
|
|
9
|
+
import androidx.media3.common.Player
|
|
10
|
+
import androidx.media3.common.VideoSize
|
|
11
|
+
import androidx.media3.exoplayer.ExoPlayer
|
|
12
|
+
import com.g9lynx.g9native.video.core.G9VideoLoopTracker
|
|
13
|
+
import com.g9lynx.g9native.video.core.G9VideoMath
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* What a file player tells its element (2.5.11): no Media3 type crosses it, so `<g9-video track>` works in a host
|
|
17
|
+
* built with `g9native.media3=false` (G9Hub) — only a `src` reaches this class, and only when Media3 is linked.
|
|
18
|
+
*/
|
|
19
|
+
internal interface G9VideoFileEvents {
|
|
20
|
+
fun ready()
|
|
21
|
+
|
|
22
|
+
fun error(code: String, message: String)
|
|
23
|
+
|
|
24
|
+
fun looped()
|
|
25
|
+
|
|
26
|
+
fun nearEnd(seconds: Double)
|
|
27
|
+
|
|
28
|
+
fun videoSize(width: Float, height: Float)
|
|
29
|
+
|
|
30
|
+
/** About four times a second while it plays: the position and the length (seconds). */
|
|
31
|
+
fun progress(seconds: Double, duration: Double)
|
|
32
|
+
|
|
33
|
+
/** The end of a file that does not loop. */
|
|
34
|
+
fun ended()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Whether Media3 is linked in this app (a host can leave it out with `g9native.media3=false`). */
|
|
38
|
+
internal object G9VideoMedia3 {
|
|
39
|
+
val available: Boolean by lazy {
|
|
40
|
+
try {
|
|
41
|
+
Class.forName("androidx.media3.exoplayer.ExoPlayer")
|
|
42
|
+
true
|
|
43
|
+
} catch (_: Throwable) {
|
|
44
|
+
false
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** One Media3 ExoPlayer drawing into the element's TextureView: the file side of `<g9-video>`. */
|
|
50
|
+
internal class G9VideoFilePlayer(
|
|
51
|
+
context: Context,
|
|
52
|
+
texture: TextureView,
|
|
53
|
+
uri: String,
|
|
54
|
+
private val startSeconds: Double,
|
|
55
|
+
nearEndSeconds: Double,
|
|
56
|
+
private val events: G9VideoFileEvents,
|
|
57
|
+
) {
|
|
58
|
+
private val main = Handler(Looper.getMainLooper())
|
|
59
|
+
private val player: ExoPlayer = ExoPlayer.Builder(context).build()
|
|
60
|
+
private val tracker = G9VideoLoopTracker().also { it.nearEndSeconds = nearEndSeconds }
|
|
61
|
+
private var startApplied = false
|
|
62
|
+
private var ticks = 0
|
|
63
|
+
|
|
64
|
+
private val poll =
|
|
65
|
+
object : Runnable {
|
|
66
|
+
override fun run() {
|
|
67
|
+
tracker.progress(player.currentPosition, player.duration)?.let { events.nearEnd(it) }
|
|
68
|
+
// progress every 250 ms (the poll runs every 100 ms for the near-end mark)
|
|
69
|
+
if (++ticks % 3 == 0) events.progress(player.currentPosition / 1000.0, seconds(player.duration))
|
|
70
|
+
if (player.isPlaying) main.postDelayed(this, POLL_MS)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private val listener =
|
|
75
|
+
object : Player.Listener {
|
|
76
|
+
override fun onRenderedFirstFrame() = events.ready()
|
|
77
|
+
|
|
78
|
+
override fun onPlayerError(error: PlaybackException) =
|
|
79
|
+
events.error(error.errorCodeName, error.message ?: error.errorCodeName)
|
|
80
|
+
|
|
81
|
+
override fun onPositionDiscontinuity(old: Player.PositionInfo, new: Player.PositionInfo, reason: Int) {
|
|
82
|
+
if (reason == Player.DISCONTINUITY_REASON_AUTO_TRANSITION) {
|
|
83
|
+
tracker.looped()
|
|
84
|
+
events.looped()
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
override fun onPlaybackStateChanged(state: Int) {
|
|
89
|
+
if (state == Player.STATE_READY && !startApplied) {
|
|
90
|
+
startApplied = true
|
|
91
|
+
G9VideoMath.startPositionMs(startSeconds, player.duration)?.let { player.seekTo(it) }
|
|
92
|
+
events.progress(player.currentPosition / 1000.0, seconds(player.duration))
|
|
93
|
+
}
|
|
94
|
+
if (state == Player.STATE_ENDED) {
|
|
95
|
+
events.progress(seconds(player.duration), seconds(player.duration))
|
|
96
|
+
events.ended()
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
override fun onIsPlayingChanged(isPlaying: Boolean) {
|
|
101
|
+
main.removeCallbacks(poll)
|
|
102
|
+
if (isPlaying) main.post(poll)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
override fun onVideoSizeChanged(size: VideoSize) =
|
|
106
|
+
events.videoSize(size.width * size.pixelWidthHeightRatio, size.height.toFloat())
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
init {
|
|
110
|
+
tracker.looped()
|
|
111
|
+
player.addListener(listener)
|
|
112
|
+
player.setVideoTextureView(texture)
|
|
113
|
+
player.setMediaItem(MediaItem.fromUri(uri))
|
|
114
|
+
player.prepare()
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
fun apply(loop: Boolean, muted: Boolean, paused: Boolean) {
|
|
118
|
+
player.repeatMode = if (loop) Player.REPEAT_MODE_ONE else Player.REPEAT_MODE_OFF
|
|
119
|
+
player.volume = if (muted) 0f else 1f
|
|
120
|
+
player.playWhenReady = !paused
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
fun setNearEndSeconds(value: Double) {
|
|
124
|
+
tracker.nearEndSeconds = value
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** A seek (2.5.11, the controls' bar): clamped to the length once it is known. */
|
|
128
|
+
fun seek(seconds: Double) {
|
|
129
|
+
val duration = player.duration
|
|
130
|
+
val ms = (seconds * 1000).toLong().coerceAtLeast(0)
|
|
131
|
+
player.seekTo(if (duration > 0) ms.coerceAtMost(duration) else ms)
|
|
132
|
+
events.progress(player.currentPosition / 1000.0, seconds(duration))
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
fun release() {
|
|
136
|
+
main.removeCallbacks(poll)
|
|
137
|
+
player.removeListener(listener)
|
|
138
|
+
player.release()
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
private fun seconds(ms: Long): Double = if (ms > 0) ms / 1000.0 else 0.0
|
|
142
|
+
|
|
143
|
+
private companion object {
|
|
144
|
+
const val POLL_MS = 100L
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
package com.g9lynx.g9native.video
|
|
2
|
+
|
|
3
|
+
import android.widget.FrameLayout
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A live track drawn into `<g9-video track="…">` (2.5.10, G9Hub 92): the app's RTC engine (LiveKit) puts its own
|
|
7
|
+
* renderer view into [container] and keeps it fed; the element only says which track, mirrored or not, cropped or not.
|
|
8
|
+
*/
|
|
9
|
+
interface G9VideoTrackAttachment {
|
|
10
|
+
/** `mirror` or `fit` changed while the track shows. */
|
|
11
|
+
fun update(mirror: Boolean, cover: Boolean) {}
|
|
12
|
+
|
|
13
|
+
/** The element let go of the track (another track, a `src`, or the element is gone): remove the renderer view. */
|
|
14
|
+
fun detach()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The app's RTC engine: shows a track in an element's container. */
|
|
18
|
+
fun interface G9VideoTrackRenderer {
|
|
19
|
+
/** Shows [track] in [container]; null when the track is not known (the element sends `error { code: 'track-unknown' }`). */
|
|
20
|
+
fun attach(track: String, container: FrameLayout, mirror: Boolean, cover: Boolean): G9VideoTrackAttachment?
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Where the host registers its track renderer, once, before a LynxView shows a call:
|
|
25
|
+
* `G9VideoTracks.register { track, container, mirror, cover -> liveKit.attach(track, container, mirror, cover) }`.
|
|
26
|
+
*/
|
|
27
|
+
object G9VideoTracks {
|
|
28
|
+
@Volatile private var renderer: G9VideoTrackRenderer? = null
|
|
29
|
+
|
|
30
|
+
@JvmStatic
|
|
31
|
+
fun register(value: G9VideoTrackRenderer?) {
|
|
32
|
+
renderer = value
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@JvmStatic fun renderer(): G9VideoTrackRenderer? = renderer
|
|
36
|
+
}
|
|
@@ -2,82 +2,66 @@ package com.g9lynx.g9native.video
|
|
|
2
2
|
|
|
3
3
|
import android.content.Context
|
|
4
4
|
import android.graphics.Matrix
|
|
5
|
-
import android.os.Handler
|
|
6
|
-
import android.os.Looper
|
|
7
5
|
import android.view.TextureView
|
|
8
6
|
import android.widget.FrameLayout
|
|
9
|
-
import androidx.media3.common.MediaItem
|
|
10
|
-
import androidx.media3.common.PlaybackException
|
|
11
|
-
import androidx.media3.common.Player
|
|
12
|
-
import androidx.media3.common.VideoSize
|
|
13
|
-
import androidx.media3.exoplayer.ExoPlayer
|
|
14
|
-
import com.g9lynx.g9native.video.core.G9VideoLoopTracker
|
|
15
7
|
import com.g9lynx.g9native.video.core.G9VideoMath
|
|
8
|
+
import com.lynx.react.bridge.Callback
|
|
9
|
+
import com.lynx.react.bridge.ReadableMap
|
|
16
10
|
import com.lynx.tasm.behavior.Behavior
|
|
17
11
|
import com.lynx.tasm.behavior.LynxContext
|
|
18
12
|
import com.lynx.tasm.behavior.LynxProp
|
|
13
|
+
import com.lynx.tasm.behavior.LynxUIMethod
|
|
14
|
+
import com.lynx.tasm.behavior.LynxUIMethodConstants
|
|
19
15
|
import com.lynx.tasm.behavior.ui.LynxUI
|
|
20
16
|
import com.lynx.tasm.event.LynxDetailEvent
|
|
21
17
|
|
|
22
18
|
/**
|
|
23
|
-
* The `<g9-video>` element on Android (plan/specs/06 §7):
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* `
|
|
27
|
-
*
|
|
28
|
-
*
|
|
19
|
+
* The `<g9-video>` element on Android (plan/specs/06 §7): a file played by Media3 into a TextureView (a SurfaceView
|
|
20
|
+
* would ignore the opacity fades the intro carousel animates), muted looping playback with MAUI's `Aspect.AspectFill`
|
|
21
|
+
* look. Props: `src` (`asset:///…`, `file://…`, `http(s)://…`), `paused` (default true), `loop`, `muted` (default true),
|
|
22
|
+
* `start-seconds` (one best-effort seek), `near-end-seconds`, `object-fit` (`cover` | `contain`). Events: `ready`
|
|
23
|
+
* (first frame rendered), `nearend` `{ seconds }`, `looped`, `error` `{ code, message }`. The player is released when
|
|
24
|
+
* the element is destroyed or its `src` changes. Register it with {@link G9VideoBehaviors}.
|
|
25
|
+
*
|
|
26
|
+
* 2.5.10 (G9Hub): `track` shows a live RTC track instead of a file, drawn by the host's [G9VideoTrackRenderer]
|
|
27
|
+
* ([G9VideoTracks.register]); `mirror` flips the picture (the self view); `fit` is the same as `object-fit`.
|
|
28
|
+
*
|
|
29
|
+
* 2.5.11 (G9Hub): Media3 is touched only for a `src` ([G9VideoFilePlayer]), so a host built with
|
|
30
|
+
* `g9native.media3=false` keeps `<g9-video track>` (a `src` then reports `error { code: 'no-media3' }`); `progress`
|
|
31
|
+
* `{ seconds, duration }` about four times a second and `ended` (a file that does not loop); the `seek` method
|
|
32
|
+
* `{ seconds }` (the controls of G9VideoPlayer).
|
|
29
33
|
*/
|
|
30
34
|
class G9VideoUI(context: LynxContext) : LynxUI<G9VideoView>(context) {
|
|
31
|
-
private
|
|
32
|
-
private var player: ExoPlayer? = null
|
|
35
|
+
private var player: G9VideoFilePlayer? = null
|
|
33
36
|
private var src: String? = null
|
|
34
37
|
private var preparedSrc: String? = null
|
|
35
38
|
private var paused = true
|
|
36
39
|
private var loop = true
|
|
37
40
|
private var muted = true
|
|
38
41
|
private var startSeconds = 0.0
|
|
39
|
-
private var
|
|
42
|
+
private var nearEndSeconds = 0.0
|
|
40
43
|
private var cover = true
|
|
41
|
-
private
|
|
42
|
-
|
|
43
|
-
private
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
private var mirror = false
|
|
45
|
+
private var track: String? = null
|
|
46
|
+
private var shownTrack: String? = null
|
|
47
|
+
private var attachment: G9VideoTrackAttachment? = null
|
|
48
|
+
|
|
49
|
+
private val events =
|
|
50
|
+
object : G9VideoFileEvents {
|
|
51
|
+
override fun ready() = send("ready")
|
|
52
|
+
|
|
53
|
+
override fun error(code: String, message: String) = send("error", mapOf("code" to code, "message" to message))
|
|
54
|
+
|
|
55
|
+
override fun looped() = send("looped")
|
|
56
|
+
|
|
57
|
+
override fun nearEnd(seconds: Double) = send("nearend", mapOf("seconds" to seconds))
|
|
51
58
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
override fun
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
override fun onPositionDiscontinuity(old: Player.PositionInfo, new: Player.PositionInfo, reason: Int) {
|
|
60
|
-
if (reason == Player.DISCONTINUITY_REASON_AUTO_TRANSITION) {
|
|
61
|
-
tracker.looped()
|
|
62
|
-
send("looped")
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
override fun onPlaybackStateChanged(state: Int) {
|
|
67
|
-
val p = player ?: return
|
|
68
|
-
if (state == Player.STATE_READY && !startApplied) {
|
|
69
|
-
startApplied = true
|
|
70
|
-
G9VideoMath.startPositionMs(startSeconds, p.duration)?.let { p.seekTo(it) }
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
override fun onIsPlayingChanged(isPlaying: Boolean) {
|
|
75
|
-
main.removeCallbacks(poll)
|
|
76
|
-
if (isPlaying) main.post(poll)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
override fun onVideoSizeChanged(size: VideoSize) =
|
|
80
|
-
mView.setVideoSize(size.width * size.pixelWidthHeightRatio, size.height.toFloat())
|
|
59
|
+
override fun videoSize(width: Float, height: Float) = mView.setVideoSize(width, height)
|
|
60
|
+
|
|
61
|
+
override fun progress(seconds: Double, duration: Double) =
|
|
62
|
+
send("progress", mapOf("seconds" to seconds, "duration" to duration))
|
|
63
|
+
|
|
64
|
+
override fun ended() = send("ended")
|
|
81
65
|
}
|
|
82
66
|
|
|
83
67
|
override fun createView(context: Context): G9VideoView = G9VideoView(context)
|
|
@@ -109,7 +93,8 @@ class G9VideoUI(context: LynxContext) : LynxUI<G9VideoView>(context) {
|
|
|
109
93
|
|
|
110
94
|
@LynxProp(name = "near-end-seconds")
|
|
111
95
|
fun setNearEndSeconds(value: Double) {
|
|
112
|
-
|
|
96
|
+
nearEndSeconds = value
|
|
97
|
+
player?.setNearEndSeconds(value)
|
|
113
98
|
}
|
|
114
99
|
|
|
115
100
|
@LynxProp(name = "object-fit")
|
|
@@ -117,42 +102,96 @@ class G9VideoUI(context: LynxContext) : LynxUI<G9VideoView>(context) {
|
|
|
117
102
|
cover = value != "contain"
|
|
118
103
|
}
|
|
119
104
|
|
|
105
|
+
@LynxProp(name = "fit")
|
|
106
|
+
fun setFit(value: String?) {
|
|
107
|
+
cover = value != "contain"
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@LynxProp(name = "mirror", defaultBoolean = false)
|
|
111
|
+
fun setMirror(value: Boolean) {
|
|
112
|
+
mirror = value
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
@LynxProp(name = "track")
|
|
116
|
+
fun setTrack(value: String?) {
|
|
117
|
+
track = value?.takeIf { it.isNotBlank() }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Moves a file to `seconds` (2.5.11). */
|
|
121
|
+
@LynxUIMethod
|
|
122
|
+
fun seek(params: ReadableMap, callback: Callback) {
|
|
123
|
+
val p = player
|
|
124
|
+
if (p == null) {
|
|
125
|
+
callback.invoke(LynxUIMethodConstants.UNKNOWN, "no file is playing")
|
|
126
|
+
return
|
|
127
|
+
}
|
|
128
|
+
p.seek(if (params.hasKey("seconds")) params.getDouble("seconds") else 0.0)
|
|
129
|
+
callback.invoke(LynxUIMethodConstants.SUCCESS)
|
|
130
|
+
}
|
|
131
|
+
|
|
120
132
|
override fun onPropsUpdated() {
|
|
121
133
|
super.onPropsUpdated()
|
|
122
134
|
mView.cover = cover
|
|
135
|
+
mView.mirror = mirror
|
|
136
|
+
if (track != shownTrack) showTrack()
|
|
137
|
+
else attachment?.update(mirror, cover)
|
|
138
|
+
if (track != null) {
|
|
139
|
+
if (player != null) release()
|
|
140
|
+
return
|
|
141
|
+
}
|
|
123
142
|
if (src != preparedSrc) prepare()
|
|
124
|
-
player?.
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
143
|
+
player?.apply(loop, muted, paused)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private fun showTrack() {
|
|
147
|
+
detachTrack()
|
|
148
|
+
val id = track ?: return
|
|
149
|
+
val renderer = G9VideoTracks.renderer()
|
|
150
|
+
if (renderer == null) {
|
|
151
|
+
send("error", mapOf("code" to "no-track-renderer", "message" to "G9VideoTracks.register was not called."))
|
|
152
|
+
return
|
|
153
|
+
}
|
|
154
|
+
val shown = renderer.attach(id, mView.tracks, mirror, cover)
|
|
155
|
+
if (shown == null) {
|
|
156
|
+
send("error", mapOf("code" to "track-unknown", "message" to "No track \"$id\"."))
|
|
157
|
+
return
|
|
158
|
+
}
|
|
159
|
+
attachment = shown
|
|
160
|
+
shownTrack = id
|
|
161
|
+
mView.showingTrack = true
|
|
162
|
+
send("ready")
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private fun detachTrack() {
|
|
166
|
+
try {
|
|
167
|
+
attachment?.detach()
|
|
168
|
+
} catch (_: RuntimeException) {
|
|
169
|
+
// the engine dropped the track already
|
|
128
170
|
}
|
|
171
|
+
attachment = null
|
|
172
|
+
shownTrack = null
|
|
173
|
+
mView.showingTrack = false
|
|
129
174
|
}
|
|
130
175
|
|
|
131
176
|
private fun prepare() {
|
|
132
177
|
release()
|
|
133
178
|
preparedSrc = src
|
|
134
179
|
val uri = src ?: return
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
p.setVideoTextureView(mView.texture)
|
|
141
|
-
p.setMediaItem(MediaItem.fromUri(uri))
|
|
142
|
-
p.prepare()
|
|
180
|
+
if (!G9VideoMedia3.available) {
|
|
181
|
+
send("error", mapOf("code" to "no-media3", "message" to "This app is built without Media3 (g9native.media3=false)."))
|
|
182
|
+
return
|
|
183
|
+
}
|
|
184
|
+
player = G9VideoFilePlayer(lynxContext, mView.texture, uri, startSeconds, nearEndSeconds, events)
|
|
143
185
|
}
|
|
144
186
|
|
|
145
187
|
private fun release() {
|
|
146
|
-
|
|
147
|
-
player?.let {
|
|
148
|
-
it.removeListener(listener)
|
|
149
|
-
it.release()
|
|
150
|
-
}
|
|
188
|
+
player?.release()
|
|
151
189
|
player = null
|
|
152
190
|
preparedSrc = null
|
|
153
191
|
}
|
|
154
192
|
|
|
155
193
|
override fun destroy() {
|
|
194
|
+
detachTrack()
|
|
156
195
|
release()
|
|
157
196
|
super.destroy()
|
|
158
197
|
}
|
|
@@ -166,15 +205,14 @@ class G9VideoUI(context: LynxContext) : LynxUI<G9VideoView>(context) {
|
|
|
166
205
|
private fun send(name: String, detail: Map<String, Any> = emptyMap()) {
|
|
167
206
|
lynxContext.eventEmitter.sendCustomEvent(LynxDetailEvent(sign, name, HashMap<String, Any>(detail)))
|
|
168
207
|
}
|
|
169
|
-
|
|
170
|
-
private companion object {
|
|
171
|
-
const val POLL_MS = 100L
|
|
172
|
-
}
|
|
173
208
|
}
|
|
174
209
|
|
|
175
210
|
/** The element's view: a TextureView scaled to `cover` (crop) or `contain` (letterbox) the video frame. */
|
|
176
211
|
class G9VideoView(context: Context) : FrameLayout(context) {
|
|
177
212
|
val texture = TextureView(context)
|
|
213
|
+
|
|
214
|
+
/** Where a live track's renderer view goes (2.5.10). */
|
|
215
|
+
val tracks = FrameLayout(context)
|
|
178
216
|
private var videoW = 0f
|
|
179
217
|
private var videoH = 0f
|
|
180
218
|
|
|
@@ -184,9 +222,24 @@ class G9VideoView(context: Context) : FrameLayout(context) {
|
|
|
184
222
|
updateTransform()
|
|
185
223
|
}
|
|
186
224
|
|
|
225
|
+
/** Flipped left to right (the self view; 2.5.10). */
|
|
226
|
+
var mirror = false
|
|
227
|
+
set(value) {
|
|
228
|
+
field = value
|
|
229
|
+
updateTransform()
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** A track shows: the file's texture is hidden. */
|
|
233
|
+
var showingTrack = false
|
|
234
|
+
set(value) {
|
|
235
|
+
field = value
|
|
236
|
+
texture.visibility = if (value) INVISIBLE else VISIBLE
|
|
237
|
+
}
|
|
238
|
+
|
|
187
239
|
init {
|
|
188
240
|
clipChildren = true
|
|
189
241
|
addView(texture, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT))
|
|
242
|
+
addView(tracks, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT))
|
|
190
243
|
}
|
|
191
244
|
|
|
192
245
|
fun setVideoSize(width: Float, height: Float) {
|
|
@@ -202,7 +255,8 @@ class G9VideoView(context: Context) : FrameLayout(context) {
|
|
|
202
255
|
|
|
203
256
|
private fun updateTransform() {
|
|
204
257
|
val (sx, sy) = G9VideoMath.fitScale(width.toFloat(), height.toFloat(), videoW, videoH, cover)
|
|
205
|
-
|
|
258
|
+
val flip = if (mirror) -1f else 1f
|
|
259
|
+
texture.setTransform(Matrix().apply { setScale(sx * flip, sy, width / 2f, height / 2f) })
|
|
206
260
|
}
|
|
207
261
|
}
|
|
208
262
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# G9TrackVideo
|
|
2
|
+
|
|
3
|
+
`import { G9TrackVideo } from '@g9tm/lynxcontrols-native/media';`
|
|
4
|
+
|
|
5
|
+
A live call track in `<g9-video track>` (2.5.10, G9Hub 92): a call tile's `video` — the host's RTC engine (LiveKit) draws it, so the app's thread has no RTC code.
|
|
6
|
+
|
|
7
|
+
Props:
|
|
8
|
+
- `track`: string
|
|
9
|
+
- `onError?`: (code: string, message: string) => void
|
|
10
|
+
- `onReady?`: () => void
|
|
11
|
+
- `fit?`: 'contain' | 'cover'
|
|
12
|
+
- `mirror?`: boolean
|
|
13
|
+
|
|
14
|
+
Example: `<G9TrackVideo track="track" />`
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# G9VideoPlayer
|
|
2
|
+
|
|
3
|
+
`import { G9VideoPlayer } from '@g9tm/lynxcontrols-native/media';`
|
|
4
|
+
|
|
5
|
+
A recording with controls (2.5.11, G9Hub 97: video notes, meeting recordings): `<g9-video>` with play / pause, back and forward 10 s, a bar that seeks where it is tapped, the time and mute — the same on Android, iOS and
|
|
6
|
+
|
|
7
|
+
Props:
|
|
8
|
+
- `src`: string
|
|
9
|
+
- `formatTime?`: (seconds: number) => void
|
|
10
|
+
- `onEnded?`: () => void
|
|
11
|
+
- `onError?`: (code: string, message: string) => void
|
|
12
|
+
- `autoPlay?`: boolean = false
|
|
13
|
+
- `fit?`: 'contain' | 'cover'
|
|
14
|
+
- `muted?`: boolean = false
|
|
15
|
+
- `words?`: object
|
|
16
|
+
|
|
17
|
+
Example: `<G9VideoPlayer id="id" src="src" />`
|