davidliu
Committed by GitHub

Update README.md

正在显示 1 个修改的文件 包含 23 行增加11 行删除
@@ -82,7 +82,7 @@ screenCaptureIntentLauncher.launch(mediaProjectionManager.createScreenCaptureInt @@ -82,7 +82,7 @@ screenCaptureIntentLauncher.launch(mediaProjectionManager.createScreenCaptureInt
82 82
83 ### Rendering subscribed tracks 83 ### Rendering subscribed tracks
84 84
85 -LiveKit uses WebRTC-provided `org.webrtc.SurfaceViewRenderer` to render video tracks. Subscribed audio tracks are automatically played. 85 +LiveKit uses WebRTC-provided `org.webrtc.SurfaceViewRenderer` to render video tracks. A `TextureView` implementation is also provided through `TextureViewRenderer`. Subscribed audio tracks are automatically played.
86 86
87 ```kt 87 ```kt
88 class MainActivity : AppCompatActivity(), RoomListener { 88 class MainActivity : AppCompatActivity(), RoomListener {
@@ -92,30 +92,30 @@ class MainActivity : AppCompatActivity(), RoomListener { @@ -92,30 +92,30 @@ class MainActivity : AppCompatActivity(), RoomListener {
92 val url = "wss://your_host"; 92 val url = "wss://your_host";
93 val token = "your_token" 93 val token = "your_token"
94 94
95 - launch { 95 + lifecycleScope.launch {
96 val room = LiveKit.connect( 96 val room = LiveKit.connect(
97 applicationContext, 97 applicationContext,
98 url, 98 url,
99 token, 99 token,
100 ConnectOptions(), 100 ConnectOptions(),
101 RoomOptions(), 101 RoomOptions(),
102 - this  
103 ) 102 )
104 val localParticipant = room.localParticipant 103 val localParticipant = room.localParticipant
105 localParticipant.setMicrophoneEnabled(true) 104 localParticipant.setMicrophoneEnabled(true)
106 localParticipant.setCameraEnabled(true) 105 localParticipant.setCameraEnabled(true)
107 106
108 - attachVideo(videoTrack) 107 + launch {
  108 + room.events.collect { event ->
  109 + when(event){
  110 + is RoomEvent.TrackSubscribed -> onTrackSubscribed(event)
  111 + }
  112 + }
  113 + }
109 } 114 }
110 } 115 }
111 116
112 - override fun onTrackSubscribed(  
113 - track: Track,  
114 - publication: RemoteTrackPublication,  
115 - participant: RemoteParticipant,  
116 - room: Room  
117 - ) {  
118 - if (track is VideoTrack) { 117 + private fun onTrackSubscribed(event: RoomEvent.TrackSubscribed) {
  118 + if (event.track is VideoTrack) {
119 attachVideo(track) 119 attachVideo(track)
120 } 120 }
121 } 121 }
@@ -128,6 +128,18 @@ class MainActivity : AppCompatActivity(), RoomListener { @@ -128,6 +128,18 @@ class MainActivity : AppCompatActivity(), RoomListener {
128 } 128 }
129 ``` 129 ```
130 130
  131 +### `@FlowObservable`
  132 +
  133 +Properties marked with `@FlowObservable` can be accessed as a Kotlin Flow to observe changes directly:
  134 +
  135 +```kt
  136 +coroutineScope.launch {
  137 + room::activeSpeakers.flow.collectLatest { speakersList ->
  138 + /*...*/
  139 + }
  140 +}
  141 +```
  142 +
131 ## Dev Environment 143 ## Dev Environment
132 144
133 To develop the Android SDK or running the sample app, you'll need: 145 To develop the Android SDK or running the sample app, you'll need: