avatar

Play a distant audio stream using Go and Gstreamer


15-07-2015 21:21 by depado

Play a distant audio stream using Go and Gstreamer

Requirements

First of all you need to have GStreamer library installed on your computer since we're going to use a Go binding of it. You can then install the Go Bindings for GStreamer using a simple go get :

go get github.com/ziutek/gst

Play the stream !

package main

import (
    "fmt"

    "github.com/ziutek/gst"
)

func main() {
    player := gst.ElementFactoryMake("playbin", "player")
    player.SetProperty("uri", "UrlToYourStreamHere.mp3")
    // Setting the state to gst.STATE_PLAYING starts playing the stream
    player.SetState(gst.STATE_PLAYING)
    fmt.Scanln()
    fmt.Println("Exiting")
}

Gst will handle the streaming itself, buffering and things like that are automated !

Pause ?

If you want to pause the stream, just use player.SetState(gst.STATE_PAUSED)

That's it ! That was easy wasn't it ? :)