Documentation ¶
Overview ¶
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. if err = player.Play(); 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/test1.mp3") if err != nil { log.Fatal(err) } err = list.AddMediaFromURL("https://example.com/test2.mp4") if err != nil { log.Fatal(err) } // Set player media list. if err = player.SetMediaList(list); 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/test3.mp3") if err != nil { log.Fatal(err) } // Start playing the media list. if err = player.Play(); 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.MediaListPlayerPlayed,, eventCallback, nil) if err != nil { log.Fatal(err) } defer manager.Detach(eventID) <-quit
Handling multiple events example
// Create a new player. player, err := vlc.NewPlayer() if err != nil { log.Fatal(err) } defer func() { player.Stop() player.Release() }() // Add player media from path. media, err := player.LoadMediaFromPath("localpath/test.mp3") if err != nil { log.Fatal(err) } defer media.Release() // Start playing the media. if err = player.Play(); err != nil { log.Fatal(err) } // Retrieve player event manager. manager, err := player.EventManager() if err != nil { log.Fatal(err) } // Create event handler. quit := make(chan struct{}) eventCallback := func(event vlc.Event, userData interface{}) { switch event { case vlc.MediaPlayerEndReached: log.Println("Player end reached") close(quit) case vlc.MediaPlayerTimeChanged: media, err := player.Media() if err != nil { log.Println(err) break } stats, err := media.Stats() if err != nil { log.Println(err) break } log.Printf("%+v\n", stats) } } // Register events with the event manager. events := []vlc.Event{ vlc.MediaPlayerTimeChanged, vlc.MediaPlayerEndReached, } var eventIDs []vlc.EventID for _, event := range events { eventID, err := manager.Attach(event, eventCallback, nil) if err != nil { log.Fatal(err) } eventIDs = append(eventIDs, eventID) } // De-register attached events. defer func() { for _, eventID := range eventIDs { manager.Detach(eventID) } }() <-quit
Index ¶
- Constants
- Variables
- func Init(args ...string) error
- func Release() error
- type AudioOutput
- type Event
- type EventCallback
- type EventID
- type EventManager
- type ListPlayer
- func (lp *ListPlayer) EventManager() (*EventManager, error)
- func (lp *ListPlayer) IsPlaying() bool
- func (lp *ListPlayer) MediaList() *MediaList
- func (lp *ListPlayer) MediaState() (MediaState, error)
- func (lp *ListPlayer) Play() error
- func (lp *ListPlayer) PlayAtIndex(index uint) error
- func (lp *ListPlayer) PlayNext() error
- func (lp *ListPlayer) PlayPrevious() error
- func (lp *ListPlayer) Player() (*Player, error)
- func (lp *ListPlayer) Release() error
- func (lp *ListPlayer) SetMediaList(ml *MediaList) error
- func (lp *ListPlayer) SetPlaybackMode(mode PlaybackMode) error
- func (lp *ListPlayer) SetPlayer(player *Player) error
- func (lp *ListPlayer) Stop() error
- func (lp *ListPlayer) TogglePause() error
- type Media
- func (m *Media) AddOptions(options ...string) error
- func (m *Media) EventManager() (*EventManager, error)
- func (m *Media) IsParsed() (bool, error)
- func (m *Media) Location() (string, error)
- func (m *Media) Meta(key MediaMetaKey) (string, error)
- func (m *Media) Parse() error
- func (m *Media) ParseAsync() error
- func (m *Media) Release() error
- func (m *Media) SaveMeta() error
- func (m *Media) SetMeta(key MediaMetaKey, val string) error
- func (m *Media) Stats() (*MediaStats, error)
- type MediaList
- func (ml *MediaList) AddMedia(m *Media) error
- func (ml *MediaList) AddMediaFromPath(path string) error
- func (ml *MediaList) AddMediaFromURL(url string) error
- func (ml *MediaList) Count() (int, error)
- func (ml *MediaList) EventManager() (*EventManager, error)
- func (ml *MediaList) InsertMedia(m *Media, index uint) error
- func (ml *MediaList) InsertMediaFromPath(path string, index uint) error
- func (ml *MediaList) InsertMediaFromURL(url string, index uint) error
- func (ml *MediaList) IsReadOnly() (bool, error)
- func (ml *MediaList) Lock() error
- func (ml *MediaList) MediaAtIndex(index uint) (*Media, error)
- func (ml *MediaList) Release() error
- func (ml *MediaList) RemoveMediaAtIndex(index uint) error
- func (ml *MediaList) Unlock() error
- type MediaMetaKey
- type MediaState
- type MediaStats
- type PlaybackMode
- type Player
- func (p *Player) EventManager() (*EventManager, error)
- func (p *Player) IsFullScreen() (bool, error)
- func (p *Player) IsPlaying() bool
- func (p *Player) LoadMediaFromPath(path string) (*Media, error)
- func (p *Player) LoadMediaFromURL(url string) (*Media, error)
- func (p *Player) Media() (*Media, error)
- func (p *Player) MediaLength() (int, error)
- func (p *Player) MediaPosition() (float32, error)
- func (p *Player) MediaState() (MediaState, error)
- func (p *Player) MediaTime() (int, error)
- func (p *Player) Play() error
- func (p *Player) Release() error
- func (p *Player) SetAudioOutput(output string) error
- func (p *Player) SetFullScreen(fullscreen bool) error
- func (p *Player) SetMedia(m *Media) error
- func (p *Player) SetMediaPosition(pos float32) error
- func (p *Player) SetMediaTime(t int) error
- func (p *Player) SetPause(pause bool) error
- func (p *Player) SetVolume(volume int) error
- func (p *Player) SetXWindow(windowID uint32) error
- func (p *Player) Stop() error
- func (p *Player) ToggleFullScreen() error
- func (p *Player) TogglePause() error
- func (p *Player) Volume() (int, error)
- func (p *Player) WillPlay() bool
- type VersionInfo
Constants ¶
const ( MediaListViewItemAdded = 0x300 + iota MediaListViewWillAddItem MediaListViewItemDeleted MediaListViewWillDeleteItem )
Deprecated events.
const ( // MediaListPlayerPlayed is triggered when playback of the media list // of the list player has ended. 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 is stopped programmatically. MediaListPlayerStopped )
Variables ¶
var ( ErrModuleInitialize = errors.New("could not initialize module") ErrModuleNotInitialized = errors.New("module not initialized") )
Module errors.
var ( ErrPlayerCreate = errors.New("could not create player") ErrPlayerNotInitialized = errors.New("player not initialized") ErrListPlayerCreate = errors.New("could not create list player") ErrListPlayerNotInitialized = errors.New("list player not initialized") )
Player errors.
var ( ErrMediaCreate = errors.New("could not create media") ErrMediaNotInitialized = errors.New("media not initialized") ErrMediaListCreate = errors.New("could not create media list") ErrMediaListNotInitialized = errors.New("media list not initialized") ErrMissingMediaStats = errors.New("could not get media statistics") ErrInvalidMediaStats = errors.New("invalid media statistics") ErrMissingMediaLocation = errors.New("could not get media location") ErrMediaMetaSave = errors.New("could not save media metadata") )
Media errors.
var ( ErrMissingEventManager = errors.New("could not get event manager instance") ErrInvalidEventCallback = errors.New("invalid event callback") )
Event manager errors.
var (
ErrAudioOutputListMissing = errors.New("could not get audio output list")
)
Audio errors.
Functions ¶
Types ¶
type AudioOutput ¶
AudioOutput is an abstraction for rendering decoded (or pass-through) audio samples.
func AudioOutputList ¶
func AudioOutputList() ([]*AudioOutput, error)
AudioOutputList returns a list of audio output devices that can be used with an instance of a player.
type Event ¶
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 ( // 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 ¶
type EventCallback func(Event, interface{})
EventCallback represents an event notification callback function.
type EventManager ¶
type EventManager struct {
// contains filtered or unexported fields
}
EventManager wraps a libvlc event manager.
func (*EventManager) Attach ¶
func (em *EventManager) Attach(event Event, callback EventCallback, userData interface{}) (EventID, error)
Attach registers a callback for an event notification.
func (*EventManager) Detach ¶
func (em *EventManager) Detach(eventID EventID)
Detach unregisters the specified event notification.
type ListPlayer ¶
type ListPlayer struct {
// contains filtered or unexported fields
}
ListPlayer is an enhanced media player used to play media lists.
func NewListPlayer ¶
func NewListPlayer() (*ListPlayer, error)
NewListPlayer creates an instance of a multi-media player.
func (*ListPlayer) EventManager ¶
func (lp *ListPlayer) EventManager() (*EventManager, error)
EventManager returns the event manager responsible for the list player.
func (*ListPlayer) IsPlaying ¶
func (lp *ListPlayer) IsPlaying() bool
IsPlaying returns a boolean value specifying if the player is currently playing.
func (*ListPlayer) MediaList ¶
func (lp *ListPlayer) MediaList() *MediaList
MediaList returns the current media list of the player, if one exists
func (*ListPlayer) MediaState ¶
func (lp *ListPlayer) MediaState() (MediaState, error)
MediaState returns the state of the current media.
func (*ListPlayer) PlayAtIndex ¶
func (lp *ListPlayer) PlayAtIndex(index uint) error
PlayAtIndex plays the media at the specified index from the current media list.
func (*ListPlayer) PlayNext ¶
func (lp *ListPlayer) PlayNext() error
PlayNext plays the next media in the current media list.
func (*ListPlayer) PlayPrevious ¶
func (lp *ListPlayer) PlayPrevious() error
PlayPrevious plays the previous media in the current media list.
func (*ListPlayer) Player ¶
func (lp *ListPlayer) Player() (*Player, error)
Player returns the underlying Player instance of the ListPlayer.
func (*ListPlayer) Release ¶
func (lp *ListPlayer) Release() error
Release destroys the media player instance.
func (*ListPlayer) SetMediaList ¶
func (lp *ListPlayer) SetMediaList(ml *MediaList) error
SetMediaList sets the media list to be played.
func (*ListPlayer) SetPlaybackMode ¶
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 ¶
func (lp *ListPlayer) SetPlayer(player *Player) error
SetPlayer sets the underlying Player instance of the ListPlayer.
func (*ListPlayer) Stop ¶
func (lp *ListPlayer) Stop() error
Stop cancels the currently playing media list, if there is one.
func (*ListPlayer) TogglePause ¶
func (lp *ListPlayer) TogglePause() error
TogglePause pauses/resumes the player. Calling this method has no effect if there is no media.
type Media ¶
type Media struct {
// contains filtered or unexported fields
}
Media is an abstract representation of a playable media file.
func NewMediaFromPath ¶
NewMediaFromPath creates a Media instance from the provided path.
func NewMediaFromURL ¶
NewMediaFromURL creates a Media instance from the provided URL.
func (*Media) AddOptions ¶
AddOptions adds the specified options to the media. The specified options determine how a media player reads the media, allowing advanced reading or streaming on a per-media basis.
func (*Media) EventManager ¶
func (m *Media) EventManager() (*EventManager, error)
EventManager returns the event manager responsible for the media.
func (*Media) IsParsed ¶
IsParsed returns true if the media was parsed. NOTE: deprecated in libVLC v3.0.0+.
func (*Media) Location ¶
Location returns the media location, which can be either a local path or a URL, depending on how the media was loaded.
func (*Media) Meta ¶
func (m *Media) Meta(key MediaMetaKey) (string, error)
Meta reads the value of the specified media metadata key.
func (*Media) Parse ¶
Parse fetches local art, metadata and track information synchronously. NOTE: deprecated in libVLC v3.0.0+.
func (*Media) ParseAsync ¶
ParseAsync fetches local art, metadata and track information asynchronously. Listen to MediaParsedChanged event on the media event manager the track when the parsing has finished. However, if the media was already parsed, the event will not be sent. NOTE: deprecated in libVLC v3.0.0+.
func (*Media) SetMeta ¶
func (m *Media) SetMeta(key MediaMetaKey, val string) error
SetMeta sets the specified media metadata key to the provided value. In order to save the metadata on the media file, call SaveMeta.
func (*Media) Stats ¶
func (m *Media) Stats() (*MediaStats, error)
Stats returns playback statistics for the media.
type MediaList ¶
type MediaList struct {
// contains filtered or unexported fields
}
MediaList represents a collection of media files.
func NewMediaList ¶
NewMediaList creates an empty media list.
func (*MediaList) AddMedia ¶
AddMedia adds the provided Media instance at the end of the media list.
func (*MediaList) AddMediaFromPath ¶
AddMediaFromPath loads the media file at the specified path and adds it at the end of the media list.
func (*MediaList) AddMediaFromURL ¶
AddMediaFromURL loads the media file at the specified URL and adds it at the end of the the media list.
func (*MediaList) EventManager ¶
func (ml *MediaList) EventManager() (*EventManager, error)
EventManager returns the event manager responsible for the media list.
func (*MediaList) InsertMedia ¶
InsertMedia inserts the provided Media instance in the list, at the specified index.
func (*MediaList) InsertMediaFromPath ¶
InsertMediaFromPath loads the media file at the provided path and inserts it in the list, at the specified index.
func (*MediaList) InsertMediaFromURL ¶
InsertMediaFromURL loads the media file at the provided URL and inserts it in the list, at the specified index.
func (*MediaList) IsReadOnly ¶
IsReadOnly specifies if the media list can be modified.
func (*MediaList) MediaAtIndex ¶
MediaAtIndex returns the media item at the specified index from the list.
func (*MediaList) RemoveMediaAtIndex ¶
RemoveMediaAtIndex removes the media item at the specified index from the list.
type MediaMetaKey ¶
type MediaMetaKey uint
MediaMetaKey uniquely identifies a type of media metadata.
const ( MediaTitle MediaMetaKey = iota MediaArtist MediaGenre MediaCopyright MediaAlbum MediaTrackNumber MediaDescription MediaRating MediaDate MediaSetting MediaURL MediaLanguage MediaNowPlaying MediaPublisher MediaEncodedBy MediaArtworkURL MediaTrackID MediaTrackTotal MediaDirector MediaSeason MediaEpisode MediaShowName MediaActors MediaAlbumArtist MediaDiscNumber MediaDiscTotal )
Media metadata types.
func (MediaMetaKey) Validate ¶
func (mt MediaMetaKey) Validate() error
Validate checks if the media metadata key is valid.
type MediaState ¶
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 MediaStats ¶
type MediaStats struct { // Input statistics. ReadBytes int // input bytes read. InputBitRate float64 // input bitrate. // Demux statistics. DemuxReadBytes int // demux bytes read (demuxed data size). DemuxBitRate float64 // demux bitrate (content bitrate). DemuxCorrupted int // demux corruptions (discarded). DemuxDiscontinuity int // demux discontinuities (dropped). // Video output statistics. DecodedVideo int // number of decoded video blocks. DisplayedPictures int // number of displayed frames. LostPictures int // number of lost frames. // Audio output statistics. DecodedAudio int // number of decoded audio blocks. PlayedAudioBuffers int // number of played audio buffers. LostAudioBuffers int // number of lost audio buffers. }
MediaStats contains playback statistics for a media file.
type PlaybackMode ¶
type PlaybackMode uint
PlaybackMode defines playback modes for a media list.
const ( Default PlaybackMode = iota Loop Repeat )
Playback modes.
type Player ¶
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 (*Player) EventManager ¶
func (p *Player) EventManager() (*EventManager, error)
EventManager returns the event manager responsible for the media player.
func (*Player) IsFullScreen ¶
IsFullScreen gets the fullscreen status of the current player.
func (*Player) IsPlaying ¶
IsPlaying returns a boolean value specifying if the player is currently playing.
func (*Player) LoadMediaFromPath ¶
LoadMediaFromPath loads the media from the specified path and adds it as the current media of the player.
func (*Player) LoadMediaFromURL ¶
LoadMediaFromURL loads the media from the specified URL and adds it as the current media of the player.
func (*Player) MediaLength ¶
MediaLength returns media length in milliseconds.
func (*Player) MediaPosition ¶
MediaPosition returns media position as a float percentage between 0.0 and 1.0.
func (*Player) MediaState ¶
func (p *Player) MediaState() (MediaState, error)
MediaState returns the state of the current media.
func (*Player) SetAudioOutput ¶
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 ¶
SetFullScreen sets the fullscreen state of the media player. Pass in true to enable fullscreen, or false to disable it.
func (*Player) SetMediaPosition ¶
SetMediaPosition sets media position as percentage between 0.0 and 1.0. Some formats and protocols do not support this.
func (*Player) SetMediaTime ¶
SetMediaTime sets the media time in milliseconds. Some formats and protocals do not support this.
func (*Player) SetPause ¶
SetPause sets the pause state of the media player. Pass in true to pause the current media, or false to resume it.
func (*Player) SetXWindow ¶
SetXWindow sets the X window to play on.
func (*Player) ToggleFullScreen ¶
ToggleFullScreen toggles the fullscreen status of the player, on non-embedded video outputs.
func (*Player) TogglePause ¶
TogglePause pauses/resumes the player. Calling this method has no effect if there is no media.
type VersionInfo ¶
VersionInfo contains details regarding the version of the libVLC module.
func Version ¶
func Version() VersionInfo
Version returns details regarding the version of the libVLC module.
func (VersionInfo) String ¶
func (v VersionInfo) String() string
String returns a string representation of the version.