libvlc-go: github.com/adrg/libvlc-go Index | Files

package vlc

import "github.com/adrg/libvlc-go"

Package vlc provides golang bindings for libVLC version 2.X/3.X/4.X.

Usage

Initialization

// 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()

Player example

// 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)
}

// 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 example

// 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)
}

// 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

Index

Package Files

audio.go doc.go event_manager.go event_registry.go events.go list_player.go media.go media_list.go player.go utils.go vlc.go

Constants

const (
    MediaListViewItemAdded = 0x300 + iota
    MediaListViewWillAddItem
    MediaListViewItemDeleted
    MediaListViewWillDeleteItem
)

Deprecated events.

const (
    // MediaListPlayerPlayed is triggered when Playback
    // of a media list player has started.
    MediaListPlayerPlayed = 0x400 + iota

    // MediaListPlayerNextItemSet is triggered when the current item
    // of a media list player has changed to a different item.
    MediaListPlayerNextItemSet

    // MediaListPlayerStopped is triggered when Playback
    // of a media list player has stopped.
    MediaListPlayerStopped
)

func Init Uses

func Init(args ...string) error

Init creates an instance of the VLC module. Must be called only once and the module instance must be released using the Release function.

func Release Uses

func Release() error

Release destroys the instance created by the Init function.

type AudioOutput Uses

type AudioOutput struct {
    Name        string
    Description string
}

AudioOutput is an abstraction for rendering decoded (or pass-through) audio samples.

func AudioOutputList Uses

func AudioOutputList() ([]*AudioOutput, error)

AudioOutputList returns a list of audio output devices that can be used with an instance of a player.

type Event Uses

type Event int

Event represents an event that can occur inside libvlc.

const (
    // MediaMetaChanged is triggered when the metadata of a media item changes.
    MediaMetaChanged Event = iota

    // MediaSubItemAdded is triggered when a Subitem is added to a media item.
    MediaSubItemAdded

    // MediaDurationChanged is triggered when the duration
    // of a media item changes.
    MediaDurationChanged

    // MediaParsedChanged is triggered when the parsing state
    // of a media item changes.
    MediaParsedChanged

    // MediaFreed is triggered when a media item is freed.
    MediaFreed

    // MediaStateChanged is triggered when the state of the media item changes.
    MediaStateChanged

    // MediaSubItemTreeAdded is triggered when a Subitem tree is
    // added to a media item.
    MediaSubItemTreeAdded

    // MediaThumbnailGenerated is triggered when a thumbnail generation is completed.
    MediaThumbnailGenerated
)

Media events.

const (
    MediaPlayerMediaChanged Event = 0x100 + iota
    MediaPlayerNothingSpecial
    MediaPlayerOpening
    MediaPlayerBuffering
    MediaPlayerPlaying
    MediaPlayerPaused
    MediaPlayerStopped
    MediaPlayerForward
    MediaPlayerBackward
    MediaPlayerEndReached
    MediaPlayerEncounteredError
    MediaPlayerTimeChanged
    MediaPlayerPositionChanged
    MediaPlayerSeekableChanged
    MediaPlayerPausableChanged
    MediaPlayerTitleChanged
    MediaPlayerSnapshotTaken
    MediaPlayerLengthChanged
    MediaPlayerVout
    MediaPlayerScrambledChanged
    MediaPlayerESAdded
    MediaPlayerESDeleted
    MediaPlayerESSelected
    MediaPlayerCorked
    MediaPlayerUncorked
    MediaPlayerMuted
    MediaPlayerUnmuted
    MediaPlayerAudioVolume
    MediaPlayerAudioDevice
    MediaPlayerChapterChanged
)

Player events.

const (
    // MediaListItemAdded is triggered when a media item is added to a media list.
    MediaListItemAdded Event = 0x200 + iota

    // MediaListWillAddItem is triggered when a media item is about to get
    // added to a media list.
    MediaListWillAddItem

    // MediaListItemDeleted is triggered when a media item is deleted
    // from a media list.
    MediaListItemDeleted

    // MediaListWillDeleteItem is triggered when a media item is about to get
    // deleted from a media list.
    MediaListWillDeleteItem

    // MediaListEndReached is triggered when a media list has reached the end.
    MediaListEndReached
)

Media list events.

const (
    MediaDiscovererStarted Event = 0x500 + iota
    MediaDiscovererEnded
)

Deprecated events.

const (
    // RendererDiscovererItemAdded is triggered when a new renderer item is
    // found by a renderer discoverer. The renderer item is valid until deleted.
    RendererDiscovererItemAdded Event = 0x502 + iota

    // RendererDiscovererItemDeleted is triggered when a previously discovered
    // renderer item was deleted by a renderer discoverer. The renderer item
    // is no longer valid.
    RendererDiscovererItemDeleted
)

Renderer events.

