Skip to content
Go bindings for libVLC 2.X/3.X/4.X used by the VLC media player
Go
Branch: master
Clone or download
Latest commit 8fd2689 Nov 6, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
CODE_OF_CONDUCT.md Add CODE_OF_CONDUCT.md Mar 19, 2019
CONTRIBUTING.md Add CONTRIBUTING.md Mar 19, 2019
LICENSE Update LICENSE Mar 19, 2019
README.md Update README.md Nov 5, 2019
audio.go Refactor event manager Jul 19, 2019
doc.go Update README.md Nov 5, 2019
event_manager.go
event_registry.go Update file naming convention Jul 23, 2019
events.go Refactor event manager Jul 19, 2019
go.mod
list_player.go Update file naming convention Jul 23, 2019
media.go Rename media state constant Jul 19, 2019
media_list.go
player.go Merge pull request #20 from adrg/event-manager Jul 23, 2019
utils.go
vlc.go

README.md

libvlc-go

GoDoc License: MIT Go Report Card

Implements Golang bindings for libVLC version 2.X/3.X/4.X. The package can be useful for adding multimedia capabilities to applications through the provided player interfaces.

Full documentation can be found at: https://godoc.org/github.com/adrg/libvlc-go

Prerequisites

In order to use this project you need to have libvlc-dev installed. On Debian based distributions it can be installed using apt.

sudo apt-get install libvlc-dev

Installation

go get github.com/adrg/libvlc-go

Build for libvlc < v3.0.0

go build -tags legacy

Usage

Player usage

package main

import (
    "log"

    vlc "github.com/adrg/libvlc-go"
)

func main() {
    // Initialize libvlc. Additional command line arguments can be passed in
    // to libvlc by specifying them in the Init function.
    if err := vlc.Init("--no-video", "--quiet"); err != nil {
        log.Fatal(err)
    }
    defer vlc.Release()

    // Create a new player.
    player, err := vlc.NewPlayer()
    if err != nil {
        log.Fatal(err)
    }
    defer func() {
        player.Stop()
        player.Release()
    }()

    // Add a media file from path or from URL.
    // Set player media from path:
    // media, err := player.LoadMediaFromPath("localpath/test.mp4")
    // Set player media from URL:
    media, err := player.LoadMediaFromURL("https://stream-uk1.radioparadise.com/mp3-32")
    if err != nil {
        log.Fatal(err)
    }
    defer media.Release()

    // Start playing the media.
    err = player.Play()
    if err != nil {
        log.Fatal(err)
    }

    // Retrieve player event manager.
    manager, err := player.EventManager()
    if err != nil {
        log.Fatal(err)
    }

    // Register the media end reached event with the event manager.
    quit := make(chan struct{})
    eventCallback := func(event vlc.Event, userData interface{}) {
        close(quit)
    }

    eventID, err := manager.Attach(vlc.MediaPlayerEndReached, eventCallback, nil)
    if err != nil {
        log.Fatal(err)
    }
    defer manager.Detach(eventID)

    <-quit
}

List player usage

package main

import (
    "log"

    vlc "github.com/adrg/libvlc-go"
)

func main() {
    // Initialize libvlc. Additional command line arguments can be passed in
    // to libvlc by specifying them in the Init function.
    if err := vlc.Init("--no-video", "--quiet"); err != nil {
        log.Fatal(err)
    }
    defer vlc.Release()

    // Create a new list player.
    player, err := vlc.NewListPlayer()
    if err != nil {
        log.Fatal(err)
    }
    defer func() {
        player.Stop()
        player.Release()
    }()

    // Create a new media list.
    list, err := vlc.NewMediaList()
    if err != nil {
        log.Fatal(err)
    }
    defer list.Release()

    err = list.AddMediaFromPath("localpath/example1.mp3")
    if err != nil {
        log.Fatal(err)
    }

    err = list.AddMediaFromURL("https://example.com")
    if err != nil {
        log.Fatal(err)
    }

    // Set player media list.
    err = player.SetMediaList(list)
    if err != nil {
        log.Fatal(err)
    }

    // Media files can be added to the list after the list has been added
    // to the player. The player will play these files as well.
    err = list.AddMediaFromPath("localpath/example2.mp3")
    if err != nil {
        log.Fatal(err)
    }

    // Retrieve player event manager.
    manager, err := player.EventManager()
    if err != nil {
        log.Fatal(err)
    }

    // Register the media end reached event with the event manager.
    quit := make(chan struct{})
    eventCallback := func(event vlc.Event, userData interface{}) {
        close(quit)
    }

    eventID, err := manager.Attach(vlc.MediaPlayerEndReached, eventCallback, nil)
    if err != nil {
        log.Fatal(err)
    }
    defer manager.Detach(eventID)

    <-quit
}

Contributing

Contributions in the form of pull requests, issues or just general feedback, are always welcome. See CONTRIBUTING.MD.

Contributors: adrg, fenimore, tarrsalah, danielpellon, patknight

References

For more information see libvlc.

License

Copyright (c) 2018 Adrian-George Bostan.

This project is licensed under the MIT license. See LICENSE for more details.

You can’t perform that action at this time.