Git Product home page Git Product logo

libvlc-go's Introduction

libvlc-go

GoDoc License: MIT

Provides golang bindings for libvlc version 2.X/3.X/4.X. This is a work in progress and it is not safe for use in a production environment. The current implementation contains only a small portion of libvlc's functionality.

Full documentation can be found at: http://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

Usage

Player usage

package main

import (
    "log"
    "time"

    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("http://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)
    }

    // Wait some amount of time for the media to start playing.
    // Depends on the version of libvlc. From my tests, libvlc 3.X does not
    // need this delay.
    // TODO: Implement proper callbacks for getting the state of the media.
    time.Sleep(1 * time.Second)

    // If the media played is a live stream the length will be 0.
    length, err := player.MediaLength()
    if err != nil || length == 0 {
        length = 1000 * 60
    }

    time.Sleep(time.Duration(length) * time.Millisecond)
}

List player usage

package main

import (
    "log"
    "time"

    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("http://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)
    }

    // Wait some amount of time for the media to start playing.
    // Depends on the version of libvlc. From my tests, libvlc 3.X does not
    // need this delay.
    // TODO: Implement proper callbacks for getting the state of the media.
    time.Sleep(1 * time.Second)

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

    time.Sleep(60 * 1000 * time.Millisecond)
}

Contributing

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

Contributors: adrg, fenimore, tarrsalah, danielpellon

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.

libvlc-go's People

Contributors

adrg avatar danielpellon avatar fenimore avatar tarrsalah avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.