moonstone/ Video Player
Provides Moonstone-themed video player components.
import VideoPlayer from '@enact/moonstone/VideoPlayer';Members
VideoPlayerComponent
A standard HTML5 video player for Moonstone. It behaves, responds to, and operates like a
<video> tag in its support for <source>. It also accepts custom tags such as
<infoComponents> for displaying additional information in the title area and <MediaControls>
for handling media playback controls and adding more controls.
Example usage:
<VideoPlayer title="Hilarious Cat Video" poster="http://my.cat.videos/boots-poster.jpg">
<source src="http://my.cat.videos/boots.mp4" type="video/mp4" />
<infoComponents>A video about my cat Boots, wearing boots.</infoComponents>
<MediaControls>
<leftComponents><IconButton backgroundOpacity="translucent">star</IconButton></leftComponents>
<rightComponents><IconButton backgroundOpacity="translucent">flag</IconButton></rightComponents>
<Button backgroundOpacity="translucent">Add To Favorites</Button>
<IconButton backgroundOpacity="translucent">search</IconButton>
</MediaControls>
</VideoPlayer>To invoke methods (e.g.: fastForward()) or get the current state (getMediaState()), store a
ref to the VideoPlayer within your component:
...
setVideoPlayer = (node) => {
this.videoPlayer = node;
}
play () {
this.videoPlayer.play();
}
render () {
return (
<VideoPlayer ref={this.setVideoPlayer} />
);
}import VideoPlayer from '@enact/moonstone/VideoPlayer';MediaControlsComponent
A set of components for controlling media playback and rendering additional components.
This uses Slottable to accept the custom tags, <leftComponents>
and <rightComponents>, to add components to the left and right of the media
controls. Any additional children will be rendered into the "more" controls area causing the
"more" button to appear. Showing the additional components is handled by MediaControls when the
user taps the "more" button.
import {MediaControls} from '@enact/moonstone/VideoPlayer';Properties
- Default: 'backward'
- Default: 'forward'
- Default: 'jumpbackward'
Disables state on the media "jump" buttons; the outer pair.
- Default: 'jumpforward'
These components are placed below the title. Typically these will be media descriptor icons, like how many audio channels, what codec the video uses, but can also be a description for the video or anything else that seems appropriate to provide information about the video to the user.
Disables the media buttons.
The label for the "more" button for when the "more" tray is open. This will show on the tooltip.
Default: 'Back'The color of the underline beneath more icon button.
This property accepts one of the following color names, which correspond with the colored buttons on a standard remote control:
'red','green','yellow','blue'.Default: 'blue'Disables the media "more" button.
The label for the "more" button. This will show on the tooltip.
Default: 'More'A custom more button ID to use with Spotlight.
Removes the "jump" buttons. The buttons that skip forward or backward in the video.
Removes the "rate" buttons. The buttons that change the playback rate of the video. Double speed, half speed, reverse 4x speed, etc.
Called when the user clicks the Backward button.
Called when cancel/back key events are fired.
Called when the user clicks the Forward button.
Called when the user clicks the JumpBackward button
Called when the user clicks the JumpForward button.
Called when the user clicks the More button.
Called when the user clicks the Play button.
A string which is sent to the
pauseicon of the player controls. This can be anything that is accepted by Icon. This will be temporarily replaced by the playIcon when the paused boolean isfalse.Default: 'pause'truewhen the video is paused.A string which is sent to the
playicon of the player controls. This can be anything that is accepted by Icon. This will be temporarily replaced by the pauseIcon when the paused boolean istrue.Default: 'play'Disables the media "play"/"pause" button.
Disables the media playback-rate control buttons; the inner pair.
These components are placed into the slot to the right of the media controls.
truecontrols are disabled from Spotlight.The spotlight ID for the media controls container.
Default: 'mediaControls'The visibility of the component. When
false, the component will be hidden.Default: true
VideoComponent
Provides support for more advanced video configurations for VideoPlayer.
Custom Video Tag
<VideoPlayer>
<Video mediaComponent="custom-video-element">
<source src="path/to/source.mp4" />
</Video>
</VideoPlayer>Preload Video Source
<VideoPlayer>
<Video>
<source src="path/to/source.mp4" />
<source src="path/to/preload-source.mp4" slot="preloadSource" />
</Video>
</VideoPlayer>import {Video} from '@enact/moonstone/VideoPlayer';Properties
Video plays automatically.
Default: falseVideo component to use.
The default (
'video') renders anHTMLVideoElement. Custom video components must have a similar API structure, exposing the following APIs:Properties:
currentTime{Number} - Playback index of the media in secondsduration{Number} - Media's entire duration in secondserror{Boolean} -trueif video playback has errored.loading{Boolean} -trueif video playback is loading.paused{Boolean} - Playing vs paused state.truemeans the media is pausedplaybackRate{Number} - Current playback rate, as a numberproportionLoaded{Number} - A value between0and1representing the proportion of the media that has loadedproportionPlayed{Number} - A value between0and1representing the proportion of the media that has already been shown
Events:
onLoadStart- Called when the video starts to loadonPlay- Sent when playback of the media starts after having been pausedonUpdate- Sent when any of the properties were updated
Methods:
play()- play videopause()- pause videoload()- load video
The source property is passed to the video component as a child node.
Default: 'video'The video source to be preloaded. Expects a
<source>node.The video source to be played.
Any children
<source>elements will be sent directly to themediaComponentas video sources.See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/source
VideoPlayerBaseComponent
A player for video moonstone/VideoPlayer.VideoPlayerBase.
import {VideoPlayerBase} from '@enact/moonstone/VideoPlayer';Properties
The time (in milliseconds) before the control buttons will hide.
Setting this to 0 or
nulldisables closing, requiring user input to open and close.Default: 5000Removes interactive capability from this component. This includes, but is not limited to, key-press events, most clickable buttons, and prevents the showing of the controls.
Amount of time (in milliseconds) after which the feedback text/icon part of the slider's tooltip will automatically hidden after the last action. Setting this to 0 or
nulldisables feedbackHideDelay; feedback will always be present.Default: 3000Components placed below the title.
Typically these will be media descriptor icons, like how many audio channels, what codec the video uses, but can also be a description for the video or anything else that seems appropriate to provide information about the video to the user.
The number of seconds the player should skip forward or backward when a "jump" button is pressed.
Default: 30Manually set the loading state of the media, in case you have information that
VideoPlayerdoes not have.The current locale as a BCP 47 language tag.
Overrides the default media control component to support customized behaviors.
The provided component will receive the following props from
VideoPlayer:mediaDisabled-truewhen the media controls are not interactiveonBackwardButtonClick- Called when the rewind button is pressedonClose- Called when cancel key is pressed when the media controls are visibleonFastForward- Called when the media is fast forwarded via a key eventonForwardButtonClick- Called when the fast forward button is pressedonJump- Called when the media jumps either forward or backwardonJumpBackwardButtonClick- Called when the jump backward button is pressedonJumpForwardButtonClick- Called when the jump forward button is pressedonKeyDown- Called when a key is pressedonPause- Called when the media is paused via a key eventonPlay- Called when the media is played via a key eventonRewind- Called when the media is rewound via a key eventonToggleMore- Called when the more components are hidden or shownpaused-truewhen the media is pausedspotlightId- The spotlight container Id for the media controlsspotlightDisabled-truewhen spotlight is disabled for the media controlsvisible-truewhen the media controls should be displayed
Default: `moonstone/VideoPlayer.MediaControls`Amount of time (in milliseconds), after the last user action, that the
miniFeedbackwill automatically hide. Setting this to 0 ornulldisablesminiFeedbackHideDelay;miniFeedbackwill always be present.Default: 2000Disable audio for this video.
In a TV context, this is handled by the remote control, not programmatically in the VideoPlayer API.
Default: falsePrevents the default behavior of playing a video immediately after it's loaded.
Default: falsePrevents the default behavior of showing media controls immediately after it's loaded.
Default: falseHides media slider feedback when fast forward or rewind while media controls are hidden.
Default: falseRemoves the mini feedback.
Default: falseRemoves the media slider.
Default: falseRemoves spinner while loading.
Called when the player's controls change availability, whether they are shown or hidden.
The current status is sent as the first argument in an object with a key
availablewhich will be eithertrueorfalse. (e.g.:onControlsAvailable({available: true}))Called when the video is fast forwarded.
Called when the user clicks the JumpBackward button.
Is passed a moonstone/VideoPlayer.videoStatus as the first argument.
Called when the user clicks the JumpForward button.
Is passed a moonstone/VideoPlayer.videoStatus as the first argument.
Called when video is paused
Called when video is played
Called when video is rewound.
Called when the user is moving the VideoPlayer's Slider knob independently of the current playback position.
It is passed an object with a
secondskey (float value) to indicate the current time index. It can be used to update thethumbnailSrcto the reflect the current scrub position.Called when seek is attempted while
seekDisabledis true.Called when seeking outside of the current
selectionrange.By default, the seek will still be performed. Calling
preventDefault()on the event will prevent the seek operation.Pauses the video when it reaches either the start or the end of the video during rewind, slow rewind, fast forward, or slow forward.
Default: falseMapping of playback rate names to playback rate values that may be set.
Default:Show default value{fastForward: ['2', '4', '8', '16'],rewind: ['-2', '-4', '-8', '-16'],slowForward: ['1/4', '1/2'],slowRewind: ['-1/2', '-1']}Disables seek function.
Note that jump by arrow keys will also be disabled when
true.A range of the video to display as selected.
The value of
selectionmay either be:nullorundefinedfor no selection,a single-element array with the start time of the selection
a two-element array containing both the start and end time of the selection in seconds
When the start time is specified, the media slider will show filled starting at that time to the current time.
When the end time is specified, the slider's background will be filled between the two times.
The video source.
Any children
<source>tag elements of VideoPlayer will be sent directly to thevideoComponentas video sources.Disables spotlight navigation into the component.
The spotlight container ID for the player.
Default: 'videoPlayer'The thumbnail component to be used instead of the built-in version.
The internal thumbnail style will not be applied to this component. This component follows the same rules as the built-in version.
Thumbnail image source to show on the slider knob.
This is a standard moonstone/Image component so it supports all of the same options for the
srcproperty. If nothumbnailComponentand nothumbnailSrcis set, no tooltip will display.Title for the video being played.
The time (in milliseconds) before the title disappears from the controls.
Setting this to
0disables hiding.Default: 5000Video component to use.
The default renders an
HTMLVideoElement. Custom video components must have a similar API structure, exposing the following APIs:Properties:
currentTime{Number} - Playback index of the media in secondsduration{Number} - Media's entire duration in secondserror{Boolean} -trueif video playback has errored.loading{Boolean} -trueif video playback is loading.paused{Boolean} - Playing vs paused state.truemeans the media is pausedplaybackRate{Number} - Current playback rate, as a numberproportionLoaded{Number} - A value between0and1representing the proportion of the media that has loadedproportionPlayed{Number} - A value between0and1representing the proportion of the media that has already been shown
Events:
onLoadStart- Called when the video starts to loadonUpdate- Sent when any of the properties were updated
Methods:
play()- play videopause()- pause videoload()- load video
The source property is passed to the video component as a child node.
Default: {@link ui/Media.Media}
Methods
- fastForward()
Changes the playback speed via selectPlaybackRate().
- getMediaState()Object
Returns an object with the current state of the media including
currentTime,duration,paused,playbackRate,proportionLoaded, andproportionPlayed.Returns
- Object
- getVideoNode()
Returns a proxy to the underlying
<video>node currently used by the VideoPlayer- hideControls()
Hides media controls.
- jump(distance)
Step a given amount of time away from the current playback position. Like seek but relative.
1 Param
- distance Number
Time value to jump
- pause()
Programmatically plays the current media.
- play()
Programmatically plays the current media.
- rewind()
Changes the playback speed via selectPlaybackRate().
- seek(timeIndex)
Set the media playback time index
1 Param
- timeIndex Number
Time index to seek
- showControls()
Shows media controls.
- toggleControls()
Toggles the media controls.
Type Definitions
playbackRateHashObject
A set of playback rates when media fast forwards, rewinds, slow-fowards, or slow-rewinds.
The number used for each operation is proportional to the normal playing speed, 1. If the rate is less than 1, it will play slower than normal speed, and, if it is larger than 1, it will play faster. If it is negative, it will play backward.
The order of numbers represents the incremental order of rates that will be used for each
operation. Note that all rates are expressed as strings and fractions are used rather than decimals
(e.g.: '1/2', not '0.5').
- fastForward •
- ArrayString
An array of playback rates when media fast forwards
- rewind •
- ArrayString
An array of playback rates when media rewinds
- slowForward •
- ArrayString
An array of playback rates when media slow-forwards
- slowRewind •
- ArrayString
An array of playback rates when media slow-rewinds
videoStatusObject
Every callback sent by VideoPlayer receives a status package, which includes an object with the following key/value pairs as the first argument:
- type •
- String
Type of event that triggered this callback
- currentTime •
- Number
Playback index of the media in seconds
- duration •
- Number
Media's entire duration in seconds
- paused •
- Boolean
Playing vs paused state.
truemeans the media is paused- playbackRate •
- Number
Current playback rate, as a number
- proportionLoaded •
- Number
A value between
0and1representing the proportion of the media that has loaded- proportionPlayed •
- Number
A value between
0and1representing the proportion of the media that has already been shown