Skip to content

Commit 30e4ca3

Browse files
authored
chore: update 'Receive video frames of a subscribed track' docs (#238)
1 parent 147eff5 commit 30e4ca3

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

README.md

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,29 @@ async fn main() -> Result<()> {
107107
### Receive video frames of a subscribed track
108108

109109
```rust
110+
...
111+
use futures::StreamExt; // this trait is required for iterating on audio & video frames
112+
use livekit::prelude::*;
113+
110114
match event {
111115
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+
},
121131
}
122-
}
132+
},
123133
_ => {}
124134
}
125135
```

0 commit comments

Comments
 (0)