mp

package
v0.0.0-...-cf6f472 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2022 License: BSD-2-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	STATE_STOPPED   State = 0
	STATE_PLAYING         = 1
	STATE_PAUSED          = 2
	STATE_BUFFERING       = 3
	STATE_SEEKING         = 4 // not in the YouTube API
)
View Source
const INITIAL_VOLUME = 80

Variables

View Source
var MPV_PROPERTY_UNAVAILABLE = errors.New("mpv: property unavailable")
View Source
var PROPERTY_UNAVAILABLE = errors.New("media player: property unavailable")

Functions

This section is empty.

Types

type Backend

type Backend interface {
	// contains filtered or unexported methods
}

type MPV

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

MPV is an implementation of Backend, using libmpv.

type MediaPlayer

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

A generic YouTube media player using a playlist.

func New

func New(stateChange chan StateChange) *MediaPlayer

func (*MediaPlayer) ChangeVolume

func (p *MediaPlayer) ChangeVolume(delta int, volumeChan chan int)

ChangeVolume increases or decreases the volume by the specified delta.

func (*MediaPlayer) Pause

func (p *MediaPlayer) Pause()

Pause pauses the currently playing video

func (*MediaPlayer) Play

func (p *MediaPlayer) Play()

Play resumes playback when it was paused

func (*MediaPlayer) Quit

func (p *MediaPlayer) Quit()

Quit quits the MediaPlayer. No other method may be called upon this object after this function has been called.

func (*MediaPlayer) RequestPlaylist

func (p *MediaPlayer) RequestPlaylist(playlistChan chan PlaylistState)

RequestPlaylist asynchronously gets the playlist state and sends it over the channel. To make asynchronous requests work, it expects a 1-buffered channel. Before a new PlaylistState is sent over the channel, the previous is read if it's there. It ensures that only one goroutine does that at one time, so this trick should not be used elsewhere on the same channel.

func (*MediaPlayer) RequestVolume

func (p *MediaPlayer) RequestVolume(volumeChan chan int)

RequestVolume asynchronously gets the volume and sends it over the channel volumeChan. See RequestPlaylist for how this works.

func (*MediaPlayer) Seek

func (p *MediaPlayer) Seek(position time.Duration)

Seek jumps to the specified position

func (*MediaPlayer) SetPlaystate

func (p *MediaPlayer) SetPlaystate(playlist []string, index int, position time.Duration, listId string)

SetPlaystate changes the play state to the specified arguments This function doesn't block, but changes may not be immediately applied.

func (*MediaPlayer) SetVideo

func (p *MediaPlayer) SetVideo(videoId string, position time.Duration)

func (*MediaPlayer) SetVolume

func (p *MediaPlayer) SetVolume(volume int, volumeChan chan int)

SetVolume sets the volume of the player to the specified value (0-100).

func (*MediaPlayer) Stop

func (p *MediaPlayer) Stop()

Stop stops the currently playing sound and clears the playlist.

func (*MediaPlayer) UpdatePlaylist

func (p *MediaPlayer) UpdatePlaylist(playlist []string, listId string)

type PlayState

type PlayState struct {
	Playlist []string
	Index    int
	State    State
	ListId   string
	Volume   int
	// contains filtered or unexported fields
}

PlayState defines the current state of the generic MediaPlayer. It is shared within the MediaPlayer and used as an access token as well: whoever holds a pointer to this structure may access it's members. That also means that a pointer to this struct should be cleared when starting a new goroutine.

func (*PlayState) NextVideo

func (ps *PlayState) NextVideo() string

NextVideo returns the next video in the playlist, or an empty string if there is no next video.

func (*PlayState) Video

func (ps *PlayState) Video() string

Video returns the current video, or an empty string if there is no current video.

type PlaylistState

type PlaylistState struct {
	Playlist []string
	Index    int
	Position time.Duration
	Duration time.Duration
	State    State
	ListId   string
}

type State

type State int

these are defined by the YouTube API

type StateChange

type StateChange struct {
	State    State
	Position time.Duration // current position in file
	Duration time.Duration // total duration of file
}

type VideoGrabber

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

func NewVideoGrabber

func NewVideoGrabber() *VideoGrabber

func (*VideoGrabber) GetStream

func (vg *VideoGrabber) GetStream(videoId string) string

GetStream returns the stream for videoId, or an empty string if an error occured.

func (*VideoGrabber) Quit

func (vg *VideoGrabber) Quit()

type VideoURL

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

func (*VideoURL) GetURL

func (u *VideoURL) GetURL() string

Gets the video stream URL, possibly waiting until that video has been fetched or an error occurs. An empty string will be returned on error.

func (*VideoURL) String

func (u *VideoURL) String() string

func (*VideoURL) WillExpire

func (u *VideoURL) WillExpire() bool

WillExpire returns true if this stream will expire within an hour.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL