File tree Expand file tree Collapse file tree 1 file changed +20
-10
lines changed Expand file tree Collapse file tree 1 file changed +20
-10
lines changed Original file line number Diff line number Diff line change @@ -107,19 +107,29 @@ async fn main() -> Result<()> {
107
107
### Receive video frames of a subscribed track
108
108
109
109
``` rust
110
+ ...
111
+ use futures :: StreamExt ; // this trait is required for iterating on audio & video frames
112
+ use livekit :: prelude :: * ;
113
+
110
114
match event {
111
115
RoomEvent :: TrackSubscribed { track , publication , participant } => {
112
- if let RemoteTrackHandle :: Video (video_track ) => {
113
- let rtc_track = video_track . rtc_track ();
114
- rtc_track . on_frame (Box :: new (move | frame , buffer | {
115
- // Just received a video frame!
116
- // The buffer is YuvEncoded, you can decode it to ABGR by using our yuv_helper
117
- // See the basic_room example for the conversion
118
- });
119
- } else {
120
- // Audio Track..
116
+ match track {
117
+ RemoteTrack :: Audio (audio_track ) => {
118
+ let audio_rtc_track = audio_track . rtc_track ();
119
+ let audio_stream = NativeAudioStream :: new (audio_rtc_track );
120
+ while let Some (audio ) = audio_stream . next (). await {
121
+ info! (" audio buffer info - {audio:#?}" );
122
+ }
123
+ },
124
+ RemoteTrack :: Video (video_track ) => {
125
+ let video_rtc_track = video_track . rtc_track ();
126
+ let video_stream = NativeVideoStream :: new (video_rtc_track );
127
+ while let Some (video_frame ) = video_stream . next (). await {
128
+ info! (" video frame info - {video_frame:#?}" );
129
+ }
130
+ },
121
131
}
122
- }
132
+ },
123
133
_ => {}
124
134
}
125
135
```
You can’t perform that action at this time.
0 commit comments