Home

Play a distant audio stream using Go and Gstreamer

Sometimes I'm facing weird problems.

go dev audio
2015/07/15 21:21

Depado

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 ? :)

2015/07/15 21:21 - Raw Markdown