VideoPlayer
Table of contents
- Create from source
- Create from resource
- Interface description
- Properties
- Events
- "abort-event"
- "can-play-event"
- "can-play-through-event"
- "complete-event"
- "duration-changed-event"
- "emptied-event"
- "ended-event"
- "load-start-event"
- "loaded-data-event"
- "loaded-metadata-event"
- "pause-event"
- "play-event"
- "player-error-event"
- "playing-event"
- "progress-event"
- "rate-changed-event"
- "seeked-event"
- "seeking-event"
- "stalled-event"
- "suspend-event"
- "time-update-event"
- "volume-changed-event"
- "waiting-event"
- Related global functions
Video playback. Implements MediaPlayer
common interface for players
Create from source
func NewVideoPlayer(session Session, params Params) VideoPlayer
Create new video player object and returns its interface
Create from resource
VideoPlayer {
id = videoPlayer,
src = video.mp4,
video-width = 320,
}
Interface description
Inherit methods, properties and events from MediaPlayer
Properties
"controls"
Whether the browser need to provide controls to allow user to control video playback, volume, seeking and pause/resume playback. Default value is false
Constant: Controls
Types: bool
, int
, string
Values
bool | int | string | Description |
---|---|---|---|
true |
1 |
"true", "yes", "on", "1" | The browser will offer controls to allow the user to control video playback, volume, seeking and pause/resume playback |
false |
0 |
"false", "no", "off", "0" | No controls will be visible to the end user |
"loop"
Controls whether the video player will play media in a loop. Default value is false
Constant: Loop
Types: bool
, int
, string
Values
bool | int | string | Description |
---|---|---|---|
true |
1 |
"true", "yes", "on", "1" | The video player will automatically seek back to the start upon reaching the end of the video |
false |
0 |
"false", "no", "off", "0" | Video player will stop playing when the end of the media file has been reached |
"muted"
Controls whether the video will be initially silenced. Default value is false
Constant: Muted
Types: bool
, int
, string
Values
bool | int | string | Description |
---|---|---|---|
true |
1 |
"true", "yes", "on", "1" | Video will be muted |
false |
0 |
"false", "no", "off", "0" | Video playing normally |
"poster"
Defines an URL for an image to be shown while the video is downloading. If this attribute isn't specified, nothing is displayed until the first frame is available, then the first frame is shown as the poster frame
Constant: Poster
Types: string
Examples
VideoPlayer {
src = video.mp4,
poster = video-poster.jpg
video-width = 320,
}
video := rui.NewVideoPlayer(session, rui.Params{
rui.Source: "video.mp4",
rui.Poster: "video-poster.jpg",
rui.VideoWidth: 320,
})
video := rui.NewVideoPlayer(session, rui.Params{
rui.Source: "video.mp4",
rui.Poster: "https://www.someserver.com/images/video-poster.jpg",
rui.VideoWidth: 320,
})
"preload"
Property is intended to provide a hint to the browser about what the author thinks will lead to the best user experience. Default value is different for each browser
Constant: Preload
Types: int
, string
Values
int | string | Description |
---|---|---|
0 (PreloadNone ) |
"none" | Media file must not be pre-loaded |
1 (PreloadMetadata ) |
"metadata" | Only metadata is preloaded |
2 (PreloadAuto ) |
"auto" | The entire media file can be downloaded even if the user doesn't have to use it |
"src"
Specifies the location of the media file(s). Since different browsers support different file formats and codecs, it is recommended to specify multiple sources in different formats. The player chooses the most suitable one from the list of sources. Setting mime types makes this process easier for the browser
Constant: Source
Types: string
, MediaSource
, []MediaSource
Internal type is []MediaSource
, other types converted to it during assignment
Examples
VideoPlayer {
id = videoPlayer,
src = video.mp4,
},
player := rui.NewVideoPlayer(session, rui.Params{
rui.Source: "video.mp4",
})
player := rui.NewVideoPlayer(session, rui.Params{
rui.Source: []rui.MediaSource{
{
Url: "video.mp4", MimeType: "video/mp4",
},
},
})
player := rui.NewVideoPlayer(session, rui.Params{
rui.Source: []rui.MediaSource{
{
Url: "video.mp4", MimeType: "video/mp4",
},
{
Url: "video.webm", MimeType: "video/webm",
},
},
})
"video-height"
Defines the height of the video's display area in pixels
Constant: VideoHeight
Types: float
, int
, string
Internal type is float
, other types converted to it during assignment
Examples
VideoPlayer {
src = video.mp4,
video-height = 560,
},
player := rui.NewVideoPlayer(session, rui.Params{
rui.Source: "video.mp4",
rui.VideoHeight: 560,
})
"video-width"
Defines the width of the video's display area in pixels
Constant: VideoWidth
Types: float
, int
, string
Values
Internal type is float
, other types converted to it during assignment
Examples
VideoPlayer {
src = video.mp4,
video-width = 320,
},
player := rui.NewVideoPlayer(session, rui.Params{
rui.Source: "video.mp4",
rui.VideoWidth: 320,
})
Events
"abort-event"
Fired when the resource was not fully loaded, but not as the result of an error
Constant: AbortEvent
General listener format:
func(player rui.MediaPlayer)
where: * player - Interface of a player which generated this event
Allowed listener formats:
func()
"can-play-event"
Occur when the browser can play the media, but estimates that not enough data has been loaded to play the media up to its end without having to stop for further buffering of content
Constant: CanPlayEvent
General listener format:
func(player rui.MediaPlayer)
where: * player - Interface of a player which generated this event
Allowed listener formats:
func()
"can-play-through-event"
Occur when the browser estimates it can play the media up to its end without stopping for content buffering
Constant: CanPlayThroughEvent
General listener format:
func(player rui.MediaPlayer)
where: * player - Interface of a player which generated this event
Allowed listener formats:
func()
"complete-event"
Occur when the rendering of an OfflineAudioContext has been terminated
Constant: CompleteEvent
General listener format:
func(player rui.MediaPlayer)
where: * player - Interface of a player which generated this event
Allowed listener formats:
func()
"duration-changed-event"
Occur when the duration attribute has been updated
Constant: DurationChangedEvent
General listener format:
func(player rui.MediaPlayer, duration float64)
where: * player - Interface of a player which generated this event * duration - Current duration
Allowed listener formats:
func(player rui.MediaPlayer)
func(duration float64)
func()
"emptied-event"
Occur when the media has become empty; for example, this event is sent if the media has already been loaded(or partially loaded), and the HTMLMediaElement.load method is called to reload it
Constant: EmptiedEvent
General listener format:
func(player rui.MediaPlayer)
where: * player - Interface of a player which generated this event
Allowed listener formats:
func()
"ended-event"
Occur when the playback has stopped because the end of the media was reached
Constant: EndedEvent
General listener format:
func(player rui.MediaPlayer)
where: * player - Interface of a player which generated this event
Allowed listener formats:
func()
"load-start-event"
Fired when the browser has started to load a resource
Constant: LoadStartEvent
General listener format:
func(player rui.MediaPlayer)
where: * player - Interface of a player which generated this event
Allowed listener formats:
func()
"loaded-data-event"
Occur when the first frame of the media has finished loading
Constant: LoadedDataEvent
General listener format:
func(player rui.MediaPlayer)
where: * player - Interface of a player which generated this event
Allowed listener formats:
func()
"loaded-metadata-event"
Occur when the metadata has been loaded
Constant: LoadedMetadataEvent
General listener format:
func(player rui.MediaPlayer)
where: * player - Interface of a player which generated this event
Allowed listener formats:
func()
"pause-event"
Occur when the playback has been paused
Constant: PauseEvent
General listener format:
func(player rui.MediaPlayer)
where: * player - Interface of a player which generated this event
Allowed listener formats:
func()
"play-event"
Occur when the playback has begun
Constant: PlayEvent
General listener format:
func(player rui.MediaPlayer)
where: * player - Interface of a player which generated this event
Allowed listener formats:
func()
"player-error-event"
Fired when the resource could not be loaded due to an error(for example, a network connectivity problem)
Constant: PlayerErrorEvent
General listener format:
func(player rui.MediaPlayer, code int, message string)
where: * player - Interface of a player which generated this event * code - Error code. See below * message - Error message
Error code | Description |
---|---|
0 (PlayerErrorUnknown ) |
Unknown error |
1 (PlayerErrorAborted ) |
Fetching the associated resource was interrupted by a user request |
2 (PlayerErrorNetwork ) |
Some kind of network error has occurred that prevented the media from successfully ejecting, even though it was previously available |
3 (PlayerErrorDecode ) |
Although the resource was previously identified as being used, an error occurred while trying to decode the media resource |
4 (PlayerErrorSourceNotSupported ) |
The associated resource object or media provider was found to be invalid |
Allowed listener formats:
func(code int, message string)
func(player rui.MediaPlayer)
func()
"playing-event"
Occur when the playback is ready to start after having been paused or delayed due to lack of data
Constant: PlayingEvent
General listener format:
func(player rui.MediaPlayer)
where: * player - Interface of a player which generated this event
Allowed listener formats:
func()
"progress-event"
Fired periodically as the browser loads a resource
Constant: ProgressEvent
General listener format:
func(player rui.MediaPlayer)
where: * player - Interface of a player which generated this event
Allowed listener formats:
func()
"rate-changed-event"
Occur when the playback rate has changed
Constant: RateChangedEvent
General listener format:
func(player rui.MediaPlayer, rate float64)
where: * player - Interface of a player which generated this event * rate - Playback rate
Allowed listener formats:
func(player rui.MediaPlayer)
func(rate float64)
func()
"seeked-event"
Occur when a seek operation completed
Constant: SeekedEvent
General listener format:
func(player rui.MediaPlayer)
where: * player - Interface of a player which generated this event
Allowed listener formats:
func()
"seeking-event"
Occur when a seek operation has began
Constant: SeekingEvent
General listener format:
func(player rui.MediaPlayer)
where: * player - Interface of a player which generated this event
Allowed listener formats:
func()
"stalled-event"
Occur when the user agent is trying to fetch media data, but data is unexpectedly not forthcoming
Constant: StalledEvent
General listener format:
func(player rui.MediaPlayer)
where: * player - Interface of a player which generated this event
Allowed listener formats:
func()
"suspend-event"
Occur when the media data loading has been suspended
Constant: SuspendEvent
General listener format:
func(player rui.MediaPlayer)
where: * player - Interface of a player which generated this event
Allowed listener formats:
func()
"time-update-event"
Occur when the time indicated by the currentTime attribute has been updated
Constant: TimeUpdateEvent
General listener format:
func(player rui.MediaPlayer, time float64)
where: * player - Interface of a player which generated this event * time - Current time
Allowed listener formats:
func(player rui.MediaPlayer)
func(time float64)
func()
"volume-changed-event"
Occur when the volume has changed
Constant: VolumeChangedEvent
General listener format:
func(player rui.MediaPlayer, volume float64)
where: * player - Interface of a player which generated this event * volume - New volume level
Allowed listener formats:
func(player rui.MediaPlayer)
func(volume float64)
func()
"waiting-event"
Occur when the playback has stopped because of a temporary lack of data
Constant: WaitingEvent
General listener format:
func(player rui.MediaPlayer)
where: * player - Interface of a player which generated this event
Allowed listener formats:
func()
Related global functions
func IsMediaPlayerEnded(view View, playerID string) bool
Tells whether the media element is ended
func IsMediaPlayerPaused(view View, playerID string) bool
Tells whether the media element is paused
func MediaPlayerCurrentTime(view View, playerID string) float64
Returns the current playback time in seconds
func MediaPlayerDuration(view View, playerID string) float64
Returns the value indicating the total duration of the media in seconds. If no media data is available, the returned value is NaN
func MediaPlayerPause(view View, playerID string)
Pause playback of the media, if the media is already in a paused state this method will have no effect
func MediaPlayerPlay(view View, playerID string)
Attempts to begin playback of the media
func MediaPlayerPlaybackRate(view View, playerID string) float64
Returns the rate at which the media is being played back
func MediaPlayerVolume(view View, playerID string) float64
Returns the audio volume from 0.0 (silent) to 1.0 (loudest)
func SetMediaPlayerCurrentTime(view View, playerID string, seconds float64)
Set the current playback time in seconds
func SetMediaPlayerPlaybackRate(view View, playerID string, rate float64)
Set the rate at which the media is being played back. This is used to implement user controls for fast forward, slow motion, and so forth. The normal playback rate is multiplied by this value to obtain the current rate, so a value of 1.0 indicates normal speed
func SetMediaPlayerVolume(view View, playerID string, volume float64)
Set the audio volume from 0.0 (silent) to 1.0 (loudest)
func VideoPlayerByID(rootView View, id string) VideoPlayer
Return a VideoPlayer
with id equal to the argument of the function or nil if there is no such View or View is not a VideoPlayer