const (
    VlmMediaAdded Event = 0x600 + iota
    VlmMediaRemoved
    VlmMediaChanged
    VlmMediaInstanceStarted
    VlmMediaInstanceStopped
    VlmMediaInstanceStatusInit
    VlmMediaInstanceStatusOpening
    VlmMediaInstanceStatusPlaying
    VlmMediaInstanceStatusPause
    VlmMediaInstanceStatusEnd
    VlmMediaInstanceStatusError
)

VideoLAN Manager events.

type EventCallback Uses

type EventCallback func(Event, interface{})

EventCallback represents an event notification callback function.

type EventID Uses

type EventID uint64

EventID uniquely identifies a registered event.

type EventManager Uses

type EventManager struct {
    // contains filtered or unexported fields
}

EventManager wraps a libvlc event manager.

func (*EventManager) Attach Uses

func (em *EventManager) Attach(event Event, callback EventCallback, userData interface{}) (EventID, error)

Attach registers a callback for an event notification.

func (*EventManager) Detach Uses

func (em *EventManager) Detach(eventID EventID)

Detach unregisters the specified event notification.

type ListPlayer Uses

type ListPlayer struct {
    // contains filtered or unexported fields
}

ListPlayer is an enhanced media player used to play media lists.

func NewListPlayer Uses

func NewListPlayer() (*ListPlayer, error)

NewListPlayer creates an instance of a multi-media player.

func (*ListPlayer) EventManager Uses

func (lp *ListPlayer) EventManager() (*EventManager, error)

EventManager returns the event manager responsible for the list player.

func (*ListPlayer) IsPlaying Uses

func (lp *ListPlayer) IsPlaying() bool

IsPlaying returns a boolean value specifying if the player is currently playing.

func (*ListPlayer) MediaList Uses

func (lp *ListPlayer) MediaList() *MediaList

MediaList returns the current media list of the player, if one exists

func (*ListPlayer) MediaState Uses

func (lp *ListPlayer) MediaState() (MediaState, error)

MediaState returns the state of the current media.

func (*ListPlayer) Play Uses

func (lp *ListPlayer) Play() error

Play plays the current media list.

func (ListPlayer) PlayAtIndex Uses

func (lp ListPlayer) PlayAtIndex(index uint) error

PlayAtIndex plays the media at the specified index from the current media list.

func (*ListPlayer) PlayNext Uses

func (lp *ListPlayer) PlayNext() error

PlayNext plays the next media in the current media list.

func (*ListPlayer) PlayPrevious Uses

func (lp *ListPlayer) PlayPrevious() error

PlayPrevious plays the previous media in the current media list.

func (*ListPlayer) Player Uses

func (lp *ListPlayer) Player() (*Player, error)

Player returns the underlying Player instance of the ListPlayer.

func (*ListPlayer) Release Uses

func (lp *ListPlayer) Release() error

Release destroys the media player instance.

func (*ListPlayer) SetMediaList Uses

func (lp *ListPlayer) SetMediaList(ml *MediaList) error

SetMediaList sets the media list to be played.

func (*ListPlayer) SetPlaybackMode Uses

func (lp *ListPlayer) SetPlaybackMode(mode PlaybackMode) error

SetPlaybackMode sets the player playback mode for the media list. By default, it plays the media list once and then stops.

func (*ListPlayer) SetPlayer Uses

func (lp *ListPlayer) SetPlayer(player *Player) error

SetPlayer sets the underlying Player instance of the ListPlayer.

func (*ListPlayer) Stop Uses

func (lp *ListPlayer) Stop() error

Stop cancels the currently playing media list, if there is one.

func (*ListPlayer) TogglePause Uses

func (lp *ListPlayer) TogglePause() error

TogglePause pauses/resumes the player. Calling this method has no effect if there is no media.

type Media Uses

type Media struct {
    // contains filtered or unexported fields
}

Media is an abstract representation of a playable media file.

func NewMediaFromPath Uses

func NewMediaFromPath(path string) (*Media, error)

NewMediaFromPath creates a Media instance from the provided path.

func NewMediaFromURL Uses

func NewMediaFromURL(url string) (*Media, error)

NewMediaFromURL creates a Media instance from the provided URL.

func (*Media) Release Uses

func (m *Media) Release() error

Release destroys the media instance.

type MediaList Uses

type MediaList struct {
    // contains filtered or unexported fields
}

MediaList represents a collection of media files.

func NewMediaList Uses

func NewMediaList() (*MediaList, error)

NewMediaList creates an empty media list.

func (*MediaList) AddMedia Uses

func (ml *MediaList) AddMedia(m *Media) error

AddMedia adds a Media instance to the media list.

func (*MediaList) AddMediaFromPath Uses

func (ml *MediaList) AddMediaFromPath(path string) error

AddMediaFromPath loads a media file from path and adds it to the the media list.

func (*MediaList) AddMediaFromURL Uses

func (ml *MediaList) AddMediaFromURL(url string) error

AddMediaFromURL loads a media file from url and adds it to the the media list.

func (*MediaList) EventManager Uses

func (ml *MediaList) EventManager() (*EventManager, error)

EventManager returns the event manager responsible for the media list.

func (*MediaList) Lock Uses

