Config provided by player and plugins for developers to customrize player to match their scenario
Stringid of a DOM node that you want player to mount on
new Player({
id:'mse'
})
HTMLElementAnother way to tell player the mount node is pass it to config.el directly
new Player({
el: document.querySelector('#mse'),
})
::: Notice
You need to pass either config.el or config.id to player, if both of them exist, player will use the value from config.id
:::
String | Object[]''When the URL is in the form of an array, Source Tag will be used for playback
new Player({
id:'mse',
url: '//abc.com/**/*.mp4',
...
});
// or
new Player({
id:'mse',
url: [
{
src: '//abc.com/**/*.mp4',
type: 'video/mp4'
},
...
],
...
});
Number | String600Target width of player, use number for a width by px, or string for other units
Number | String337.5Target height of player, use number for a height by px, or string for other units
BooleanfalseIf setted with value true, player would invoke video.play() after enough media data loaded.
::: Notice In many cases, autoplay action was limited by browser policy :::
BooleanfalseAutoplay with video muted
BooleantrueLoading media resource immediately after player inited
BooleantrueEnable inline playing mode, would set playsinline DOM attribute to media element. for more details about inline playing mode see new-video-policies-for-ios
WARNING
For devices which's version under ios10, playsinline config doesn't work
Number1Default playbackrate for media element, reference values: 0.5/0.75/1/1.5/2
Number0.6HTMLMediaElement.volume
BooleanfalseHTMLMediaElement.loop
StringPoster image url
Number0When setted, player would immediately seek to startTime after media resource loaded
Object{}DOM attributes for media element, for more details see MediaElement
Stringdocument.documentElement.getAttribute('lang') || navigator.language || 'zh-cn'Player language
BooleanfalseThe fluid layout allows the player's width varies to follow the width of the parent element's change, and the height varies according to the height and width proportion of the configuration item (the player's width and height is the internal default value when width and height are not set).
Stringfixedfixed static sizefixWidth fit by widthfixHeight fit by heightWhen video resource was playing, fit raw height、width of video resource to player's
Stringautoreference values: fillHeight | fillWidth | fill | auto
Stringplayplaypauseauto Keep player status before seekingPlayer status after seeking
Array[]Marks for progress bar
const progressDot = [{
id: 0,
time: 10, // Shows on progress bar with the position: time / player.duration
text: '01', // Text shows when user hovers on it
duration: 5, // Mark duration
color: 'red', // Mark color
style: {} // Style object for mark DOM
},
...
]
ObjectnullThumbnail for user to preview unplayed video content
var thumbnail = {
urls: [], // Thumbnail picture urls
pic_num: 0, // Total number for all thumbnail pictures
row: 0, // Row number in seperate thumbnail picture
col: 0, // Col number in seperate thumbnail picture
height: 160, // Height for video frame in seperate thumbnail picture by px
width: 90 // Width for video frame in seperate thumbnail picture by px
}
BooleanfalseIf player render control bar and media element sperately
marginControls:false
marginControls:true
numberThe threshold for delayed response of the event waiting. A typical scenario is: this configuration can avoid displaying the short loading UI. After the video is played to this time point, if the state of the video player is still waiting, the waiting event will be triggered. The triggering time of the waiting event may be changed: canplay, timeupdate, seeked
BooleanfalsePrevent player from entering focused status when mousemoving on media element Only for PC Browsers
BooleanfalsePrevent player from entering focused status when user pause player
BooleanfalsePrevent player from entering focused status when user play player
BooleanfalseFor PC browsers: prevent user from pausing/playing player by click media element For mobile browsers: prevent user pausing/playing player by touch media element
BooleanfalseFor PC browsers: prevent user from pausing/playing player by double click media element For mobile browsers: prevent user pausing/playing player by double touch media element
BooleanfalsePrevent player from auto entering blur status
Number3000Duration after user's last interaction, for player to enter blur status
Number3000It only takes effect on the PC side, 'leavePlayerTime'
is the delay time in milliseconds to haide the control bar when the user's mouse leaves the player area. If you want to hide bar immediately, set it to 0
BooleantrueIf auto hide player's top bar (custom plugin's mount position - ROOT_TOP)
BooleanfalseEnable context menu for user
BooleantrueAllow user to perform seek action after video ended
type: array
default value: []
Plugin list, use a plugin by pass it to config.plugins. Plugin you passed would be inited by player
import Aplugin from 'Aplugin'
new Player({
el:document.querySelector('#mse'),
url: '{{ video_url }}',
plugins: [Aplugin]
});
You can pass config to a plugin by setting config[pluginName]
// pluginName为'aplugin'
import Aplugin from 'a-xgplayer-plugin'
new Player({
el:document.querySelector('#mse'),
url: '{{ video_url }}',
plugins: [Aplugin],
[pluginName]: {{ pluginConfig }}
});
Lazyload plugin
new Player({
...,
plugins: [{
loader: () => import('a-xgplayer-plugin'), // 异步加载器,需要bundler(webpack、rollup等)支持
timeout: 10000, // Max waiting time for plugin loading
lazy: true, // Mark this plugin as an lazyload plugin
forceBeforeInit: true // Player should waits for plugin loaded before invoking plugin lifecycle callback "beforeInit"
}],
[pluginName]: {{ pluginConfig }}
})
array[]Preset list, for more details about preset, see preset mechanism
array[]Ignore built-in plugins by pluginName
new Player({
...,
ignores: ['start']
})
object{}Config for customizing player UI, pass DOMString、DOM node、image URL are all acceptable,
For more details about icons see Icons
import MyPlayIcon from '../icons/my-play-icon.svg';
import MyPauseIcon from '../icons/my-pause-icon.svg';
import Player from 'xgplayer'
const player = new Player({
el:document.querySelector('#mse'),
icons: {
play: MyPlayIcon,
pause: MyPauseIcon
}
})
Notice! if you want to use svg image, please convert it to string before passing. for webpack users we recommand you to use raw-loader
object{}Styles config for built-in plugins
{
progressColor: '',
playedColor: '',
// Media cached color
cachedColor: '',
// Progress slider button style
sliderBtnStyle: {},
// Volume bar color
volumeColor: ''
}
Boolean/objecttruePass false to disable the control bar, on the other hand you can pass controls config to customize the control bar, for more details see built-in controls plugin
BooleanfalsePass true to enable the mini progress bar, which comes out when control bar hide;
BooleanfalsePass true to enable screenShot, this configuration is the shortcut start configuration of the screenshot plugin, or you can pass in a set of screenshot plugin configuration,for more details see
internalPlugins->screenShot
BooleanfalsePass true to enable rotate, this configuration is the shortcut start configuration of the rotate plugin, or you can pass in a set of rotate plugin configuration,for more details see internalPlugins->rotate
BooleanfalsePass true to enable download, this configuration is the shortcut start configuration of the download plugin, or you can pass in a set of download plugin configuration,for more details see internalPlugins->download
BooleanfalsePass true to enable pip (Picture in Picture), this configuration is the shortcut start configuration of the pip plugin, or you can pass in a set of pip plugin configuration,for more details see internalPlugins->pip
BooleanfalsePass true to enable mini, this configuration is the shortcut start configuration of the mini plugin, or you can pass in a set of mini plugin configuration,for more details see internalPlugins->miniscreen
Boolean | {}falsePass true to enable cssFullscreen plugin which uses css to realize video full screen, this configuration is the shortcut start configuration of the cssFullscreen plugin, or you can pass in a set of cssFullscreen plugin configuration,for more details see internalPlugins->cssfullscreen
Boolean | array | {}[0.5, 0.75, 1, 1.5, 2]Pass false or array to control playbackRate plugin, when pass false, playbackRate plugin will be disabled,for more details see internalPlugins->playbackrate
BooleantruePass true to enable keyShortcut, for more details see internalPlugins->keyboard