simplify example

This commit is contained in:
aler9
2022-11-07 22:01:39 +01:00
parent 37e2070c91
commit 16e4e3c2ef

View File

@@ -1,6 +1,7 @@
package main package main
import ( import (
"fmt"
"log" "log"
"github.com/aler9/gortsplib" "github.com/aler9/gortsplib"
@@ -10,7 +11,7 @@ import (
// This example shows how to // This example shows how to
// 1. connect to a RTSP server // 1. connect to a RTSP server
// 2. get tracks published on a path // 2. get tracks published on a path
// 3. read only selected tracks // 3. read only the H264 track
func main() { func main() {
c := gortsplib.Client{ c := gortsplib.Client{
@@ -40,18 +41,21 @@ func main() {
panic(err) panic(err)
} }
// setup only H264 tracks, skipping audio or application tracks // find the H264 track
h264Track := func() gortsplib.Track {
for _, t := range tracks { for _, t := range tracks {
if _, ok := t.(*gortsplib.TrackH264); ok { if _, ok := t.(*gortsplib.TrackH264); ok {
_, err := c.Setup(t, baseURL, 0, 0) return t
if err != nil {
panic(err)
} }
} }
return nil
}()
if h264Track == nil {
panic(fmt.Errorf("H264 track not found"))
} }
// start reading tracks // setup and play the H264 track only
_, err = c.Play(nil) err = c.SetupAndPlay(gortsplib.Tracks{h264Track}, baseURL)
if err != nil { if err != nil {
panic(err) panic(err)
} }