func (ml *MediaList) Lock() error

Lock makes the caller the current owner of the media list.

func (*MediaList) Release Uses

func (ml *MediaList) Release() error

Release destroys the media list instance.

func (*MediaList) Unlock Uses

func (ml *MediaList) Unlock() error

Unlock releases ownership of the media list.

type MediaState Uses

type MediaState uint

MediaState represents the state of a media file.

const (
    MediaNothingSpecial MediaState = iota
    MediaOpening
    MediaBuffering
    MediaPlaying
    MediaPaused
    MediaStopped
    MediaEnded
    MediaError
)

Media states.

type PlaybackMode Uses

type PlaybackMode uint

PlaybackMode defines playback modes for a media list.

const (
    Default PlaybackMode = iota
    Loop
    Repeat
)

Playback modes.

type Player Uses

type Player struct {
    // contains filtered or unexported fields
}

Player is a media player used to play a single media file. For playing media lists (playlists) use ListPlayer instead.

func NewPlayer Uses

func NewPlayer() (*Player, error)

NewPlayer creates an instance of a single-media player.

func (*Player) EventManager Uses

func (p *Player) EventManager() (*EventManager, error)

EventManager returns the event manager responsible for the media list.

func (*Player) IsFullScreen Uses

func (p *Player) IsFullScreen() (bool, error)

IsFullScreen gets the fullscreen status of the current player.

func (*Player) IsPlaying Uses

func (p *Player) IsPlaying() bool

IsPlaying returns a boolean value specifying if the player is currently playing.

func (*Player) LoadMediaFromPath Uses

func (p *Player) LoadMediaFromPath(path string) (*Media, error)

LoadMediaFromPath loads the media from the specified path and adds it as the current media of the player.

func (*Player) LoadMediaFromURL Uses

func (p *Player) LoadMediaFromURL(url string) (*Media, error)

LoadMediaFromURL loads the media from the specified URL and adds it as the current media of the player.

func (*Player) Media Uses

func (p *Player) Media() (*Media, error)

Media returns the current media of the player, if one exists.

func (*Player) MediaLength Uses

func (p *Player) MediaLength() (int, error)

MediaLength returns media length in milliseconds.

func (*Player) MediaPosition Uses

func (p *Player) MediaPosition() (float32, error)

MediaPosition returns media position as a float percentage between 0.0 and 1.0.

func (*Player) MediaState Uses

func (p *Player) MediaState() (MediaState, error)

MediaState returns the state of the current media.

func (*Player) MediaTime Uses

func (p *Player) MediaTime() (int, error)

MediaTime returns media time in milliseconds.

func (*Player) Play Uses

func (p *Player) Play() error

Play plays the current media.

func (*Player) Release Uses

func (p *Player) Release() error

Release destroys the media player instance.

func (*Player) SetAudioOutput Uses

func (p *Player) SetAudioOutput(output string) error

SetAudioOutput selects an audio output module. Any change will take be effect only after playback is stopped and restarted. Audio output cannot be changed while playing.

func (*Player) SetFullScreen Uses

func (p *Player) SetFullScreen(fullscreen bool) error

SetFullScreen sets the fullscreen state of the media player. Pass in true to enable fullscreen, or false to disable it.

func (*Player) SetMedia Uses

func (p *Player) SetMedia(m *Media) error

SetMedia sets the provided media as the current media of the player.

func (*Player) SetMediaPosition Uses

func (p *Player) SetMediaPosition(pos float32) error

SetMediaPosition sets media position as percentage between 0.0 and 1.0. Some formats and protocols do not support this.

func (*Player) SetMediaTime Uses

func (p *Player) SetMediaTime(t int) error

SetMediaTime sets the media time in milliseconds. Some formats and protocals do not support this.

func (*Player) SetPause Uses

func (p *Player) SetPause(pause bool) error

SetPause sets the pause state of the media player. Pass in true to pause the current media, or false to resume it.

func (*Player) SetVolume Uses

func (p *Player) SetVolume(volume int) error

SetVolume sets the volume of the player.

func (*Player) SetXWindow Uses

func (p *Player) SetXWindow(windowID uint32) error

SetXWindow sets the X window to play on.

func (*Player) Stop Uses

func (p *Player) Stop() error

Stop cancels the currently playing media, if there is one.

func (*Player) ToggleFullScreen Uses

func (p *Player) ToggleFullScreen() error

ToggleFullScreen toggles the fullscreen status of the player, on non-embedded video outputs.

func (*Player) TogglePause Uses

func (p *Player) TogglePause() error

TogglePause pauses/resumes the player. Calling this method has no effect if there is no media.

func (*Player) Volume Uses

func (p *Player) Volume() (int, error)

Volume returns the volume of the player.

func (*Player) WillPlay Uses

func (p *Player) WillPlay() bool

WillPlay returns true if the current media is not in a finished or error state.

Package vlc imports 4 packages (graph) and is imported by 3 packages. Updated 2020-01-17. Refresh now. Tools for package owners.