youtube

package module
v0.0.0-...-ac173f2 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2018 License: MIT Imports: 1 Imported by: 0

README

youtube

Gopherjs Bindings for Youtube's Iframe API documented @ https://developers.google.com/youtube/iframe_api_reference

Test and example page can be accessed by gopherjs serve.

Usage: Sample code is in the example package


const playerID            = "playerID"

func main() {
	// 1. Add the Youtube script to your header
	yourAddScriptFunc(youtubeIframeAPISrc)

	// 2. Place the player container as a div in your html with a predefined id
	var app = &App{playerID: playerID}
	vecty.RenderBody(app)

	// 3. Initialize the player when the Youtube API's done loading
	js.Global.Set("onYouTubeIframeAPIReady", func() {
		// Create and set the initial properties of the player (check the document
		// for the specific fields)
		var props = youtube.NewProperties()
		props.Width = 640
		props.Height = 390
		props.VideoID = "dQw4w9WgXcQ"
		props.PlayerVars.EnableJsAPI = 1
		props.Events.OnReady = func(e *youtube.Event) {
			e.Target.PlayVideo()
		}
		// Create and cache the created player
		app.player = youtube.NewPlayer(playerID, props)
	})
}

Please feel free to contribute!

Documentation

Index

Constants

View Source
const (
	// IvPolicyShown shows video's annotation
	IvPolicyShown = iota + 1

	// IvPolicyNotShown hides video's annotation
	IvPolicyNotShown
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ControlsMode

type ControlsMode int
const (
	// ControlsNotDisplay has the player controls not displayed in the player
	ControlsNotDisplay ControlsMode = iota
	// ControlsDisplayImmediately has the controls displayed immediately and
	// the Flash player also loads immediately.
	ControlsDisplayImmediately
	// ControlsDisplayAfter has the controls displayed, and the Flash player
	// loaded after the user initiates the video playback.
	ControlsDisplayAfter
)

type CuePlaylistOptions

type CuePlaylistOptions struct {
	*js.Object
	ListType ListType `js:"listType"`
	// the ID of the list
	List             string  `js:"list"`
	Index            int     `js:"index"`
	StartSeconds     float64 `js:"startSeconds"`
	SuggestedQuality Quality `js:"suggestedQuality"`
}

CuePlaylistOptions represents an argument for Player.CuePlaylist2(arg)

func NewCuePlaylistOptions

func NewCuePlaylistOptions() *CuePlaylistOptions

NewCuePlaylistOptions prepares an argument for Player.CuePlaylist2(arg) with all inner objects properly initialized

type Error

type Error int

Error represents the errors returned OnError event

const (
	ErrInvalidParameters Error = 2
	ErrNonHTML5          Error = 5
	ErrVideoNotFound     Error = 100
	ErrNotForEmbedded    Error = 101
)

func (Error) String

func (err Error) String() string

type Event

type Event struct {
	*js.Object
	Target *Player    `js:"target"`
	Data   *js.Object `js:"data"`
}

type EventType

type EventType string
const (
	OnReady                 EventType = "onReady"
	OnStateChange           EventType = "onStateChange"
	OnPlaybackQualityChange EventType = "onPlaybackQualityChange"
	OnPlaybackRateChange    EventType = "onPlaybackRateChange"
	OnError                 EventType = "onError"
	OnApiChange             EventType = "onApiChange"
)

type ListType

type ListType string
const (
	// ListTypePlaylist represents playlist
	ListTypePlaylist ListType = "playlist"
	// ListTypeSearch represents search list
	ListTypeSearch ListType = "search"
	// ListTypeUserUploads represents user uploads
	ListTypeUserUploads ListType = "user_uploads"
)

type LoadByIDOptions

type LoadByIDOptions struct {
	*js.Object
	VideoID          string  `js:"videoId"`
	StartSeconds     float64 `js:"startSeconds"`
	EndSeconds       float64 `js:"endSeconds"`
	SuggestedQuality Quality `js:"suggestedQuality"`
}

LoadByIDOptions represents an argument for Player.LoadVideoByID2(arg) and Player.CueVideoByID2(arg)

func NewLoadByIDOptions

func NewLoadByIDOptions() *LoadByIDOptions

NewLoadByIDOptions prepares an argument for Player.LoadVideoByID2(arg) and Player.CueVideoByID2(arg) with all inner objects properly initialized

type LoadByURLOptions

type LoadByURLOptions struct {
	*js.Object
	MediaContentURL  string  `js:"mediaContentUrl"`
	StartSeconds     float64 `js:"startSeconds"`
	EndSeconds       float64 `js:"endSeconds"`
	SuggestedQuality Quality `js:"suggestedQuality"`
}

LoadByURLOptions represents an argument for Player.LoadVideoByUrl2(arg)

func NewLoadByURLOptions

func NewLoadByURLOptions() *LoadByURLOptions

NewLoadByURLOptions returns a prepared argument for Player.LoadeVideoByUrl2(arg) with all inner objects properly initialized

type Player

type Player struct {
	*js.Object
}

Player represents the Youtube Iframe player

func NewPlayer

func NewPlayer(iframeID string, props *Properties) *Player

NewPlayer creates a new youtube player by replacing the provided iframe with the id of iframeId This call is equivalent to new YT.Player(id, props)

func (*Player) AddEventListener

func (p *Player) AddEventListener(event EventType, listener func(event *Event))

func (*Player) AvailablePlaybackRates

func (p *Player) AvailablePlaybackRates() []float64

AvailableRates returns the set of playback rates in which the current video is available

func (*Player) AvailableQualityLevels

func (p *Player) AvailableQualityLevels() []Quality

func (*Player) CuePlaylist

func (p *Player) CuePlaylist(ids []string, index int, startSec float64, q Quality)

func (*Player) CuePlaylist2

func (p *Player) CuePlaylist2(params *CuePlaylistOptions)

func (*Player) CueVideoByID

func (p *Player) CueVideoByID(vid string, startSec float64, q Quality)

func (*Player) CueVideoByID2

func (p *Player) CueVideoByID2(params *LoadByIDOptions)

func (*Player) CurrentTime

func (p *Player) CurrentTime() float64

func (*Player) Destroy

func (p *Player) Destroy()

func (*Player) Duration

func (p *Player) Duration() float64

func (*Player) Iframe

func (p *Player) Iframe() *js.Object

func (*Player) IsMuted

func (p *Player) IsMuted() bool

func (*Player) LoadPlaylist

func (p *Player) LoadPlaylist(ids []string, index int, startSec float64, q Quality)

func (*Player) LoadPlaylist2

func (p *Player) LoadPlaylist2(params *CuePlaylistOptions)

func (*Player) LoadVideoByID

func (p *Player) LoadVideoByID(vid string, startSec float64, q Quality)

func (*Player) LoadVideoByID2

func (p *Player) LoadVideoByID2(params *LoadByIDOptions)

func (*Player) LoadVideoByURL

func (p *Player) LoadVideoByURL(url string, startSec float64, q Quality)

func (*Player) LoadVideoByURL2

func (p *Player) LoadVideoByURL2(params *LoadByURLOptions)

func (*Player) Mute

func (p *Player) Mute()

func (*Player) NextVideo

func (p *Player) NextVideo()

func (*Player) PauseVideo

func (p *Player) PauseVideo()

func (*Player) PlayVideo

func (p *Player) PlayVideo()

func (*Player) PlayVideoAt

func (p *Player) PlayVideoAt(index int)

func (*Player) PlaybackQuality

func (p *Player) PlaybackQuality() Quality

func (*Player) PlaybackRate

func (p *Player) PlaybackRate() float64

func (*Player) PlayerState

func (p *Player) PlayerState() PlayerState

func (*Player) Playlist

func (p *Player) Playlist() []string

func (*Player) PlaylistIndex

func (p *Player) PlaylistIndex() int

func (*Player) PreviousVideo

func (p *Player) PreviousVideo()

func (*Player) RemoveEventListener

func (p *Player) RemoveEventListener(event EventType, listener func(event *Event))

func (*Player) SeekTo

func (p *Player) SeekTo(seconds float64, allowSeekAhead bool)

func (*Player) SetLoop

func (p *Player) SetLoop(val bool)

func (*Player) SetPlaybackQuality

func (p *Player) SetPlaybackQuality(suggested Quality)

func (*Player) SetPlaybackRate

func (p *Player) SetPlaybackRate(suggestedRate float64)

func (*Player) SetShuffle

func (p *Player) SetShuffle(val bool)

func (*Player) SetSize

func (p *Player) SetSize(width int, height int) *js.Object

func (*Player) SetVolume

func (p *Player) SetVolume(vol int)

func (*Player) StopVideo

func (p *Player) StopVideo()

func (*Player) UnMute

func (p *Player) UnMute()

func (*Player) VideoData

func (p *Player) VideoData() *VideoData

func (*Player) VideoEmbedCode

func (p *Player) VideoEmbedCode() string

func (*Player) VideoLoadedFraction

func (p *Player) VideoLoadedFraction() float64

func (*Player) VideoURL

func (p *Player) VideoURL() string

func (*Player) Volume

func (p *Player) Volume() int

type PlayerEvents

type PlayerEvents struct {
	*js.Object
	OnReady                 func(*Event) `js:"onReady"`
	OnStateChange           func(*Event) `js:"onStateChange"`
	OnPlaybackQualityChange func(*Event) `js:"onPlaybackQualityChange"`
	OnPlaybackRateChange    func(*Event) `js:"onPlaybackRateChange"`
	OnError                 func(*Event) `js:"onError"`
	OnAPIChange             func(*Event) `js:"onApiChange"`
}

PlayerEvents contains a set of callbacks assigned at the creation of the player. This struct's fields correspond to each youtube.EventType

type PlayerParams

type PlayerParams struct {
	*js.Object
	Autoplay       int             `js:"autoplay"`
	CcLoadPolicy   int             `js:"cc_load_policy"`
	Color          ProgessBarColor `js:"color"`
	Controls       ControlsMode    `js:"controls"`
	DisableKB      int             `js:"disablekb"`
	EnableJsAPI    int             `js:"enablejsapi"`
	End            int             `js:"end"`
	Fs             int             `js:"fs"`
	Hl             string          `js:"hl"`
	IvLoadPolicy   int             `js:"iv_load_policy"`
	List           string          `js:"list"`
	ListType       ListType        `js:"listType"`
	Loop           int             `js:"loop"`
	ModestBranding int             `js:"modestbranding"`
	Origin         string          `js:"origin"`
	Playlist       []string        `js:"playlist"`
	PlaysInline    int             `js:"playsinline"`
	Rel            int             `js:"rel"`
	ShowInfo       int             `js:"showinfo"`
	Start          int             `js:"start"`
	WidgetReferrer string          `js:"widget_referrer"`
}

PlayerParams represents the player parameter documented at https://developers.google.com/youtube/player_parameters

type PlayerState

type PlayerState int

PlayerState represents the youtube player's state

const (
	Unstarted PlayerState = iota - 1
	Ended
	Playing
	Paused
	Buffering

	VideoCued
)

type ProgessBarColor

type ProgessBarColor string
const (
	Red   ProgessBarColor = "red"
	White ProgessBarColor = "white"
)

type Properties

type Properties struct {
	*js.Object
	Width      int           `js:"width"`
	Height     int           `js:"height"`
	VideoID    string        `js:"videoId"`
	PlayerVars *PlayerParams `js:"playerVars"`
	Events     *PlayerEvents `js:"events"`
}

Properties represents a set of video properties feeded to NewPlayer(id, properties) to create the player. NewProperties() is recommended to create the properties.

func NewProperties

func NewProperties() *Properties

NewProperties creates a new Property JS object with all inner objects properly initialized

type Quality

type Quality string

Quality represents the player video's quality

const (
	Small   Quality = "small"
	Medium  Quality = "medium"
	Large   Quality = "large"
	HD720   Quality = "hd720"
	HD1080  Quality = "hd1080"
	HighRes Quality = "highres"
)

type VideoData

type VideoData struct {
	*js.Object
	VideoID      string  `js:"video_id"`
	Author       string  `js:"author"`
	Title        string  `js:"title"`
	VideoQuality Quality `js:"video_quality"`
}

Directories

Path Synopsis
Package ytutil contains utility functions for setting up the Youtube Iframe API The application, however, can be set up without using this package.
Package ytutil contains utility functions for setting up the Youtube Iframe API The application, however, can be set up without using this package.

Jump to

Keyboard shortcuts

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