diff --git a/docs/llms.txt b/docs/llms.txt
index 00e53da88..77a67f110 100644
--- a/docs/llms.txt
+++ b/docs/llms.txt
@@ -4,7 +4,7 @@
Advanced Properties
-The Advanced Properties here refer to the secondary properties attached to the instance, which are less commonly used.
+The Advanced Properties refer to the secondary properties attached to the instance, which are less commonly used.
option
@@ -39,8 +39,8 @@ events
Manages all DOM events for the player. It essentially proxies addEventListener and removeEventListener. When using the following methods to handle events, the event will be automatically destroyed when the player is destroyed.
-- The proxy method is used to proxy DOM events.
-- The hover method is used to proxy custom hover events.
+The proxy method is used to proxy DOM events.
+The hover method is used to proxy custom hover events.
var container = document.querySelector('.artplayer-app');
@@ -50,7 +50,7 @@ var art = new Artplayer({
});
art.events.proxy(container, 'click', event => {
- console.info('click', event);
+ console.info('click', event);
});
art.events.hover(container, (event) => {
@@ -65,11 +65,11 @@ storage
Manages the player's local storage.
-- The name property is used to set the cache key.
-- The set method is used to set a cache value.
-- The get method is used to get a cache value.
-- The del method is used to delete a cache value.
-- The clear method is used to clear all cache.
+The name property is used to set the cache key.
+The set method is used to set a cache value.
+The get method is used to get a cache value.
+The del method is used to delete a cache value.
+The clear method is used to clear all cache.
var art = new Artplayer({
container: '.artplayer-app',
@@ -111,8 +111,8 @@ i18n
Manages the player's i18n.
-- The get method is used to get an i18n value.
-- The update method is used to update the i18n object.
+The get method is used to get an i18n value.
+The update method is used to update the i18n object.
var art = new Artplayer({
container: '.artplayer-app',
@@ -148,11 +148,11 @@ layers
Manages the player's layers.
-- The add method is used to dynamically add a layer.
-- The remove method is used to dynamically remove a layer.
-- The update method is used to dynamically update a layer.
-- The show property is used to set whether all layers are visible.
-- The toggle method is used to toggle the visibility of all layers.
+The add method is used to dynamically add a layer.
+The remove method is used to dynamically remove a layer.
+The update method is used to dynamically update a layer.
+The show property is used to set whether all layers are visible.
+The toggle method is used to toggle the visibility of all layers.
var art = new Artplayer({
container: '.artplayer-app',
@@ -164,9 +164,9 @@ art.on('ready', () => {
html: 'Some Text',
});
- setTimeout(() => {
- art.layers.show = false;
- }, 1000);
+ setTimeout(() => {
+ art.layers.show = false;
+ }, 1000);
});
Refer to the following address for Component Configuration: /component/layers.html
@@ -175,11 +175,11 @@ controls
Manages the player's controls.
-- The add method is used to dynamically add a control.
-- The remove method is used to dynamically remove a control.
-- The update method is used to dynamically update controls.
-- The show property is used to set whether to display all controls.
-- The toggle method is used to toggle the display of all controls.
+The add method is used to dynamically add a control.
+The remove method is used to dynamically remove a control.
+The update method is used to dynamically update controls.
+The show property is used to set whether to display all controls.
+The toggle method is used to toggle the display of all controls.
var art = new Artplayer({
container: '.artplayer-app',
@@ -192,9 +192,9 @@ art.on('ready', () => {
position: 'left',
});
- setTimeout(() => {
- art.controls.show = false;
- }, 1000);
+ setTimeout(() => {
+ art.controls.show = false;
+ }, 1000);
});
For Component Configuration, please refer to: /component/controls.html
@@ -203,11 +203,11 @@ contextmenu
Manages the player's context menu.
-- The add method is used to dynamically add menu items.
-- The remove method is used to dynamically remove menu items.
-- The update method is used to dynamically update menu items.
-- The show property is used to set whether to display all menu items.
-- The toggle method is used to toggle the display of all menu items.
+The add method is used to dynamically add menu items.
+The remove method is used to dynamically remove menu items.
+The update method is used to dynamically update menu items.
+The show property is used to set whether to display all menu items.
+The toggle method is used to toggle the display of all menu items.
var art = new Artplayer({
container: '.artplayer-app',
@@ -220,9 +220,9 @@ art.on('ready', () => {
});
art.contextmenu.show = true;
- setTimeout(() => {
- art.contextmenu.show = false;
- }, 1000);
+ setTimeout(() => {
+ art.contextmenu.show = false;
+ }, 1000);
});
For Component Configuration, please refer to: /component/contextmenu.html
@@ -231,12 +231,12 @@ subtitle
Manages the player's subtitle functionality.
-- The url property sets and returns the current subtitle URL.
-- The style method sets the style of the current subtitle.
-- The switch method sets the current subtitle URL and options.
-- textTrack gets the current text track.
-- activeCues gets the list of currently active cues.
-- cues gets the overall list of cues.
+The url property sets and returns the current subtitle URL.
+The style method sets the style of the current subtitle.
+The switch method sets the current subtitle URL and options.
+textTrack gets the current text track.
+activeCues gets the list of currently active cues.
+cues gets the overall list of cues.
var art = new Artplayer({
container: '.artplayer-app',
@@ -254,9 +254,13 @@ info
Manages the player's information panel, commonly used to view the current status of the player and video, such as version number, resolution, duration, etc.
-Control the panel's visibility via art.info.show. The triggered event is named 'info' (see the event documentation for details).
+ArtPlayer Documentation
-Run Code
+Info Panel
+
+Control the panel's visibility via art.info.show. The triggered event is named info (see the event documentation for details).
+
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
@@ -271,11 +275,11 @@ art.on('ready', () => {
}, 3000);
});
+Loading Layer
-loading
Manages the player's loading layer. The show property is used to set whether to display the loading layer. The toggle property is used to toggle the display of the loading layer.
-Run Code
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
@@ -289,11 +293,11 @@ art.on('ready', () => {
}, 1000);
});
+Hotkey
-hotkey
Manages the player's hotkey functionality. The add method is used to add hotkeys. The remove method is used to remove hotkeys.
-Run Code
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
@@ -313,11 +317,11 @@ art.on('ready', () => {
Note: These hotkeys only take effect after the player gains focus (e.g., after clicking on the player).
+Mask Layer
-mask
Manages the player's mask layer. The show property is used to set whether to display the mask layer. The toggle property is used to toggle the display of the mask layer.
-Run Code
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
@@ -331,11 +335,11 @@ art.on('ready', () => {
}, 1000);
});
+Setting Panel
-setting
Manages the player's settings panel. The add method is used to dynamically add settings items. The remove method is used to dynamically remove settings items. The update method is used to dynamically update settings items. The show property is used to set whether to display all settings items. The toggle method is used to toggle the display of all settings items.
-Run Code
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
@@ -356,11 +360,11 @@ art.on('ready', () => {
For the Settings Panel, please refer to: /component/setting.html
+Plugins
-plugins
Manages the player's plugin functionality, with only the add method for dynamically adding plugins.
-Run Code
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
@@ -382,14 +386,15 @@ art.on('ready', () => {
art.plugins.add(myPlugin);
});
-
Static Properties
+
Static Properties refer to the top-level properties mounted on the constructor function, which are very rarely used.
-instances
+Instances
+
Returns an array of all player instances. This property can be useful when you need to manage multiple player instances simultaneously.
-Run Code
+Example code:
console.info([...Artplayer.instances]);
@@ -400,103 +405,103 @@ var art = new Artplayer({
console.info([...Artplayer.instances]);
+Version
-version
Returns the version information of the player.
-Run Code
+Example code:
console.info(Artplayer.version);
+Env
-env
Returns the environment variables of the player.
-Run Code
+Example code:
console.info(Artplayer.env);
+Build
-build
Returns the build time of the player.
-Run Code
+Example code:
console.info(Artplayer.build);
+Config
-config
Returns the default configuration for videos.
-Run Code
+Example code:
console.info(Artplayer.config);
+Utils
-utils
Returns the collection of utility functions for the player.
-Run Code
+Example code:
console.info(Artplayer.utils);
-For all utility functions, please refer to: artplayer/types/utils.d.ts
+For all utility functions, please refer to the following address: artplayer/types/utils.d.ts
+Scheme
-scheme
Returns the validation schema for player options.
-Run Code
+Example code:
console.info(Artplayer.scheme);
-
Emitter
+
Returns the constructor function for the event emitter.
-Run Code
+Example code:
console.info(Artplayer.Emitter);
+Validator
-validator
Returns the validation function for options.
-Run Code
+Example code:
console.info(Artplayer.validator);
+KindOf
-kindOf
Returns the utility function for type detection.
-Run Code
+Example code:
console.info(Artplayer.kindOf);
+Html
-html
Returns the html string required by the player.
-Run Code
+Example code:
console.info(Artplayer.html);
+Option
-option
Returns the default options for the player.
-Run Code
+Example code:
console.info(Artplayer.option);
-
Instance Events
-Player events are divided into two types: native events (prefixed with 'video:') and custom events.
+
+Player events are divided into two types: native events (prefixed with video:) and custom events.
Listen to an event:
-Run Code
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
@@ -507,10 +512,9 @@ art.on('video:canplay', () => {
console.info('video:canplay');
});
-
Listen to an event only once:
-Run Code
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
@@ -521,10 +525,9 @@ art.once('video:canplay', () => {
console.info('video:canplay');
});
-
Manually trigger an event:
-Run Code
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
@@ -533,10 +536,9 @@ var art = new Artplayer({
art.emit('focus');
-
Remove an event listener:
-Run Code
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
@@ -552,11 +554,11 @@ art.on('ready', onReady);
For a complete list of events, please refer to: artplayer/types/events.d.ts
+Ready Event
-ready
Triggered when the player is ready for the first time.
-Run Code
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
@@ -567,11 +569,11 @@ art.on('ready', () => {
console.info('ready');
});
+Restart Event
-restart
Triggered when the player switches URL and becomes playable.
-Run Code
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
@@ -586,19 +588,12 @@ art.on('restart', (url) => {
console.info('restart', url);
});
-
-pause
-Triggered when the player is paused.
-
-Run Code
-
-ArtPlayer Event Documentation
-
-The following events can be used with ArtPlayer to handle various player interactions and state changes.
-
Pause Event
+
Triggered when the player is paused.
+Example code:
+
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -608,9 +603,27 @@ art.on('pause', () => {
console.info('pause');
});
-Play Event
+ArtPlayer Event Documentation
+
+The following events are available in ArtPlayer. Each event can be bound using the `art.on()` method. The basic player setup is consistent across examples.
+
+Event: pause
+Triggered when the player pauses.
+
+Example code:
+var art = new Artplayer({
+ container: '.artplayer-app',
+ url: '/assets/sample/video.mp4',
+});
+
+art.on('pause', () => {
+ console.info('pause');
+});
+
+Event: play
Triggered when the player starts playing.
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -620,9 +633,10 @@ art.on('play', () => {
console.info('play');
});
-Hotkey Event
-Triggered when a hotkey is pressed on the player. The event object contains details about the key pressed.
+Event: hotkey
+Triggered when a hotkey is pressed on the player. The event object contains details about the key press.
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -632,9 +646,10 @@ art.on('hotkey', (event) => {
console.info('hotkey', event);
});
-Destroy Event
-Triggered when the player is destroyed. This example shows how to destroy the player when it's ready.
+Event: destroy
+Triggered when the player instance is destroyed. This example shows destroying the player in the ready event handler.
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -648,9 +663,10 @@ art.on('destroy', () => {
console.info('destroy');
});
-Focus Event
-Triggered when the player gains focus.
+Event: focus
+Triggered when the player element gains focus.
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -660,9 +676,10 @@ art.on('focus', (event) => {
console.info('focus', event);
});
-Blur Event
-Triggered when the player loses focus.
+Event: blur
+Triggered when the player element loses focus.
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -672,9 +689,10 @@ art.on('blur', (event) => {
console.info('blur', event);
});
-Double Click Event
+Event: dblclick
Triggered when the player is double-clicked.
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -684,9 +702,10 @@ art.on('dblclick', (event) => {
console.info('dblclick', event);
});
-Click Event
+Event: click
Triggered when the player is clicked.
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -696,9 +715,10 @@ art.on('click', (event) => {
console.info('click', event);
});
-Error Event
-Triggered when an error occurs while loading the video. The example uses a non-existent video file to demonstrate.
+Event: error
+Triggered when an error occurs while loading the video. The callback provides the error and a reconnectTime parameter.
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/404.mp4',
@@ -708,9 +728,10 @@ art.on('error', (error, reconnectTime) => {
console.info(error, reconnectTime);
});
-Hover Event
-Triggered when the mouse enters or leaves the player. The state parameter indicates whether the mouse is entering or leaving.
+Event: hover
+Triggered when the mouse enters or leaves the player area. The state parameter indicates 'enter' or 'leave'.
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -720,9 +741,10 @@ art.on('hover', (state, event) => {
console.info('hover', state, event);
});
-Mouse Move Event
+Event: mousemove
Triggered when the mouse moves over the player.
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -732,9 +754,10 @@ art.on('mousemove', (event) => {
console.info('mousemove', event);
});
-Resize Event
-Triggered when the player's dimensions change.
+Event: resize
+Triggered when the player's container dimensions change.
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -744,9 +767,10 @@ art.on('resize', () => {
console.info('resize');
});
-View Event
-Triggered when the player enters or leaves the viewport.
+Event: view
+Triggered when the player enters or leaves the browser viewport. The state parameter indicates the visibility.
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -756,9 +780,10 @@ art.on('view', (state) => {
console.info('view', state);
});
-Lock Event
-Triggered when the lock state changes on mobile devices. Requires the lock option to be enabled.
+Event: lock
+Triggered when the screen lock state changes, primarily on mobile devices. Requires the lock option to be enabled.
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -769,9 +794,10 @@ art.on('lock', (state) => {
console.info('lock', state);
});
-Aspect Ratio Event
-Triggered when the player's aspect ratio changes. Requires both aspectRatio and setting options to be enabled.
+Event: aspectRatio
+Triggered when the player's aspect ratio changes. Requires the aspectRatio and setting options to be enabled.
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -783,9 +809,10 @@ art.on('aspectRatio', (aspectRatio) => {
console.info('aspectRatio', aspectRatio);
});
-Auto Height Event
-Triggered when the player automatically adjusts its height. The autoHeight method must be called.
+Event: autoHeight
+Triggered when the player automatically adjusts its height, typically after calling the art.autoHeight() method.
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -799,9 +826,10 @@ art.on('autoHeight', (height) => {
console.info('autoHeight', height);
});
-Auto Size Event
+Event: autoSize
Triggered when the player automatically adjusts its size. Requires the autoSize option to be enabled.
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -812,9 +840,10 @@ art.on('autoSize', () => {
console.info('autoSize');
});
-Flip Event
-Triggered when the player is flipped. Requires both flip and setting options to be enabled.
+Event: flip
+Triggered when the video flip state changes. Requires the flip and setting options to be enabled.
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -826,9 +855,10 @@ art.on('flip', (flip) => {
console.info('flip', flip);
});
-Fullscreen Event
-Triggered when the player enters or exits window fullscreen mode. Requires the fullscreen option to be enabled.
+Event: fullscreen
+Triggered when the player enters or exits traditional window fullscreen mode. Requires the fullscreen option.
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -839,9 +869,10 @@ art.on('fullscreen', (state) => {
console.info('fullscreen', state);
});
-Fullscreen Error Event
-Triggered when a window fullscreen error occurs. This example attempts to enable fullscreen programmatically.
+Event: fullscreenError
+Triggered when an error occurs while attempting to enter window fullscreen mode.
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -855,9 +886,10 @@ art.on('fullscreenError', (event) => {
console.info('fullscreenError', event);
});
-Fullscreen Web Event
-Triggered when the player enters or exits web fullscreen mode. Requires the fullscreenWeb option to be enabled.
+Event: fullscreenWeb
+Triggered when the player enters or exits web fullscreen mode (fullscreen within the browser). Requires the fullscreenWeb option.
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -868,9 +900,10 @@ art.on('fullscreenWeb', (state) => {
console.info('fullscreenWeb', state);
});
-Mini Event
-Triggered when the player enters or exits mini mode. The mini property must be set to true.
+Event: mini
+Triggered when the player enters or exits mini-player mode.
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -884,9 +917,10 @@ art.on('mini', (state) => {
console.info('mini', state);
});
-Picture-in-Picture Event
-Triggered when the player enters or exits picture-in-picture mode. Requires the pip option to be enabled.
+Event: pip
+Triggered when the player enters or exits picture-in-picture mode. Requires the pip option.
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -897,9 +931,10 @@ art.on('pip', (state) => {
console.info('pip', state);
});
-Screenshot Event
-Triggered when the player captures a screenshot. Requires the screenshot option to be enabled.
+Event: screenshot
+Triggered when a screenshot is captured. Requires the screenshot option. The callback receives the image as a Data URI.
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -910,9 +945,10 @@ art.on('screenshot', (dataUri) => {
console.info('screenshot', dataUri);
});
-Seek Event
-Triggered when the player performs a time seek.
+Event: seek
+Triggered when the playback time is sought, either by dragging the progress bar or calling a method.
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -922,9 +958,10 @@ art.on('seek', (currentTime) => {
console.info('seek', currentTime);
});
-Subtitle Offset Event
-Triggered when subtitle offset changes in the player. Requires subtitleOffset and setting options to be enabled, plus a subtitle URL.
+Event: subtitleOffset
+Triggered when the subtitle synchronization offset is changed. Requires the subtitleOffset option and a subtitle track.
+Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -935,18 +972,23 @@ var art = new Artplayer({
setting: true,
});
-subtitleOffset
+ArtPlayer Event: subtitleOffset
-This event is triggered when the subtitle offset changes.
+Triggered when the subtitle offset changes.
+
+Example usage:
art.on('subtitleOffset', (offset) => {
console.info('subtitleOffset', offset);
});
-subtitleBeforeUpdate
+
+ArtPlayer Event: subtitleBeforeUpdate
Triggered before subtitles are updated.
+Example usage:
+
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -959,10 +1001,13 @@ art.on('subtitleBeforeUpdate', (cues) => {
console.info('subtitleBeforeUpdate', cues);
});
-subtitleAfterUpdate
+
+ArtPlayer Event: subtitleAfterUpdate
Triggered after subtitles are updated.
+Example usage:
+
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -975,10 +1020,13 @@ art.on('subtitleAfterUpdate', (cues) => {
console.info('subtitleAfterUpdate', cues);
});
-subtitleLoad
+
+ArtPlayer Event: subtitleLoad
Triggered when subtitles are loaded.
+Example usage:
+
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -991,10 +1039,13 @@ art.on('subtitleLoad', (option, cues) => {
console.info('subtitleLoad', cues, option);
});
-info
+
+ArtPlayer Event: info
Triggered when the info panel is shown or hidden.
+Example usage:
+
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1004,10 +1055,13 @@ art.on('info', (state) => {
console.log(state);
});
-layer
+
+ArtPlayer Event: layer
Triggered when custom layers are shown or hidden.
+Example usage:
+
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1017,10 +1071,13 @@ art.on('layer', (state) => {
console.log(state);
});
-loading
+
+ArtPlayer Event: loading
Triggered when the loader is shown or hidden.
+Example usage:
+
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1030,10 +1087,13 @@ art.on('loading', (state) => {
console.log(state);
});
-mask
+
+ArtPlayer Event: mask
Triggered when the mask layer is shown or hidden.
+Example usage:
+
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1043,10 +1103,13 @@ art.on('mask', (state) => {
console.log(state);
});
-subtitle
+
+ArtPlayer Event: subtitle
Triggered when the subtitle layer is shown or hidden.
+Example usage:
+
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1056,10 +1119,13 @@ art.on('subtitle', (state) => {
console.log(state);
});
-contextmenu
+
+ArtPlayer Event: contextmenu
Triggered when the context menu is shown or hidden.
+Example usage:
+
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1069,10 +1135,13 @@ art.on('contextmenu', (state) => {
console.log(state);
});
-control
+
+ArtPlayer Event: control
Triggered when the controls are shown or hidden.
+Example usage:
+
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1082,10 +1151,13 @@ art.on('control', (state) => {
console.log(state);
});
-setting
+
+ArtPlayer Event: setting
Triggered when the settings panel is shown or hidden.
+Example usage:
+
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1096,10 +1168,13 @@ art.on('setting', (state) => {
console.log(state);
});
-muted
+
+ArtPlayer Event: muted
Triggered when the mute state changes.
+Example usage:
+
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1109,10 +1184,13 @@ art.on('muted', (state) => {
console.log(state);
});
-keydown
+
+ArtPlayer Event: keydown
Listens for keydown events from the document.
+Example usage:
+
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1122,7 +1200,10 @@ art.on('keydown', (event) => {
console.log(event.code);
});
-Video Events
+
+Video Element Events
+
+The following are standard HTML5 video events that ArtPlayer can listen to.
video:canplay - The browser can start playing the media, but estimates there isn't enough data to play through to the end without having to stop for further buffering.
@@ -1166,13 +1247,14 @@ video:volumechange - The volume has changed.
video:waiting - Playback has stopped due to temporary lack of data.
+
Global Properties
These global properties refer to the top-level properties mounted on the constructor. The property names are all in uppercase. They are subject to change in the future and are generally not used.
-DEBUG
+DEBUG - Whether to enable debug mode, which can print all built-in events of the video. Default is off.
-Whether to enable debug mode, which can print all built-in events of the video. Default is off.
+Example usage:
Artplayer.DEBUG = true;
@@ -1181,15 +1263,17 @@ var art = new Artplayer({
url: '/assets/sample/video.mp4',
});
-STYLE
-Returns the player style text.
+STYLE - Returns the player style text.
+
+Example usage:
console.log(Artplayer.STYLE);
-CONTEXTMENU
-Whether to enable the context menu. Default is on.
+CONTEXTMENU - Whether to enable the context menu. Default is on.
+
+Example usage:
Artplayer.CONTEXTMENU = false;
@@ -1198,9 +1282,10 @@ var art = new Artplayer({
url: '/assets/sample/video.mp4',
});
-NOTICE_TIME
-The display duration for notification messages, in milliseconds. Default is 2000.
+NOTICE_TIME - The display duration for notification messages, in milliseconds. Default is 2000.
+
+Example usage:
Artplayer.NOTICE_TIME = 5000;
@@ -1209,9 +1294,10 @@ var art = new Artplayer({
url: '/assets/sample/video.mp4',
});
-SETTING_WIDTH
-The default width of the settings panel, in pixels. Default is 250.
+SETTING_WIDTH - The default width of the settings panel, in pixels. Default is 250.
+
+Example usage:
Artplayer.SETTING_WIDTH = 300;
@@ -1225,9 +1311,10 @@ var art = new Artplayer({
aspectRatio: true,
});
-SETTING_ITEM_WIDTH
-The default width of settings items in the settings panel, in pixels. Default is 200.
+SETTING_ITEM_WIDTH - The default width of settings items in the settings panel, in pixels. Default is 200.
+
+Example usage:
Artplayer.SETTING_ITEM_WIDTH = 300;
@@ -1241,9 +1328,29 @@ var art = new Artplayer({
aspectRatio: true,
});
+
+SETTING_ITEM_HEIGHT - The default height of settings items in the settings panel, in pixels. Default is 35.
+
+Example usage:
+
+Artplayer.SETTING_ITEM_HEIGHT = 300;
+
+var art = new Artplayer({
+ container: '.artplayer-app',
+ url: '/assets/sample/video.mp4',
+ setting: true,
+ loop: true,
+ flip: true,
+ playbackRate: true,
+ aspectRatio: true,
+});
+
+ArtPlayer provides several static properties that allow you to customize its behavior. These can be set before creating a new player instance.
+
SETTING_ITEM_HEIGHT
+The height of each item in the settings panel, in pixels. The default is 40.
-The default height of settings items in the settings panel, in pixels. Default is 35.
+Example of setting a custom height and initializing a player with various settings enabled:
Artplayer.SETTING_ITEM_HEIGHT = 40;
@@ -1257,21 +1364,10 @@ var art = new Artplayer({
aspectRatio: true,
});
-To configure the height of setting menu items, set the SETTING_ITEM_HEIGHT property. The default value is 40 pixels.
+RESIZE_TIME
+The throttle time for the resize event, in milliseconds. The default is 200.
-Artplayer.SETTING_ITEM_HEIGHT = 40;
-
-var art = new Artplayer({
- container: '.artplayer-app',
- url: '/assets/sample/video.mp4',
- setting: true,
- loop: true,
- flip: true,
- playbackRate: true,
- aspectRatio: true,
-});
-
-RESIZE_TIME controls the throttle time for resize events in milliseconds. The default is 200.
+Example of setting a custom throttle time and listening for the resize event:
Artplayer.RESIZE_TIME = 500;
@@ -1284,7 +1380,10 @@ art.on('resize', () => {
console.log('resize');
});
-SCROLL_TIME sets the throttle time for scroll events in milliseconds. The default is 200.
+SCROLL_TIME
+The throttle time for the scroll event, in milliseconds. The default is 200.
+
+Example of setting a custom throttle time and listening for the scroll event:
Artplayer.SCROLL_TIME = 500;
@@ -1297,7 +1396,10 @@ art.on('scroll', () => {
console.log('scroll');
});
-SCROLL_GAP defines the boundary tolerance distance for view events in pixels. The default is 50.
+SCROLL_GAP
+The boundary tolerance distance for the view event, in pixels. The default is 50.
+
+Example of setting a custom gap and listening for the scroll event:
Artplayer.SCROLL_GAP = 100;
@@ -1310,7 +1412,10 @@ art.on('scroll', () => {
console.log('scroll');
});
-AUTO_PLAYBACK_MAX specifies the maximum record count for auto-playback. The default is 10.
+AUTO_PLAYBACK_MAX
+The maximum record count for the auto-playback feature. The default is 10.
+
+Example of setting a custom maximum and enabling auto-playback:
Artplayer.AUTO_PLAYBACK_MAX = 20;
@@ -1320,7 +1425,10 @@ var art = new Artplayer({
autoPlayback: true,
});
-AUTO_PLAYBACK_MIN sets the minimum record duration for auto-playback in seconds. The default is 5.
+AUTO_PLAYBACK_MIN
+The minimum record duration for the auto-playback feature, in seconds. The default is 5.
+
+Example of setting a custom minimum duration and enabling auto-playback:
Artplayer.AUTO_PLAYBACK_MIN = 10;
@@ -1330,7 +1438,10 @@ var art = new Artplayer({
autoPlayback: true,
});
-AUTO_PLAYBACK_TIMEOUT controls the hide delay duration for auto-playback in milliseconds. The default is 3000.
+AUTO_PLAYBACK_TIMEOUT
+The hide delay duration for the auto-playback feature, in milliseconds. The default is 3000.
+
+Example of setting a custom timeout and enabling auto-playback:
Artplayer.AUTO_PLAYBACK_TIMEOUT = 5000;
@@ -1340,7 +1451,10 @@ var art = new Artplayer({
autoPlayback: true,
});
-RECONNECT_TIME_MAX defines the maximum number of automatic reconnection attempts. The default is 5.
+RECONNECT_TIME_MAX
+The maximum number of automatic reconnection attempts when a connection error occurs. The default is 5.
+
+Example of setting a custom maximum reconnection count:
Artplayer.RECONNECT_TIME_MAX = 10;
@@ -1349,7 +1463,10 @@ var art = new Artplayer({
url: '/assets/sample/404.mp4',
});
-RECONNECT_SLEEP_TIME sets the delay time for automatic reconnection in milliseconds. The default is 1000.
+RECONNECT_SLEEP_TIME
+The delay time for automatic reconnection when a connection error occurs, in milliseconds. The default is 1000.
+
+Example of setting a custom reconnection delay:
Artplayer.RECONNECT_SLEEP_TIME = 3000;
@@ -1358,7 +1475,10 @@ var art = new Artplayer({
url: '/assets/sample/404.mp4',
});
-CONTROL_HIDE_TIME determines the delay time for auto-hiding the bottom control bar in milliseconds. The default is 3000.
+CONTROL_HIDE_TIME
+The delay time in milliseconds for auto-hiding the bottom control bar. The default is 3000.
+
+Example of setting a custom control hide delay:
Artplayer.CONTROL_HIDE_TIME = 5000;
@@ -1367,7 +1487,10 @@ var art = new Artplayer({
url: '/assets/sample/video.mp4',
});
-DBCLICK_TIME sets the delay time for double-click events in milliseconds. The default is 300.
+DBCLICK_TIME
+The delay time in milliseconds for double-click events. The default is 300.
+
+Example of setting a custom double-click delay and listening for the event:
Artplayer.DBCLICK_TIME = 500;
@@ -1380,7 +1503,10 @@ art.on('dblclick', () => {
console.log('dblclick');
});
-DBCLICK_FULLSCREEN controls whether double-click toggles fullscreen on desktop. The default is true.
+DBCLICK_FULLSCREEN
+On desktop, determines whether double-click toggles fullscreen mode. The default is true.
+
+Example of disabling double-click fullscreen:
Artplayer.DBCLICK_FULLSCREEN = false;
@@ -1389,7 +1515,10 @@ var art = new Artplayer({
url: '/assets/sample/video.mp4',
});
-MOBILE_DBCLICK_PLAY determines whether double-click toggles play/pause on mobile devices. The default is true.
+MOBILE_DBCLICK_PLAY
+On mobile devices, determines whether double-click toggles play/pause. The default is true.
+
+Example of disabling double-click play/pause on mobile:
Artplayer.MOBILE_DBCLICK_PLAY = false;
@@ -1398,7 +1527,10 @@ var art = new Artplayer({
url: '/assets/sample/video.mp4',
});
-MOBILE_CLICK_PLAY controls whether single-click toggles play/pause on mobile devices. The default is false.
+MOBILE_CLICK_PLAY
+On mobile devices, determines whether single-click toggles play/pause. The default is false.
+
+Example of enabling single-click play/pause on mobile:
Artplayer.MOBILE_CLICK_PLAY = true;
@@ -1407,7 +1539,10 @@ var art = new Artplayer({
url: '/assets/sample/video.mp4',
});
-AUTO_ORIENTATION_TIME sets the delay time for automatic screen rotation on mobile devices in milliseconds. The default is 200.
+AUTO_ORIENTATION_TIME
+On mobile devices, the delay time in milliseconds for automatic screen rotation. The default is 200.
+
+Example of setting a custom orientation delay and enabling auto-orientation:
Artplayer.AUTO_ORIENTATION_TIME = 500;
@@ -1417,7 +1552,10 @@ var art = new Artplayer({
autoOrientation: true,
});
-INFO_LOOP_TIME defines the refresh interval for the information panel in milliseconds. The default is 1000.
+INFO_LOOP_TIME
+The refresh interval in milliseconds for the information panel. The default is 1000.
+
+Example of setting a custom refresh interval and showing the info panel:
Artplayer.INFO_LOOP_TIME = 2000;
@@ -1428,7 +1566,10 @@ var art = new Artplayer({
art.info.show = true;
-FAST_FORWARD_VALUE sets the speed multiplier for fast-forward during long-press on mobile devices. The default is 3.
+FAST_FORWARD_VALUE
+On mobile devices, the speed multiplier for fast-forward during long-press. The default is 3.
+
+Example of setting a custom fast-forward speed and enabling the feature:
Artplayer.FAST_FORWARD_VALUE = 5;
@@ -1438,7 +1579,10 @@ var art = new Artplayer({
fastForward: true,
});
-FAST_FORWARD_TIME controls the delay time for activating fast-forward during long-press on mobile devices in milliseconds. The default is 1000.
+FAST_FORWARD_TIME
+On mobile devices, the delay time in milliseconds for activating fast-forward during long-press. The default is 1000.
+
+Example of setting a custom activation delay and enabling fast-forward:
Artplayer.FAST_FORWARD_TIME = 2000;
@@ -1448,7 +1592,10 @@ var art = new Artplayer({
fastForward: true,
});
-TOUCH_MOVE_RATIO sets the speed multiplier for seeking when swiping left/right on mobile devices. The default is 0.5.
+TOUCH_MOVE_RATIO
+On mobile devices, the speed multiplier for seeking when swiping left/right. The default is 0.5.
+
+Example of setting a custom seek sensitivity:
Artplayer.TOUCH_MOVE_RATIO = 1;
@@ -1457,7 +1604,10 @@ var art = new Artplayer({
url: '/assets/sample/video.mp4',
});
-VOLUME_STEP defines the volume adjustment step for keyboard shortcuts. The default is 0.1.
+VOLUME_STEP
+The volume adjustment step for keyboard shortcuts. The default is 0.1.
+
+Example of setting a custom volume step:
Artplayer.VOLUME_STEP = 0.2;
@@ -1466,7 +1616,10 @@ var art = new Artplayer({
url: '/assets/sample/video.mp4',
});
-SEEK_STEP sets the seeking step in seconds for keyboard shortcuts. The default is 5.
+SEEK_STEP
+The seeking step in seconds for keyboard shortcuts. The default is 5.
+
+Example of setting a custom seek step:
Artplayer.SEEK_STEP = 10;
@@ -1475,7 +1628,10 @@ var art = new Artplayer({
url: '/assets/sample/video.mp4',
});
-PLAYBACK_RATE contains the built-in list of playback rates. The default is [0.5, 0.75, 1, 1.25, 1.5, 2].
+PLAYBACK_RATE
+The built-in list of playback rates. The default is [0.5, 0.75, 1, 1.25, 1.5, 2].
+
+Example of setting a custom playback rate list and enabling the feature in settings:
Artplayer.PLAYBACK_RATE = [0.5, 1, 2, 3, 4, 5];
@@ -1489,7 +1645,10 @@ var art = new Artplayer({
art.contextmenu.show = true;
art.setting.show = true;
-ASPECT_RATIO contains the built-in list of video aspect ratios. The default is ['default', '4:3', '16:9'].
+ASPECT_RATIO
+The built-in list of video aspect ratios. The default is ['default', '4:3', '16:9'].
+
+Example of setting a custom aspect ratio list and enabling the feature in settings:
Artplayer.ASPECT_RATIO = ['default', '1:1', '2:1', '4:3', '6:5'];
@@ -1503,7 +1662,10 @@ var art = new Artplayer({
art.contextmenu.show = true;
art.setting.show = true;
-FLIP contains the built-in list of video flip modes. The default is ['normal', 'horizontal', 'vertical'].
+FLIP
+The built-in list of video flip modes. The default is ['normal', 'horizontal', 'vertical'].
+
+Example of setting a custom flip mode list and enabling the feature in settings:
Artplayer.FLIP = ['normal', 'horizontal'];
@@ -1517,14 +1679,26 @@ var art = new Artplayer({
art.contextmenu.show = true;
art.setting.show = true;
-FULLSCREEN_WEB_IN_BODY determines whether to mount the player under the body element during web fullscreen mode. The default is true.
+FULLSCREEN_WEB_IN_BODY
+Determines whether to mount the player under the body element during web fullscreen mode. The default is true.
-ArtPlayer Documentation
+Example of setting this property:
+
+Artplayer.FULLSCREEN_WEB_IN_BODY = false;
+
+var art = new Artplayer({
+ container: '.artplayer-app',
+ url: '/assets/sample/video.mp4',
+});
+
+ArtPlayer Global Configuration
FULLSCREEN_WEB_IN_BODY
-This setting determines whether fullscreen mode places the player within the body element. The default value is false.
-Example code:
+This setting determines whether fullscreen mode is applied to the entire web page body. By default, it is set to false.
+
+Example:
+
Artplayer.FULLSCREEN_WEB_IN_BODY = false;
var art = new Artplayer({
@@ -1534,9 +1708,11 @@ var art = new Artplayer({
});
LOG_VERSION
-Controls whether the player version is printed to console. The default is true.
-Example code:
+Sets whether to print the player version in the console. The default value is true.
+
+Example:
+
Artplayer.LOG_VERSION = false;
var art = new Artplayer({
@@ -1545,9 +1721,11 @@ var art = new Artplayer({
});
USE_RAF
-Enables or disables requestAnimationFrame usage. Defaults to false. Primarily used for smoother progress bar animations.
-Example code:
+Sets whether to use requestAnimationFrame for smoother animations, such as the progress bar. The default value is false.
+
+Example:
+
Artplayer.USE_RAF = true;
var art = new Artplayer({
@@ -1557,9 +1735,11 @@ var art = new Artplayer({
});
REMOVE_SRC_WHEN_DESTROY
-Determines if video source is removed and load() is called when destroying the player. Defaults to true. This helps reduce resource usage in single-page applications with frequent player creation/destruction. Set to false if you want to preserve video element state while only removing the UI.
-Example code:
+Determines whether to remove the video's src attribute and call load() to release media resources when the player is destroyed. The default is true. Set this to false if you want to preserve the video element's state and only remove the UI.
+
+Example:
+
Artplayer.REMOVE_SRC_WHEN_DESTROY = false;
var art = new Artplayer({
@@ -1572,9 +1752,9 @@ art.destroy();
Writing Plugins
-Once you understand the player's properties, methods, and events, creating plugins is straightforward.
+Once you are familiar with the player's properties, methods, and events, writing plugins is straightforward. You can load plugins during player instantiation or add them afterward.
-You can load plugins during player instantiation:
+Loading a plugin during instantiation:
function myPlugin(art) {
console.info(art);
@@ -1597,7 +1777,7 @@ art.on('ready', () => {
console.info(art.plugins.myPlugin);
});
-You can also add plugins after instantiation:
+Loading a plugin after instantiation:
function myPlugin(art) {
console.info(art);
@@ -1621,7 +1801,9 @@ art.on('ready', () => {
console.info(art.plugins.myPlugin);
});
-Here's an example plugin that shows an image ad when video is paused:
+Example Plugin: Displaying an Image Ad on Pause
+
+This plugin shows an image ad when the video is paused and provides controls to hide or show it.
function adsPlugin(option) {
return (art) => {
@@ -1686,13 +1868,15 @@ var art = new Artplayer({
Instance Properties
-These are first-level properties mounted on the player instance that are commonly used.
+These are first-level properties available on the player instance.
play
-Type: Function
-Starts video playback.
-Example code:
+Type: Function
+Plays the video.
+
+Example:
+
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1704,10 +1888,12 @@ art.on('ready', () => {
});
pause
-Type: Function
-Pauses video playback.
-Example code:
+Type: Function
+Pauses the video.
+
+Example:
+
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1723,10 +1909,12 @@ art.on('ready', () => {
});
toggle
-Type: Function
-Toggles between play and pause states.
-Example code:
+Type: Function
+Toggles between play and pause.
+
+Example:
+
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1742,11 +1930,13 @@ art.on('ready', () => {
});
destroy
+
Type: Function
Parameter: Boolean
-Destroys the player. Accepts a boolean parameter indicating whether to remove the player's HTML after destruction. Defaults to true.
+Destroys the player. Accepts a boolean parameter indicating whether to remove the player's HTML from the DOM after destruction. Defaults to true.
+
+Example:
-Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1757,12 +1947,12 @@ art.on('ready', () => {
});
reset
+
Type: Function
-Resets the video element by removing current source and calling load(). Useful for manually releasing media resources or reinitializing video tags in single-page applications.
+Resets the player's video element by removing the current src and calling load(). Useful for manually releasing media resources or reinitializing the video tag in single-page applications. Note: The global configuration Artplayer.REMOVE_SRC_WHEN_DESTROY also triggers similar logic when destroy() is called.
-Note: The global configuration Artplayer.REMOVE_SRC_WHEN_DESTROY automatically executes similar logic when destroy() is called.
+Example:
-Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1774,11 +1964,13 @@ art.on('ready', () => {
});
seek
+
Type: Setter
Parameter: Number
-Seeks to a specific time in the video, specified in seconds.
+Seeks to a specific time in the video, in seconds.
+
+Example:
-Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1789,11 +1981,13 @@ art.on('ready', () => {
});
forward
+
Type: Setter
Parameter: Number
-Fast forwards the video by specified number of seconds.
+Fast-forwards the video by a specified number of seconds.
+
+Example:
-Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1804,11 +1998,13 @@ art.on('ready', () => {
});
backward
+
Type: Setter
Parameter: Number
-Rewinds the video by specified number of seconds.
+Rewinds the video by a specified number of seconds.
+
+Example:
-Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1823,11 +2019,13 @@ art.on('ready', () => {
});
volume
+
Type: Setter/Getter
Parameter: Number
-Sets and gets the video volume. Accepts values between 0 and 1.
+Sets or gets the video volume. The value must be between 0 and 1.
+
+Example:
-Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1840,11 +2038,13 @@ art.on('ready', () => {
});
url
+
Type: Setter/Getter
Parameter: String
-Sets and gets the video URL.
+Sets or gets the video URL.
+
+Example:
-Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1852,21 +2052,21 @@ var art = new Artplayer({
ArtPlayer Documentation
-Ready Event Example
-The following code demonstrates how to set the video URL when the player is ready:
+The following sections describe various properties and methods available on an ArtPlayer instance.
+Setting the video URL directly.
+
+Example:
art.on('ready', () => {
art.url = '/assets/sample/video.mp4?t=0';
});
-Switch Property
+Property: switch
Type: Setter
Parameter: String
+Description: Sets the video URL. Similar to `art.url` when setting, but performs some optimization operations.
-Sets the video URL. Similar to art.url when setting, but performs some optimization operations.
-
-Example showing how to switch video source after 3 seconds:
-
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1879,14 +2079,12 @@ art.on('ready', () => {
}, 3000);
});
-SwitchUrl Function
+Method: switchUrl
Type: Function
Parameter: String
+Description: Sets the video URL. Similar to `art.url` when setting, but performs some optimization operations.
-Sets the video URL. Similar to art.url when setting, but performs some optimization operations.
-
-Example showing how to switch video source using the function method:
-
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1899,16 +2097,14 @@ art.on('ready', () => {
}, 3000);
});
-Note: art.switch and art.switchUrl have the same functionality, but the art.switchUrl method returns a Promise. It resolves when the new URL is playable and rejects when the new URL fails to load.
+Note: `art.switch` and `art.switchUrl` have the same functionality, but the `art.switchUrl` method returns a `Promise`. It `resolve`s when the new URL is playable and `reject`s when the new URL fails to load.
-SwitchQuality Function
+Method: switchQuality
Type: Function
Parameter: String
+Description: Sets the video quality URL. Similar to `art.switchUrl`, but retains the previous playback progress.
-Sets the video quality URL. Similar to art.switchUrl, but retains the previous playback progress.
-
-Example showing quality switching:
-
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1921,14 +2117,12 @@ art.on('ready', () => {
}, 3000);
});
-Muted Property
+Property: muted
Type: Setter/Getter
Parameter: Boolean
+Description: Sets and gets whether the video is muted.
-Sets and gets whether the video is muted.
-
-Example showing how to check and set muted state:
-
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1940,14 +2134,12 @@ art.on('ready', () => {
console.info(art.muted);
});
-CurrentTime Property
+Property: currentTime
Type: Setter/Getter
Parameter: Number
+Description: Sets and gets the current playback time of the video. Setting the time is similar to `seek`, but it does not trigger additional events.
-Sets and gets the current playback time of the video. Setting the time is similar to seek, but it does not trigger additional events.
-
-Example showing how to get and set current time:
-
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1959,13 +2151,11 @@ art.on('ready', () => {
console.info(art.currentTime);
});
-Duration Property
+Property: duration
Type: Getter
+Description: Gets the duration of the video.
-Gets the duration of the video.
-
-Example showing how to get video duration:
-
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1975,15 +2165,13 @@ art.on('ready', () => {
console.info(art.duration);
});
-Note: Some videos may not have a duration, such as live streams or videos that have not been fully decoded. In these cases, the obtained duration will be 0.
+Note: Some videos may not have a duration, such as live streams or videos that have not been fully decoded. In these cases, the obtained duration will be `0`.
-Screenshot Function
+Method: screenshot
Type: Function
+Description: Downloads a screenshot of the current video frame. An optional parameter specifies the screenshot filename.
-Downloads a screenshot of the current video frame. An optional parameter specifies the screenshot filename.
-
-Example showing how to take a screenshot:
-
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -1993,13 +2181,11 @@ art.on('ready', () => {
art.screenshot('your-name');
});
-GetDataURL Function
+Method: getDataURL
Type: Function
+Description: Gets the `base64` URL of a screenshot of the current video frame. Returns a `Promise`.
-Gets the base64 URL of a screenshot of the current video frame. Returns a Promise.
-
-Example showing how to get screenshot as data URL:
-
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2010,13 +2196,11 @@ art.on('ready', async () => {
console.info(url)
});
-GetBlobUrl Function
+Method: getBlobUrl
Type: Function
+Description: Gets the `blob` URL of a screenshot of the current video frame. Returns a `Promise`.
-Gets the blob URL of a screenshot of the current video frame. Returns a Promise.
-
-Example showing how to get screenshot as blob URL:
-
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2027,14 +2211,12 @@ art.on('ready', async () => {
console.info(url);
});
-Fullscreen Property
+Property: fullscreen
Type: Setter/Getter
Parameter: Boolean
+Description: Sets and gets the player's window fullscreen state.
-Sets and gets the player's window fullscreen state.
-
-Example showing fullscreen toggle in controls:
-
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2051,14 +2233,12 @@ var art = new Artplayer({
Note: Due to browser security mechanisms, the page must have prior user interaction (e.g., the user has clicked on the page) before triggering window fullscreen.
-FullscreenWeb Property
+Property: fullscreenWeb
Type: Setter/Getter
Parameter: Boolean
+Description: Sets and gets the player's web page fullscreen state.
-Sets and gets the player's web page fullscreen state.
-
-Example showing web fullscreen usage:
-
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2073,14 +2253,12 @@ art.on('ready', () => {
}, 3000);
});
-Pip Property
+Property: pip
Type: Setter/Getter
Parameter: Boolean
+Description: Sets and gets the player's Picture-in-Picture mode.
-Sets and gets the player's Picture-in-Picture mode.
-
-Example showing PIP toggle in controls:
-
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2097,14 +2275,12 @@ var art = new Artplayer({
Note: Due to browser security mechanisms, the page must have prior user interaction (e.g., the user has clicked on the page) before triggering Picture-in-Picture.
-Poster Property
+Property: poster
Type: Setter/Getter
Parameter: String
+Description: Sets and gets the video poster. The poster effect is only visible before video playback starts.
-Sets and gets the video poster. The poster effect is only visible before video playback starts.
-
-Example showing poster usage:
-
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2117,14 +2293,12 @@ art.on('ready', () => {
console.info(art.poster);
});
-Mini Property
+Property: mini
Type: Setter/Getter
Parameter: Boolean
+Description: Sets and gets the player's mini mode.
-Sets and gets the player's mini mode.
-
-Example showing mini mode activation:
-
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2134,14 +2308,12 @@ art.on('ready', () => {
art.mini = true;
});
-Playing Property
+Property: playing
Type: Getter
Parameter: Boolean
+Description: Gets whether the video is currently playing.
-Gets whether the video is currently playing.
-
-Example showing how to check playing status:
-
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2152,14 +2324,12 @@ art.on('ready', () => {
console.info(art.playing);
});
-State Property
+Property: state
Type: Setter/Getter
Parameter: String
+Description: Gets or sets the player's current state. Supported values: `standard` (normal), `mini` (mini window), `pip` (picture-in-picture), `fullscreen` (fullscreen window), `fullscreenWeb` (webpage fullscreen).
-Gets or sets the player's current state. Supported values: standard (normal), mini (mini window), pip (picture-in-picture), fullscreen (fullscreen window), fullscreenWeb (webpage fullscreen).
-
-Example showing state usage:
-
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2170,13 +2340,11 @@ art.on('ready', () => {
art.state = 'mini';
});
-AutoSize Function
+Method: autoSize
Type: Function
+Description: Sets whether the video adapts its size automatically.
-Sets whether the video adapts its size automatically.
-
-Example showing autoSize usage:
-
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2186,25 +2354,20 @@ art.on('ready', () => {
art.autoSize();
});
-Rect Property
+Property: rect
Type: Getter
+Description: Gets the player's dimensions and coordinate information.
-Gets the player's dimensions and coordinate information.
-
-Example showing rect usage:
-
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
-art.on('ready', () => {
- console.info(art.rect);
-});
+Here is the documentation reorganized into a clean, plain text format.
-To initialize an ArtPlayer instance, create a new object with the container and video URL specified. The following example demonstrates setting up the player and logging its dimensions and position once it's ready.
+First, an example of how to access the player's rect property, which contains its dimensions and coordinates. The information is obtained via getBoundingClientRect.
-Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2214,14 +2377,8 @@ art.on('ready', () => {
console.info(JSON.stringify(art.rect));
});
-Note: The dimension and coordinate information is obtained via getBoundingClientRect.
+The following properties are getters that provide shortcut access to the rect object. bottom, top, left, right, x, and y correspond to the fields of the same name in a DOMRect. width and height represent the player's current visible width and height.
-Properties: bottom, top, left, right, x, y, width, height
-Type: Getter
-
-These properties provide shortcut access to the rect object. bottom, top, left, right, x, and y correspond to the fields of the same name in DOMRect. width and height represent the player's current visible width and height.
-
-Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2231,13 +2388,8 @@ art.on('ready', () => {
console.info(art.width, art.height, art.left, art.top);
});
-Property: flip
-Type: Setter/Getter
-Parameter: String
+The flip property is both a setter and a getter. It controls the player's flip state and accepts a string parameter. Supported values are normal, horizontal, and vertical.
-Sets and gets the player flip state. Supported values are normal, horizontal, and vertical.
-
-Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2249,13 +2401,8 @@ art.on('ready', () => {
console.info(art.flip);
});
-Property: playbackRate
-Type: Setter/Getter
-Parameter: Number
+The playbackRate property is a setter and getter for the player's playback speed. It accepts a number parameter.
-Sets and gets the player's playback rate.
-
-Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2267,13 +2414,8 @@ art.on('ready', () => {
console.info(art.playbackRate);
});
-Property: aspectRatio
-Type: Setter/Getter
-Parameter: String
+The aspectRatio property is a setter and getter for the player's aspect ratio. It accepts a string parameter.
-Sets and gets the player's aspect ratio.
-
-Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2285,12 +2427,8 @@ art.on('ready', () => {
console.info(art.aspectRatio);
});
-Property: autoHeight
-Type: Function
+The autoHeight function is useful when your container has a defined width but an unknown height. It automatically calculates and sets the video height. You need to determine the appropriate timing to call this function.
-When the container only has a defined width, this property can automatically calculate and set the video height.
-
-Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2304,15 +2442,8 @@ art.on('resize', () => {
art.autoHeight();
});
-Note: This property is useful when your container has only a defined width but an unknown height. It automatically calculates the video height, but you need to determine the appropriate timing to set this property.
+The attr function dynamically gets and sets attributes of the video element. It accepts a string parameter for the attribute name.
-Property: attr
-Type: Function
-Parameter: String
-
-Dynamically gets and sets attributes of the video element.
-
-Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2324,13 +2455,8 @@ art.on('ready', () => {
console.info(art.attr('playsInline'));
});
-Property: type
-Type: Setter/Getter
-Parameter: String
+The type property is a setter and getter for the video type. It accepts a string parameter.
-Dynamically gets and sets the video type.
-
-Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2342,13 +2468,8 @@ art.on('ready', () => {
console.info(art.type);
});
-Property: theme
-Type: Setter/Getter
-Parameter: String
+The theme property is a setter and getter for the player's theme color. It accepts a string parameter.
-Dynamically gets and sets the player's theme color.
-
-Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2360,12 +2481,8 @@ art.on('ready', () => {
console.info(art.theme);
});
-Property: airplay
-Type: Function
+The airplay function initiates AirPlay.
-Initiates AirPlay.
-
-Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2380,12 +2497,8 @@ var art = new Artplayer({
],
});
-Property: loaded
-Type: Getter
+The loaded property is a getter that returns the proportion of the video that has been buffered, ranging from 0 to 1. It is often used with the video:timeupdate event.
-The proportion of the video that has been buffered, ranging from 0 to 1. Often used with the video:timeupdate event.
-
-Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2395,12 +2508,8 @@ art.on('video:timeupdate', () => {
console.info(art.loaded);
});
-Property: loadedTime
-Type: Getter
+The loadedTime property is a getter that returns the amount of media that has been buffered, in seconds. It is typically used alongside loaded to display detailed buffering progress.
-The amount of media that has been buffered, in seconds. Typically used alongside loaded to display detailed buffering progress.
-
-Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2410,12 +2519,8 @@ art.on('video:timeupdate', () => {
console.info(art.loadedTime);
});
-Property: played
-Type: Getter
+The played property is a getter that returns the proportion of the video that has been played, ranging from 0 to 1. It is often used with the video:timeupdate event.
-The proportion of the video that has been played, ranging from 0 to 1. Often used with the video:timeupdate event.
-
-Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2425,12 +2530,8 @@ art.on('video:timeupdate', () => {
console.info(art.played);
});
-Property: proxy
-Type: Function
+The proxy function is a proxy for DOM events, essentially handling addEventListener and removeEventListener. When using proxy to handle events, the event listener is automatically removed when the player is destroyed. This is strongly recommended to avoid memory leaks if you need DOM events to exist only for the duration of the player's lifecycle.
-A proxy function for DOM events, essentially proxying addEventListener and removeEventListener. When using proxy to handle events, the event is automatically removed when the player is destroyed.
-
-Example code:
var container = document.querySelector('.artplayer-app');
var art = new Artplayer({
@@ -2442,14 +2543,8 @@ art.proxy(container, 'click', event => {
console.info(event);
});
-Note: If you need DOM events to exist only for the duration of the player's lifecycle, it is strongly recommended to use this function to avoid memory leaks.
+The query function is a DOM query function similar to document.querySelector, but the search is scoped to the current player instance, preventing errors from duplicate class names.
-Property: query
-Type: Function
-
-A DOM query function, similar to document.querySelector, but the search is scoped to the current player instance, preventing errors from duplicate class names.
-
-Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2457,12 +2552,8 @@ var art = new Artplayer({
console.info(art.query('.art-video'));
-Property: video
-Type: Element
+The video property quickly returns the player's video element.
-Quickly returns the player's video element.
-
-Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2470,12 +2561,8 @@ var art = new Artplayer({
console.info(art.video);
-Property: cssVar
-Type: Function
+The cssVar function dynamically gets or sets CSS variables.
-Dynamically gets or sets CSS variables.
-
-Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2487,13 +2574,8 @@ art.on('ready', () => {
console.log(art.cssVar('--art-theme'));
});
-Property: quality
-Type: Setter
-Parameter: Array
+The quality property is a setter that dynamically sets the list of available quality levels. It accepts an array parameter.
-Dynamically sets the list of available quality levels.
-
-Example code:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -2524,19 +2606,17 @@ art.on('ready', () => {
},
];
}, 3000);
-});
+})
-Property: thumbnails
-Type: Setter/Getter
-Parameter: Object
+The thumbnails property is a setter and getter for dynamically setting thumbnails. It accepts an object parameter.
-Dynamically set thumbnails.
+Example code for thumbnails would be placed here.
-Example code:
+ArtPlayer Documentation
-Initializing ArtPlayer with thumbnails
+Thumbnails Example
-Here is an example of initializing ArtPlayer with thumbnail support. The thumbnails configuration is set when the player is ready.
+This example shows how to set thumbnails for a video after the player is ready.
var art = new Artplayer({
container: '.artplayer-app',
@@ -2551,14 +2631,14 @@ art.on('ready', () => {
};
});
-Subtitle Offset
-
-The subtitleOffset property allows you to dynamically adjust subtitle timing. It can be both set and retrieved.
+subtitleOffset
Type: Setter/Getter
Parameter: Number
-This example shows how to set a subtitle offset of 1 second:
+This property allows you to dynamically set the subtitle offset in seconds.
+
+Example of setting a subtitle offset:
var art = new Artplayer({
container: '.artplayer-app',
@@ -2574,21 +2654,23 @@ art.on('ready', () => {
Context Menu
-Configuration Options
+Configuration
+
+The contextmenu component can be configured with the following properties:
Property Type Description
-disable Boolean Whether to disable the component
-name String Unique component name for CSS class
-index Number Component index for display priority
-html String, Element Component DOM element
-style Object Component style object
-click Function Component click event
-mounted Function Triggered after component mount
-tooltip String Component tooltip text
+disable Boolean Whether to disable the component
+name String Unique component name for CSS class
+index Number Component index for display priority
+html String, Element Component DOM element
+style Object Component style object
+click Function Component click event
+mounted Function Triggered after component mount
+tooltip String Component tooltip text
-Creating Context Menu Items
+Creation
-You can add custom context menu items during player initialization:
+You can create context menu items during player initialization.
var art = new Artplayer({
container: '.artplayer-app',
@@ -2610,9 +2692,9 @@ art.contextmenu.show = true;
// Get the Element of contextmenu by name
console.info(art.contextmenu['your-menu']);
-Adding Context Menu Items After Initialization
+Addition
-You can also add context menu items after the player has been created:
+You can add a context menu item after the player has been created.
var art = new Artplayer({
container: '.artplayer-app',
@@ -2633,9 +2715,9 @@ art.contextmenu.show = true;
// Get the Element of contextmenu by name
console.info(art.contextmenu['your-menu']);
-Removing Context Menu Items
+Removal
-This example shows how to remove a context menu item after a delay:
+You can remove a context menu item by its name.
var art = new Artplayer({
container: '.artplayer-app',
@@ -2661,9 +2743,9 @@ art.on('ready', () => {
}, 3000);
});
-Updating Context Menu Items
+Update
-You can update existing context menu items:
+You can update the properties of an existing context menu item.
var art = new Artplayer({
container: '.artplayer-app',
@@ -2694,24 +2776,26 @@ art.on('ready', () => {
Controls
-Configuration Options
+Configuration
+
+Controls can be configured with the following properties:
Property Type Description
-disable Boolean Whether to disable the control
-name String Unique control name for CSS class identification
-index Number Control index for display priority
-html String, Element Control's DOM element
-style Object Control style object
-click Function Control click event handler
-mounted Function Triggered after control is mounted
-tooltip String Control tooltip text
-position String left or right - controls display position
-selector Array Array of selector list objects
-onSelect Function Function triggered when selector item is clicked
+disable Boolean Whether to disable the control
+name String Unique control name for CSS class identification
+index Number Control index for display priority
+html String, Element Control's DOM element
+style Object Control style object
+click Function Control click event handler
+mounted Function Triggered after control is mounted
+tooltip String Control tooltip text
+position String 'left' or 'right' - controls display position
+selector Array Array of selector list objects
+onSelect Function Function triggered when selector item is clicked
-Creating Controls
+Creation
-This example shows how to create custom controls during player initialization:
+You can define controls during the player's initialization.
var art = new Artplayer({
container: '.artplayer-app',
@@ -2758,9 +2842,9 @@ var art = new Artplayer({
console.info(art.controls['your-button']);
console.info(art.controls['subtitle']);
-Adding Controls After Initialization
+Adding
-You can add controls to an existing player instance:
+You can add a new control to the player after it has been created.
var art = new Artplayer({
container: '.artplayer-app',
@@ -2787,9 +2871,9 @@ art.controls.add({
// Get the Element of control by name
console.info(art.controls['button1']);
-Removing Controls
+Removal
-This example demonstrates how to remove a control after a delay:
+You can remove a control by its name.
var art = new Artplayer({
container: '.artplayer-app',
@@ -2815,9 +2899,9 @@ art.on('ready', () => {
}, 3000);
});
-Updating Controls
+Updating
-You can update existing controls with new properties:
+You can update the properties of an existing control.
var art = new Artplayer({
container: '.artplayer-app',
@@ -2841,11 +2925,9 @@ var art = new Artplayer({
]
});
-Here is the reorganized documentation for learning ArtPlayer:
+ArtPlayer Documentation: Controls Update Example
-Controls Update Example
-
-This example shows how to update a control after the player is ready. After a 3-second delay, it updates a button control with new properties including position and selector options.
+This example shows how to update a control after the player is ready. After a 3-second delay, it updates a control named 'button1', changing its position, HTML content, and adding a selector list.
art.on('ready', () => {
setTimeout(() => {
@@ -2868,23 +2950,25 @@ art.on('ready', () => {
}, 3000);
});
-LAYER COMPONENT
+ArtPlayer Documentation: Layer Component
-Layer Configuration Options
+Layer Configuration
-Property Type Description
-disable Boolean Whether to disable the component
-name String Unique component name for CSS class
-index Number Component index for display priority
-html String, Element Component DOM element
-style Object Component style object
-click Function Component click event
-mounted Function Triggered after component mount
-tooltip String Component tooltip text
+The following properties can be used when creating or updating a layer component.
+
+Property Type Description
+disable Boolean Whether to disable the component
+name String Unique component name for CSS class
+index Number Component index for display priority
+html String, Element Component DOM element
+style Object Component style object
+click Function Component click event
+mounted Function Triggered after component mount
+tooltip String Component tooltip text
Layer Creation
-You can create layers during player initialization. This example creates a layer with an image that has custom styling and event handlers.
+This example shows how to add a layer during the initial Artplayer configuration. It creates a layer with an image, custom styling, and event handlers.
var img = '/assets/sample/layer.png';
var art = new Artplayer({
@@ -2915,7 +2999,7 @@ console.info(art.layers['potser']);
Layer Addition
-You can also add layers after player initialization using the layers.add method.
+This example shows how to add a layer after the Artplayer instance has been created, using the layers.add method.
var img = '/assets/sample/layer.png';
var art = new Artplayer({
@@ -2945,7 +3029,7 @@ console.info(art.layers['potser']);
Layer Removal
-This example shows how to remove a layer by name after a 3-second delay.
+This example shows how to remove a layer by its name after a delay, using the layers.remove method.
var img = '/assets/sample/layer.png';
var art = new Artplayer({
@@ -2973,7 +3057,7 @@ art.on('ready', () => {
Layer Update
-This example demonstrates updating layer properties after initialization, including changing the HTML content and style positioning.
+This example shows how to update an existing layer's properties, such as its HTML content and style, using the layers.update method.
var img = '/assets/sample/layer.png';
var art = new Artplayer({
@@ -3007,11 +3091,11 @@ art.on('ready', () => {
}, 3000);
});
-SETTINGS PANEL
+ArtPlayer Documentation: Settings Panel
Built-in Settings
-To enable the settings panel, set setting to true. The panel includes four built-in items: flip, playbackRate, aspectRatio, and subtitleOffset.
+To use the settings panel, set the 'setting' option to true. You can then enable specific built-in settings like flip, playbackRate, aspectRatio, and subtitleOffset.
var art = new Artplayer({
container: '.artplayer-app',
@@ -3025,16 +3109,16 @@ var art = new Artplayer({
Creating Button Settings
-Button settings configuration options:
+A button in the settings panel can be configured with the following properties.
-Property Type Description
-html String, Element Element DOM
-icon String, Element Element icon
-onClick Function Element click event
-width Number List width
-tooltip String Tooltip text
+Property Type Description
+html String, Element Element DOM
+icon String, Element Element icon
+onClick Function Element click event
+width Number List width
+tooltip String Tooltip text
-Example of creating a custom button in the settings panel:
+This example creates a simple button setting with a custom icon and a click handler.
var art = new Artplayer({
container: '.artplayer-app',
@@ -3055,17 +3139,17 @@ var art = new Artplayer({
Creating Selection List Settings
-Selection list configuration options:
+A selection list in the settings panel can be configured with the following properties. The 'selector' array defines the list items.
-Property Type Description
-html String, Element Element DOM
-icon String, Element Element icon
-selector Array Element list
-onSelect Function Element click event
-width Number List width
-tooltip String Tooltip text
+Property Type Description
+html String, Element Element DOM
+icon String, Element Element icon
+selector Array Element list
+onSelect Function Element click event
+width Number List width
+tooltip String Tooltip text
-Example of creating selection lists for subtitle and quality settings:
+This example creates two selection lists: one for subtitles and one for video quality. Each item in the selector can have a default state, custom HTML, and a data URL.
var art = new Artplayer({
container: '.artplayer-app',
@@ -3123,41 +3207,41 @@ var art = new Artplayer({
Creating Nested Lists
-The settings panel also supports nested list structures for more complex configuration options.
+The documentation mentions the ability to create nested lists within the settings panel, but a specific code example was not provided in the source text.
-ArtPlayer Documentation
+ArtPlayer Documentation for AI Learning
+
+This documentation covers the installation, usage, and configuration of ArtPlayer, with a focus on creating and managing settings.
Installation and Usage
-Installation
+You can install ArtPlayer via several package managers or include it directly via script tag.
-You can install ArtPlayer using npm, yarn, pnpm, or via script tag.
-
-npm installation:
+Using npm:
npm install artplayer
-yarn installation:
+Using yarn:
yarn add artplayer
-pnpm installation:
+Using pnpm:
pnpm add artplayer
-Script tag installation:
+Using a script tag in HTML:
-CDN
+CDN Links
-You can also use ArtPlayer via CDN:
+You can also load ArtPlayer from a CDN.
-jsdelivr.net CDN:
+From jsdelivr.net:
https://cdn.jsdelivr.net/npm/artplayer/dist/artplayer.js
-unpkg.com CDN:
+From unpkg.com:
https://unpkg.com/artplayer/dist/artplayer.js
-Usage
+Basic Usage Example
-Basic HTML implementation example:
+Here is a basic HTML example to get started with ArtPlayer.
@@ -3182,14 +3266,15 @@ Basic HTML implementation example:
-Important note: The player's dimensions depend on the size of its container, so your container must have defined dimensions.
+Important Note: The player's dimensions depend entirely on the size of its container element. You must define the width and height for your container.
-For more usage examples, visit:
-/example
+For more detailed usage examples, you can visit the project's example directory.
-Vue.js Integration
+Vue.js Integration Example
-ArtPlayer Vue component:
+ArtPlayer can be integrated into a Vue.js application. Here is a component example.
+
+First, create a reusable Artplayer.vue component:
@@ -3224,7 +3309,7 @@ onBeforeUnmount(() => {
})
-Vue implementation example:
+Then, use the component in your app.vue file:
@@ -3249,11 +3334,15 @@ function getInstance(art) {
}
-Important note: Artplayer is not reactive.
+Important Note: The Artplayer instance itself is not reactive. Manage its state through its own API methods.
-Settings Configuration
+Creating Settings
-Multi-level Settings Example
+ArtPlayer allows you to add custom settings to its control panel. There are several types of settings you can create.
+
+Creating a Multi-Level Selector Setting
+
+This example shows how to create a setting with nested selectors.
var art = new Artplayer({
container: '.artplayer-app',
@@ -3300,16 +3389,31 @@ var art = new Artplayer({
],
});
-Toggle Button Settings
+Creating a Toggle Button Setting
-Properties for toggle button:
-Property: html, Type: String, Element, Description: DOM element of the item
-Property: icon, Type: String, Element, Description: Icon of the item
-Property: switch, Type: Boolean, Description: Default state of the button
-Property: onSwitch, Type: Function, Description: Button toggle event
-Property: tooltip, Type: String, Description: Tooltip text
+A toggle button setting has a switch that can be on or off. Here are its properties.
-Toggle button implementation:
+Property: html
+Type: String, Element
+Description: DOM element or text for the item.
+
+Property: icon
+Type: String, Element
+Description: Icon for the item.
+
+Property: switch
+Type: Boolean
+Description: The default state of the button (true for on, false for off).
+
+Property: onSwitch
+Type: Function
+Description: The function called when the button is toggled.
+
+Property: tooltip
+Type: String
+Description: The text shown when hovering over the button.
+
+Here is an example of creating a toggle button for Picture-in-Picture (PIP) mode.
var art = new Artplayer({
container: '.artplayer-app',
@@ -3332,24 +3436,42 @@ var art = new Artplayer({
],
});
-Range Slider Settings
+Creating a Range Slider Setting
-Properties for range slider:
-Property: html, Type: String, Element, Description: DOM element of the item
-Property: icon, Type: String, Element, Description: Icon of the item
-Property: range, Type: Array, Description: Default state array
-Property: onRange, Type: Function, Description: Event triggered on completion
-Property: onChange, Type: Function, Description: Event triggered on change
-Property: tooltip, Type: String, Description: Tooltip text
+A range slider setting allows users to select a numeric value. Here are its properties.
-Range array structure:
+Property: html
+Type: String, Element
+Description: DOM element or text for the item.
+
+Property: icon
+Type: String, Element
+Description: Icon for the item.
+
+Property: range
+Type: Array
+Description: An array defining the slider's state: [default_value, min_value, max_value, step].
+
+Property: onRange
+Type: Function
+Description: Function triggered when the user finishes changing the slider.
+
+Property: onChange
+Type: Function
+Description: Function triggered whenever the slider value changes.
+
+Property: tooltip
+Type: String
+Description: The text shown when hovering over the slider.
+
+The range array is structured as follows:
const range = [5, 1, 10, 1];
-const value = range[0];
-const min = range[1];
-const max = range[2];
-const step = range[3];
+const value = range[0]; // The current/default value (5)
+const min = range[1]; // The minimum value (1)
+const max = range[2]; // The maximum value (10)
+const step = range[3]; // The step increment (1)
-Range slider implementation:
+Here is an example of creating a playback speed slider.
var art = new Artplayer({
container: '.artplayer-app',
@@ -3369,9 +3491,9 @@ var art = new Artplayer({
],
});
-Adding Settings Dynamically
+Adding a Setting After Initialization
-You can add settings after initialization:
+You can add a new setting to the player after it has been created using the `add` method.
var art = new Artplayer({
container: '.artplayer-app',
@@ -3388,9 +3510,9 @@ art.setting.add({
range: [5, 1, 10, 1],
});
-Removing Settings
+Removing a Setting
-Settings can be removed by name:
+You can remove a setting by its unique `name` property using the `remove` method. In this example, the setting named 'slider' is removed after a 3-second delay.
var art = new Artplayer({
container: '.artplayer-app',
@@ -3417,9 +3539,9 @@ art.on('ready', () => {
}, 3000);
});
-Updating Settings
+Updating a Setting
-Existing settings can be updated:
+You can update the properties of an existing setting by its `name` using the `update` method. In this example, a slider setting is changed to a toggle button after 3 seconds.
var art = new Artplayer({
container: '.artplayer-app',
@@ -3453,13 +3575,11 @@ art.on('ready', () => {
ArtPlayer Documentation
-Vue.js Integration
+React.js
-Note: Directly modifying the option object in Vue.js will not update the player.
+Here is an example of using ArtPlayer in a React.js component.
-React.js Integration
-
-Here is a React component implementation for ArtPlayer:
+Artplayer.jsx:
import Artplayer from 'artplayer'
import { useEffect, useRef } from 'react'
@@ -3483,7 +3603,7 @@ export default function Player({ option, getInstance, ...rest }) {
return
}
-Example usage in a React application:
+app.jsx:
import Artplayer from './Artplayer.jsx'
@@ -3507,13 +3627,13 @@ function App() {
export default App
-Important: Directly modifying the option object in React.js will not update the player.
+Important note: Artplayer is not reactive. Directly modifying the `option` prop in React.js will not update the player.
-TypeScript Support
+TypeScript
-The artplayer.d.ts type definitions are automatically imported when importing Artplayer.
+TypeScript definitions are automatically imported when you import Artplayer. Here are examples for different frameworks.
-Vue.js with TypeScript:
+Vue.js:
-React.js with TypeScript:
+React.js:
import Artplayer from 'artplayer';
const art = useRef(null);
art.current = new Artplayer();
-You can also use the Option type for better type safety:
+You can also import and use the Option type for better type safety.
+
+Option:
import Artplayer, { type Option } from 'artplayer';
@@ -3540,20 +3662,20 @@ option.volume = 0.5;
const art = new Artplayer(option);
-For complete TypeScript definitions, refer to: packages/artplayer/types
+For the full TypeScript definitions, refer to the repository: packages/artplayer/types
-JavaScript Type Hints
+JavaScript
-If your JavaScript files lose TypeScript type hints, you can manually import types using JSDoc comments.
+If your JavaScript files lose TypeScript type hints, you can manually import the types using JSDoc comments.
-For variables:
+For a variable:
/**
* @type {import("artplayer")}
*/
let art = null;
-For function parameters:
+For a function parameter:
/**
* @param {import("artplayer")} art
@@ -3562,7 +3684,7 @@ function getInstance(art) {
//
}
-For object properties:
+For a Vue.js component property:
export default {
data() {
@@ -3575,7 +3697,7 @@ export default {
}
}
-For option objects:
+For the Option type:
/**
* @type {import("artplayer/types/option").Option}
@@ -3590,23 +3712,29 @@ option.volume = 0.5;
const art8 = new Artplayer(option);
-Legacy Browser Support
+Legacy Browsers
-The standard production build artplayer.js supports only the latest Chrome version. For legacy browser support, use artplayer.legacy.js which supports IE 11 and above.
+The standard production build, artplayer.js, supports the latest version of Chrome. For compatibility with older browsers, use the legacy build.
+
+Import the legacy version:
import Artplayer from 'artplayer/legacy'
-CDN URLs for legacy version:
+You can also use it via a CDN:
+
+From jsdelivr.net:
https://cdn.jsdelivr.net/npm/artplayer/dist/artplayer.legacy.js
+
+From unpkg.com:
https://unpkg.com/artplayer/dist/artplayer.legacy.js
-To support even older browsers, modify the build configuration and build it yourself. Refer to scripts/build.js and the browserslist documentation.
+The legacy build supports browsers as old as IE 11. If you need to support even older browsers, you can modify the build configuration and compile it yourself. Refer to the build script and the browserslist documentation for details.
-ECMAScript Module Support
+ECMAScript Module
-Starting from version 5.2.6, ArtPlayer provides ESM versions with .mjs extension.
+Starting from version 5.2.6, ArtPlayer and its plugins provide ESM versions with the .mjs extension.
-Example HTML using ESM with import maps:
+Example using an import map in HTML:
@@ -3645,9 +3773,11 @@ Example HTML using ESM with import maps:
-Custom User Agent
+Custom userAgent
-To adjust player UI by changing user agent detection, use globalThis.CUSTOM_USER_AGENT (available from version 5.2.4).
+To manually adjust the player's UI for mobile detection, you can set a custom userAgent string. This feature is available from version 5.2.4.
+
+Set the global variable `globalThis.CUSTOM_USER_AGENT` before importing the Artplayer script.
@@ -3673,17 +3803,15 @@ To adjust player UI by changing user agent detection, use globalThis.CUSTOM_USER
-Important: You must set CUSTOM_USER_AGENT before importing the ArtPlayer dependency.
+Important: You must set the custom userAgent before loading the Artplayer library for it to take effect.
-Language Settings (i18n)
+Language Settings
-Important: Starting from version 5.1.0, only Simplified Chinese and English are included in the core bundle. Other languages must be imported manually.
-
-When a language cannot be matched, English will be displayed by default.
+Important: From version 5.1.0, the core artplayer.js only includes Simplified Chinese (zh-cn) and English (en). Other languages must be imported manually. If a language is not matched, English will be displayed by default.
Default Languages
-The default included languages are English (en) and Simplified Chinese (zh-cn).
+The default languages, 'en' and 'zh-cn', are built-in.
var art = new Artplayer({
container: '.artplayer-app',
@@ -3691,11 +3819,11 @@ var art = new Artplayer({
lang: 'zh-cn', // or 'en'
});
-Importing Additional Languages
+Importing Languages
-Language files are available in artplayer/src/i18n/*.js before bundling and artplayer/dist/i18n/*.js after bundling.
+Language files are available in the dist/i18n/ directory. You can import them as modules or via script tags.
-Using import:
+Module import example:
import id from 'artplayer/i18n/id';
import zhTw from 'artplayer/i18n/zh-tw';
@@ -3710,7 +3838,7 @@ var art = new Artplayer({
lang: 'zh-tw',
});
-Using script tags:
+Script tag example:
@@ -3727,6 +3855,8 @@ var art = new Artplayer({
Adding a New Language
+You can define a custom language directly in the options.
+
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -3738,7 +3868,9 @@ var art = new Artplayer({
},
});
-Modifying Existing Languages
+Modifying Languages
+
+You can override the strings of any language, including the default ones.
import zhTw from 'artplayer/i18n/zh-tw';
@@ -3746,11 +3878,11 @@ var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
i18n: {
- // Change the default language
+ // Change the default 'zh-cn' language
'zh-cn': {
Play: 'Your Play'
},
- // Change the imported language
+ // Change the imported 'zh-tw' language
'zh-tw': {
...zhTw,
Play: 'Your Play'
@@ -3760,51 +3892,58 @@ var art = new Artplayer({
Basic Options
-container Option
+container
-Type: String, Element
-Default: #artplayer
+- Type: String, Element
+- Default: #artplayer
The DOM container where the player is mounted.
-To initialize ArtPlayer, the container option is required. You can specify it using a CSS selector or a DOM element.
+To initialize an ArtPlayer instance, you must provide a container element. This can be a CSS selector string or a direct DOM element reference.
+```js
var art = new Artplayer({
container: '.artplayer-app',
// container: document.querySelector('.artplayer-app'),
url: '/assets/sample/video.mp4',
});
+```
-You may need to set the size of the container element. Here are two common approaches:
-
-Using fixed width and height:
+You may need to define the size of the container element. You can set explicit width and height.
+```css
.artplayer-app {
width: 400px;
height: 300px;
}
+```
-Or using aspect ratio:
+Alternatively, you can use the CSS aspect-ratio property.
+```css
.artplayer-app {
aspect-ratio: 16/9;
}
+```
-Note: Among all options, only container is required.
+Note: Among all configuration options, only the `container` is required.
-URL Option
+URL
Type: String
Default: ''
-The video source URL.
+This is the video source URL.
+```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
+```
-If the URL is not available immediately, you can set it asynchronously:
+If the video URL is not known at initialization time, you can set it asynchronously later.
+```js
var art = new Artplayer({
container: '.artplayer-app',
});
@@ -3812,27 +3951,31 @@ var art = new Artplayer({
setTimeout(() => {
art.url = '/assets/sample/video.mp4';
}, 1000);
+```
-Note: By default, three video file formats are supported: .mp4, .ogg, .webm. To play other formats like .m3u8 or .flv, please refer to the Third-party Libraries section.
+Note: By default, three video file formats are supported: .mp4, .ogg, .webm. To play other formats like .m3u8 or .flv, please refer to the 'Third-party Libraries' section.
-ID Option
+ID
Type: String
Default: ''
-The unique identifier for the player, currently used for playback resumption with autoplayback.
+A unique identifier for the player, currently used for the playback resumption feature (`autoplayback`).
+```js
var art = new Artplayer({
id: 'your-url-id',
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
+```
-onReady Option
+ONREADY
Type: Function
Default: undefined
-A callback function triggered when the player is successfully initialized and the video is ready to play.
+You can pass a function as the second parameter to the constructor. This function is called once the player is fully initialized and the video is ready to play, similar to the 'ready' event.
+```js
var art = new Artplayer(
{
container: '.artplayer-app',
@@ -3843,9 +3986,11 @@ var art = new Artplayer(
this.play()
},
);
+```
-This is equivalent to using the ready event:
+This is equivalent to using the event listener method:
+```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -3855,295 +4000,317 @@ var art = new Artplayer({
art.on('ready', () => {
art.play();
});
+```
-Note: Inside the callback function, this refers to the player instance. However, if an arrow function is used, this will not point to the player instance.
+Note: Inside the `onReady` callback function, `this` refers to the player instance. However, if you use an arrow function, `this` will not be bound to the player instance.
-Poster Option
+POSTER
Type: String
Default: ''
-The video poster image, displayed when the player is initialized but not yet playing.
+The poster image URL, displayed when the player is initialized but before video playback begins.
+```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
poster: '/assets/sample/poster.jpg',
});
+```
-Theme Option
+THEME
Type: String
Default: '#f00'
-The player's theme color, used for the progress bar and highlighted elements.
+The theme color for the player, used for elements like the progress bar and highlights.
+```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
theme: '#ffad00',
});
+```
-Volume Option
+VOLUME
Type: Number
Default: 0.7
-The default volume of the player.
+The default volume level for the player.
+```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
volume: 0.5,
});
+```
-Note: The player caches the last volume level and will use this cached value upon next initialization.
+Note: The player caches the last volume setting. On the next initialization (e.g., page refresh), it will use this cached value.
-isLive Option
+ISLIVE
Type: Boolean
Default: false
-Enable live streaming mode, which hides the progress bar and playback time.
+Enables live streaming mode, which hides the progress bar and playback time.
+```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
isLive: true,
});
+```
-Muted Option
+MUTED
Type: Boolean
Default: false
-Whether to mute by default.
+Determines if the player starts in a muted state.
+```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
muted: true,
});
+```
-Autoplay Option
+AUTOPLAY
Type: Boolean
Default: false
-Whether to autoplay.
+Determines if the video should start playing automatically.
+```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
autoplay: true,
muted: true,
});
+```
-Note: If you want the video to autoplay immediately upon page load, muted must be set to true. For more information, please read Autoplay Policy Changes.
+Note: For a video to autoplay immediately on page load, `muted` must be set to `true`. Please refer to browser autoplay policies for more details.
-AutoSize Option
+AUTOSIZE
Type: Boolean
Default: false
-Automatically adjusts the player size to hide black bars, similar to object-fit: cover in CSS.
+Automatically adjusts the player size to fill the container and hide black bars, similar to the CSS property `object-fit: cover;`.
+```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
autoSize: true,
});
+```
-AutoMini Option
+AUTOMINI
Type: Boolean
Default: false
-Automatically enters mini player mode when the player scrolls out of the browser viewport.
+Automatically switches to mini-player mode when the player scrolls out of the browser viewport.
+```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
autoMini: true,
});
+```
-Loop Option
+LOOP
Type: Boolean
Default: false
-Whether to enable video looping.
+Enables looping of the video.
+```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
loop: true,
});
+```
-Flip Option
+FLIP
Type: Boolean
Default: false
-Whether to display the video flip functionality. Appears in the Settings Panel and Context Menu.
+Enables the video flip functionality, which appears in the Settings Panel and Context Menu.
+```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
flip: true,
setting: true,
});
+```
-PlaybackRate Option
+PLAYBACKRATE
Type: Boolean
Default: false
-Whether to display the video playback rate functionality. Appears in the Settings Panel and Context Menu.
+Enables the video playback rate functionality, which appears in the Settings Panel and Context Menu.
+```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
playbackRate: true,
setting: true,
});
+```
-AspectRatio Option
+ASPECTRATIO
Type: Boolean
Default: false
-Whether to display the video aspect ratio functionality. Appears in the Settings Panel and Context Menu.
+Enables the video aspect ratio functionality, which appears in the Settings Panel and Context Menu.
+```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
aspectRatio: true,
setting: true,
});
+```
-Screenshot Option
+SCREENSHOT
Type: Boolean
Default: false
-Whether to display the Video Screenshot functionality in the bottom control bar.
+Adds a video screenshot button to the bottom control bar.
+```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
screenshot: true,
});
+```
-Note: Due to browser security mechanisms, screenshot capture may fail if the video source URL is cross-origin with the website.
+Note: Due to browser security policies, screenshot capture may fail if the video is served from a different origin (cross-origin) than the website.
-Setting Option
+SETTING
Type: Boolean
Default: false
-Whether to display the toggle button for the Settings Panel in the bottom control bar.
+Adds a toggle button for the Settings Panel to the bottom control bar.
+```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
setting: true,
});
+```
-Hotkey Option
+HOTKEY
Type: Boolean
Default: true
-Whether to enable hotkeys.
+Enables keyboard hotkeys for player control.
+```js
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
hotkey: true,
});
+```
-Hotkeys for ArtPlayer
+Hotkeys
-The following hotkeys are available for controlling the player:
+The following hotkeys are available for controlling the player. Note that these hotkeys only take effect after the player gains focus, for example by clicking on it.
-Up arrow: Increase volume
-Down arrow: Decrease volume
-Left arrow: Seek forward
-Right arrow: Seek backward
-Spacebar: Toggle play/pause
+Hotkey: Up arrow
+Description: Increase volume
-Note: These hotkeys only take effect after the player gains focus (e.g., by clicking on the player).
+Hotkey: Down arrow
+Description: Decrease volume
+Hotkey: Left arrow
+Description: Seek forward
-Picture-in-Picture Option
+Hotkey: Right arrow
+Description: Seek backward
+Hotkey: Space
+Description: Toggle play/pause
+
+Configuration Options
+
+pip
Type: Boolean
Default: false
+This setting determines whether to display the Picture-in-Picture toggle button in the bottom control bar.
-Whether to display the Picture-in-Picture toggle button in the bottom control bar.
-
-Example configuration:
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
pip: true,
});
-
-Mutex Option
-
+mutex
Type: Boolean
Default: true
+When multiple players exist on the same page, this setting controls whether only one player is allowed to play at a time.
-If multiple players exist simultaneously on the page, whether only one player is allowed to play at a time.
-
-Example configuration:
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
mutex: true,
});
-
-Backdrop Option
-
+backdrop
Type: Boolean
Default: true
+This enables or disables a backdrop blur effect for UI overlays like the settings panel, creating a frosted glass appearance. It may impact performance on some devices or older browsers.
-Whether to enable the backdrop blur effect for the player UI. When enabled, overlays such as the settings panel, context menu, and volume bar will apply a backdrop-filter frosted glass effect for a more transparent appearance. However, this may cause performance or compatibility issues on some low-performance devices or older browsers.
-
-Example configuration (disabling the effect):
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
- backdrop: false,
+ backdrop: false, // Disable frosted glass effect
});
-
-Fullscreen Option
-
+fullscreen
Type: Boolean
Default: false
+This setting determines whether to display the Window Fullscreen button in the bottom control bar.
-Whether to display the player Window Fullscreen button in the bottom control bar.
-
-Example configuration:
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
fullscreen: true,
});
-
-Fullscreen Web Option
-
+fullscreenWeb
Type: Boolean
Default: false
+This setting determines whether to display the Webpage Fullscreen button in the bottom control bar.
-Whether to display the player Webpage Fullscreen button in the bottom control bar.
-
-Example configuration:
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
fullscreenWeb: true,
});
-
-Subtitle Offset Option
-
+subtitleOffset
Type: Boolean
Default: false
+When enabled, this adds a subtitle timing offset control to the Settings Panel, allowing adjustments within a range of -5 to +5 seconds.
-Subtitle timing offset, range within [-5s, 5s]. Appears in the Settings Panel.
-
-Example configuration:
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -4154,32 +4321,24 @@ var art = new Artplayer({
setting: true,
});
-
-Mini Progress Bar Option
-
+miniProgressBar
Type: Boolean
Default: false
+When enabled, a mini progress bar will appear when the player loses focus but is still playing.
-Mini progress bar that appears only when the player loses focus and is playing.
-
-Example configuration:
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
miniProgressBar: true,
});
-
-Use SSR Option
-
+useSSR
Type: Boolean
Default: false
+This setting enables Server-Side Rendering (SSR) mount mode, useful for pre-rendering the player's HTML. You can access the required HTML via Artplayer.html.
-Whether to use SSR mount mode. Useful if you want to pre-render the player's required HTML before mounting.
-
-You can access the player's required HTML via Artplayer.html.
-
-Example configuration:
+Example:
var $container = document.querySelector('.artplayer-app');
$container.innerHTML = Artplayer.html;
@@ -4189,30 +4348,24 @@ var art = new Artplayer({
useSSR: true,
});
-
-Plays Inline Option
-
+playsInline
Type: Boolean
Default: true
+This controls whether to use playsInline mode for video playback on mobile devices.
-Whether to use playsInline mode on mobile devices.
-
-Example configuration:
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
playsInline: true,
});
-
-Layers Option
-
+layers
Type: Array
Default: []
+This array is used to initialize custom layers on the player.
-Initialize custom layers.
-
-Example configuration:
+Example:
var img = '/assets/sample/layer.png';
var art = new Artplayer({
container: '.artplayer-app',
@@ -4238,17 +4391,14 @@ var art = new Artplayer({
],
});
-For Component Configuration, please refer to: /component/layers.html
-
-
-Settings Option
+For detailed Component Configuration, please refer to: /component/layers.html
+settings
Type: Array
Default: []
+This array is used to initialize a custom settings panel. Note that the main 'setting' option must also be set to true.
-Initialize custom settings panel.
-
-Example configuration:
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -4285,17 +4435,14 @@ var art = new Artplayer({
],
});
-For Settings Panel configuration, please refer to: /component/setting.html
-
-
-Context Menu Option
+For detailed Settings Panel configuration, please refer to: /component/setting.html
+contextmenu
Type: Array
Default: []
+This array is used to initialize custom items in the player's right-click context menu.
-Initialize custom context menu.
-
-Example configuration:
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -4310,17 +4457,14 @@ var art = new Artplayer({
],
});
-For Component Configuration, please refer to: /component/contextmenu.html
-
-
-Controls Option
+For detailed Component Configuration, please refer to: /component/contextmenu.html
+controls
Type: Array
Default: []
+This array is used to initialize custom controls in the bottom control bar.
-Initialize custom bottom control bar.
-
-Example configuration:
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -4339,22 +4483,17 @@ var art = new Artplayer({
],
});
-For Component Configuration, please refer to: /component/controls.html
-
-
-Quality Option
+For detailed Component Configuration, please refer to: /component/controls.html
+quality
Type: Array
Default: []
+This array defines the available quality options for the Quality Selection list in the control bar. Each object in the array uses the following properties:
+Property: default, Type: Boolean, Description: Marks this as the default quality.
+Property: html, Type: String, Description: The display name for the quality.
+Property: url, Type: String, Description: The video URL for this quality.
-Whether to display the Quality Selection list in the bottom control bar.
-
-Quality option properties:
-Property: default, Type: Boolean, Description: Default quality
-Property: html, Type: String, Description: Quality name
-Property: url, Type: String, Description: Quality URL
-
-Example configuration:
+Example:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -4371,17 +4510,14 @@ var art = new Artplayer({
],
});
-
-Highlight Option
-
+highlight
Type: Array
Default: []
+This array is used to define highlight markers that will be displayed on the player's progress bar.
-Display Highlight Information on the progress bar.
+Here is the reorganized documentation for learning the ArtPlayer AI model, presented in a clean, readable plain text format with all code and configuration preserved.
-Here is the reorganized documentation for the ArtPlayer AI model:
-
-HIGHLIGHT
+The highlight option allows you to mark specific points in the video timeline with text annotations. Each highlight is defined by a time in seconds and a text string.
Property: time
Type: Number
@@ -4391,7 +4527,7 @@ Property: text
Type: String
Description: Highlight text
-Example configuration showing how to set up video highlights at specific timestamps:
+Example configuration with multiple highlights:
var art = new Artplayer({
container: '.artplayer-app',
@@ -4420,14 +4556,15 @@ var art = new Artplayer({
],
});
-PLUGINS
+
+Plugins
Type: Array
Default: []
-Initialize custom plugins. Plugins allow you to extend ArtPlayer functionality with custom features.
+Initialize custom plugins. A plugin is a function that receives the art instance and returns an object with a name and custom methods.
-Example of creating and using a custom plugin:
+Example of defining and using a custom plugin:
function myPlugin(art) {
console.info(art);
@@ -4446,12 +4583,13 @@ var art = new Artplayer({
plugins: [myPlugin],
});
-THUMBNAILS
+
+Thumbnails
Type: Object
Default: {}
-Set preview thumbnails on the progress bar.
+Set Preview Thumbnails on the progress bar. This requires a sprite image containing all thumbnails.
Property: url
Type: String
@@ -4477,7 +4615,7 @@ Property: scale
Type: Number
Description: Thumbnail scale
-Example configuration for setting up thumbnails:
+Basic configuration example:
var art = new Artplayer({
container: '.artplayer-app',
@@ -4491,12 +4629,13 @@ var art = new Artplayer({
Note: You can generate thumbnails online using artplayer-tool-thumbnail.
-SUBTITLE
+
+Subtitle
Type: Object
Default: {}
-Set the video subtitle. Supported subtitle formats: vtt, srt, ass.
+Set the video subtitle. Supported subtitle formats are vtt, srt, and ass.
Property: name
Type: String
@@ -4526,7 +4665,7 @@ Property: onVttLoad
Type: Function
Description: Function for modifying vtt text
-Example configuration for setting up subtitles with custom styling:
+Example with an SRT subtitle and custom styling:
var art = new Artplayer({
container: '.artplayer-app',
@@ -4543,14 +4682,15 @@ var art = new Artplayer({
},
});
-MORE VIDEO ATTR
+
+More Video Attributes
Type: Object
-Default: {'controls': false, 'preload': 'metadata'} (In Safari, it automatically adjusts to preload: 'auto' for better loading experience)
+Default: {'controls': false, 'preload': 'metadata'} (In Safari, it automatically adjusts to preload: 'auto' for better loading experience).
More video attributes. These attributes will be directly written into the video element.
-Example showing how to set inline playback attributes:
+Example adding inline playback attributes for mobile:
var art = new Artplayer({
container: '.artplayer-app',
@@ -4561,14 +4701,15 @@ var art = new Artplayer({
},
});
-ICONS
+
+Icons
Type: Object
Default: {}
Used to replace default icons, supports both Html strings and HTMLElement.
-Example showing how to customize loading and state icons:
+Example replacing the loading and state icons:
var art = new Artplayer({
container: '.artplayer-app',
@@ -4579,16 +4720,17 @@ var art = new Artplayer({
},
});
-Note: See artplayer/types/icons.d.ts for all available icon definitions.
+Note: For all icon definitions, refer to artplayer/types/icons.d.ts.
-TYPE
+
+Type
Type: String
Default: ''
Used to specify the video format. It needs to be used in conjunction with customType. By default, the video format is determined by the suffix of the video URL (e.g., .m3u8, .mkv, .ts). However, sometimes the video URL lacks the correct suffix, so explicit specification is necessary.
-Example showing how to explicitly specify the video type:
+Example specifying an HLS stream:
var art = new Artplayer({
container: '.artplayer-app',
@@ -4596,38 +4738,37 @@ var art = new Artplayer({
type: 'm3u8',
});
-Note: The player can only parse suffixes like /assets/sample/video.m3u8 but cannot parse suffixes like /assets/sample/video?type=m3u8. Therefore, if you use customType, it is best to also specify the type.
+Note: The player can parse suffixes like /assets/sample/video.m3u8 but not query parameters like /assets/sample/video?type=m3u8. If you use customType, it is best to also specify the type.
-CUSTOM TYPE
+
+Custom Type
Type: Object
Default: {}
-Matches based on the video's type and delegates video decoding to third-party programs. The handler function receives three parameters:
-- video: The video DOM element
-- url: The video URL
-- art: The current instance
+Matches based on the video's type and delegates video decoding to third-party programs. The handler function receives three parameters: video (the video DOM element), url (the video URL), and art (the current instance).
-Example showing how to set up custom type handling:
+Example setting up a custom handler for HLS streams:
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.m3u8',
customType: {
m3u8: function (video, url, art) {
- //
+ // Your custom playback logic here
},
},
});
-LANG
+
+Language
Type: String
Default: navigator.language.toLowerCase()
The default display language. Currently supported: en, zh-cn.
-Example showing how to set the language to English:
+Example setting the player to English:
var art = new Artplayer({
container: '.artplayer-app',
@@ -4635,16 +4776,17 @@ var art = new Artplayer({
lang: 'en',
});
-Note: See /start/i18n.html for more language settings.
+Note: For more language settings, see /start/i18n.html.
-I18N
+
+Internationalization (i18n)
Type: Object
Default: {}
Custom i18n configuration. This configuration will be deeply merged with the built-in i18n.
-Example showing how to add a new language:
+Example adding a new language:
var art = new Artplayer({
container: '.artplayer-app',
@@ -4657,7 +4799,7 @@ var art = new Artplayer({
},
});
-Example showing how to modify existing languages:
+Example modifying an existing language:
var art = new Artplayer({
container: '.artplayer-app',
@@ -4672,16 +4814,17 @@ var art = new Artplayer({
},
});
-Note: See /start/i18n.html for more language settings.
+Note: For more language settings, see /start/i18n.html.
-LOCK
+
+Lock
Type: Boolean
Default: false
Whether to display a lock button on mobile devices to hide the bottom control bar.
-Example showing how to enable the lock feature:
+Example enabling the lock feature:
var art = new Artplayer({
container: '.artplayer-app',
@@ -4689,14 +4832,15 @@ var art = new Artplayer({
lock: true,
});
-GESTURE
+
+Gesture
Type: Boolean
Default: true
Whether to enable gesture events on the video element on mobile devices.
-Example showing how to disable gestures:
+Example disabling gestures:
var art = new Artplayer({
container: '.artplayer-app',
@@ -4704,14 +4848,15 @@ var art = new Artplayer({
gesture: false,
});
-FAST FORWARD
+
+Fast Forward
Type: Boolean
Default: false
Whether to add a long-press video fast-forward feature on mobile devices.
-Example showing how to enable fast forward:
+Example enabling fast-forward:
var art = new Artplayer({
container: '.artplayer-app',
@@ -4719,7 +4864,10 @@ var art = new Artplayer({
fastForward: true,
});
-To use ArtPlayer, initialize it with a container and video URL. Here is a basic example:
+Here is the documentation reorganized into a clean, plain text format.
+
+Initialization Example
+This is a basic example of creating an ArtPlayer instance.
var art = new Artplayer({
container: '.artplayer-app',
@@ -4730,8 +4878,7 @@ var art = new Artplayer({
autoPlayback
Type: Boolean
Default: false
-
-This option enables the automatic playback feature, which resumes video playback from the last watched position.
+Determines whether to use the automatic playback feature, which resumes video playback from the last watched position.
var art = new Artplayer({
container: '.artplayer-app',
@@ -4740,13 +4887,12 @@ var art = new Artplayer({
autoPlayback: true,
});
-Note: By default, the player uses the url as the key to cache playback progress. If the same video has different URLs, use the id to set a unique key for accurate progress tracking.
+Note: By default, the player uses the video URL as the key to cache playback progress. If the same video can be accessed via different URLs, you must provide a unique 'id' to serve as the cache key.
autoOrientation
Type: Boolean
Default: false
-
-When enabled, this rotates the player during fullscreen mode on mobile devices based on video dimensions and viewport size.
+When enabled on mobile web, this will automatically rotate the player during fullscreen mode based on the video's dimensions and the screen size.
var art = new Artplayer({
container: '.artplayer-app',
@@ -4757,8 +4903,7 @@ var art = new Artplayer({
airplay
Type: Boolean
Default: false
-
-This option shows the AirPlay button, but note that it is only supported in some browsers.
+Controls the visibility of the AirPlay button. Note that this feature is only supported in certain browsers.
var art = new Artplayer({
container: '.artplayer-app',
@@ -4769,24 +4914,22 @@ var art = new Artplayer({
cssVar
Type: Object
Default: {}
-
-Use this to modify built-in CSS variables for customizing the player's appearance.
+This object allows you to override the player's built-in CSS variables for custom styling.
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
cssVar: {
- //
+ // Define custom CSS variables here
},
});
-For a list of available CSS variables, refer to: artplayer/types/cssVar.d.ts
+For a full list of available CSS variables, please refer to the official type definition file: artplayer/types/cssVar.d.ts
proxy
Type: function
Default: undefined
-
-This function can return a third-party HTMLCanvasElement or HTMLVideoElement, such as proxying an existing video DOM element.
+This function can return a third-party HTMLCanvasElement or HTMLVideoElement. A common use case is to proxy an existing video DOM element for the player to use.
var art = new Artplayer({
container: '.artplayer-app',
@@ -4800,57 +4943,63 @@ var art = new Artplayer({
artplayer-plugin-ads.d.ts
-This plugin handles advertising functionality within ArtPlayer.
+This plugin adds advertising capabilities to ArtPlayer, supporting video, image, and HTML ad formats.
-The Option interface defines ad configuration:
interface Option {
/**
* 广告源文本,支持视频链接、图片链接、HTML文本
+ * Ad source text, supports video links, image links, HTML text
*/
source: string
/**
* 知名广告的类型:'video' | 'image' | 'html'
+ * Known ad type: 'video' | 'image' | 'html'
*/
type: 'video' | 'image' | 'html'
/**
* 广告必看的时长,单位为秒
+ * Mandatory ad viewing duration in seconds
*/
playDuration?: number
/**
* 广告总的时长,单位为秒
+ * Total ad duration in seconds
*/
totalDuration?: number
/**
* 视频广告是否默认静音
+ * Whether video ads are muted by default
*/
muted?: boolean
}
-The Ads interface provides ad control methods:
interface Ads {
name: 'artplayerPluginAds'
/**
* 跳过广告
+ * Skip ad
*/
skip: () => void
/**
* 暂停广告
+ * Pause ad
*/
pause: () => void
/**
* 播放广告
+ * Play ad
*/
play: () => void
}
-Plugin declaration:
+// The plugin is a function that takes an Option object and returns a function that takes an Artplayer instance, returning an Ads instance.
declare const artplayerPluginAds: (option: Option) => (art: Artplayer) => Ads
export default artplayerPluginAds
@@ -4860,9 +5009,8 @@ export as namespace artplayerPluginAds;
artplayer-plugin-ambilight.d.ts
-This plugin creates ambient lighting effects around the video player.
+This plugin creates an ambient light effect around the video player based on the video content.
-Configuration options for the ambilight effect:
interface Option {
blur?: string
opacity?: number
@@ -4871,14 +5019,12 @@ interface Option {
duration?: number
}
-Result interface with control methods:
interface Result {
name: 'artplayerPluginAmbilight'
start: () => void
stop: () => void
}
-Plugin declaration:
declare const artplayerPluginAmbilight: (option: Option) => (art: Artplayer) => Result
export default artplayerPluginAmbilight
@@ -4888,15 +5034,13 @@ export as namespace artplayerPluginAmbilight;
artplayer-plugin-asr.d.ts
-This plugin provides Automatic Speech Recognition (ASR) functionality.
+This plugin provides Automatic Speech Recognition (ASR) functionality, capturing audio chunks for subtitle generation.
-AudioChunk interface for audio data:
interface AudioChunk {
pcm: ArrayBuffer
wav: ArrayBuffer
}
-ASR plugin configuration options:
interface AsrPluginOption {
length?: number
interval?: number
@@ -4905,7 +5049,6 @@ interface AsrPluginOption {
onAudioChunk?: (chunk: AudioChunk) => void | Promise
}
-ASR plugin instance with control methods:
interface AsrPluginInstance {
name: 'artplayerPluginAsr'
stop: () => void
@@ -4913,7 +5056,6 @@ interface AsrPluginInstance {
append: (subtitle: string) => void
}
-Plugin declaration:
declare function artplayerPluginAsr(option?: AsrPluginOption): (art: Artplayer) => AsrPluginInstance
export default artplayerPluginAsr
@@ -4921,11 +5063,55 @@ export default artplayerPluginAsr
export = artplayerPluginAsr
export as namespace artplayerPluginAsr;
+artplayer-plugin-audio-track.d.ts
+
+This plugin allows adding an external audio track to synchronize with the video playback.
+
+interface Option {
+ /**
+ * Audio track URL
+ */
+ url: string
+
+ /**
+ * Time offset in seconds between video and audio
+ * Positive value means audio plays ahead of video
+ * Negative value means audio plays behind video
+ * @default 0
+ */
+ offset?: number
+
+ /**
+ * Synchronization threshold in seconds
+ * @default 0.3
+ */
+ sync?: number
+}
+
+interface Result {
+ name: 'artplayerPluginAudioTrack'
+ /**
+ * The audio element
+ */
+ audio: HTMLAudioElement
+
+ /**
+ * Update option
+ */
+ update: (option: Option) => void
+}
+
+declare const artplayerPluginAudioTrack: (option: Option) => (art: Artplayer) => Result
+
+export default artplayerPluginAudioTrack
+
+export = artplayerPluginAudioTrack
+export as namespace artplayerPluginAudioTrack;
+
artplayer-plugin-auto-thumbnail.d.ts
-This plugin automatically generates video thumbnails.
+This plugin automatically generates thumbnails for the video seek bar.
-Configuration options for thumbnail generation:
interface Option {
url?: string
width?: number
@@ -4933,12 +5119,10 @@ interface Option {
scale?: number
}
-Result interface:
interface Result {
name: 'artplayerPluginAutoThumbnail'
}
-Plugin declaration:
declare const artplayerPluginAutoThumbnail: (option: Option) => (art: Artplayer) => Result
export default artplayerPluginAutoThumbnail
@@ -4948,27 +5132,23 @@ export as namespace artplayerPluginAutoThumbnail;
artplayer-plugin-chapter.d.ts
-This plugin provides chapter navigation for videos.
+This plugin adds chapter markers to the video timeline.
-Chapters type definition:
type Chapters = {
start: number
end: number
title: string
}[]
-Chapter plugin configuration:
interface Option {
chapters?: Chapters
}
-Result interface with update method:
interface Result {
name: 'artplayerPluginChapter'
update: (option: Option) => void
}
-Plugin declaration:
declare const artplayerPluginChapter: (option: Option) => (art: Artplayer) => Result
export default artplayerPluginChapter
@@ -4978,9 +5158,8 @@ export as namespace artplayerPluginChapter;
artplayer-plugin-chromecast.d.ts
-This plugin enables Chromecast functionality.
+This plugin enables Google Chromecast support for casting video to external devices.
-Chromecast configuration options:
interface Option {
url?: string
sdk?: string
@@ -4988,12 +5167,10 @@ interface Option {
mimeType?: string
}
-Chromecast interface:
interface Chromecast {
name: 'artplayerPluginChromecast'
}
-Plugin declaration:
declare const artplayerPluginChromecast: (option: Option) => (art: Artplayer) => Chromecast
export default artplayerPluginChromecast
@@ -5003,9 +5180,8 @@ export as namespace artplayerPluginChromecast;
artplayer-plugin-danmuku-mask.d.ts
-This plugin provides masking functionality for danmaku (bullet comments).
+This plugin applies a mask to danmaku (bullet comments) to prevent them from obscuring important content in the video, often using computer vision.
-Configuration options for danmaku masking:
interface Option {
solutionPath?: string
modelSelection?: number
@@ -5019,14 +5195,12 @@ interface Option {
maskBlurAmount?: number
}
-Result interface with async control methods:
interface Result {
name: 'artplayerPluginDanmukuMask'
start: () => Promise
stop: () => void
}
-Plugin declaration:
declare const artplayerPluginDanmukuMask: (option?: Option) => (art: Artplayer) => Result
export default artplayerPluginDanmukuMask
@@ -5036,9 +5210,8 @@ export as namespace artplayerPluginDanmukuMask;
artplayer-plugin-danmuku.d.ts
-This plugin provides comprehensive danmaku (bullet comment) functionality.
+This is the core danmaku (bullet comment) plugin with extensive configuration for display, behavior, and styling.
-Type definitions for danmaku modes and data:
export type Mode = 0 | 1 | 2
export type Danmuku
= | Danmu[]
@@ -5046,7 +5219,6 @@ export type Danmuku
| (() => Promise)
| Promise
-Slider configuration interface:
export interface Slider {
min?: number
max?: number
@@ -5057,98 +5229,114 @@ export interface Slider {
}[]
}
-Individual danmaku item definition:
export interface Danmu {
/**
* 弹幕文本
+ * Danmaku text
*/
text: string
/**
* 弹幕发送模式: 0: 滚动,1: 顶部,2: 底部
+ * Danmaku send mode: 0: scroll, 1: top, 2: bottom
*/
mode?: Mode
/**
* 弹幕颜色
+ * Danmaku color
*/
color?: string
/**
* 弹幕出现的时间,单位为秒
+ * Danmaku appearance time in seconds
*/
time?: number
/**
* 弹幕是否有描边, 默认为 false
+ * Whether the danmaku has a border, default is false
*/
border?: boolean
/**
* 弹幕自定义样式
+ * Danmaku custom style
*/
style?: Partial
}
-Comprehensive danmaku configuration options:
export interface Option {
/**
* 弹幕数据: 函数,数组,Promise,URL
+ * Danmaku data: function, array, Promise, URL
*/
danmuku: Danmuku
/**
* 弹幕持续时间,范围在[1 ~ 10]
+ * Danmaku duration, range [1 ~ 10]
*/
speed?: number
/**
* 弹幕上下边距,支持像素数字和百分比
+ * Danmaku top and bottom margin, supports pixel numbers and percentages
*/
margin?: [number | `${number}%`, number | `${number}%`]
/**
* 弹幕透明度,范围在[0 ~ 1]
+ * Danmaku opacity, range [0 ~ 1]
*/
opacity?: number
/**
* 默认弹幕颜色,可以被单独弹幕项覆盖
+ * Default danmaku color, can be overridden by individual danmaku items
*/
color?: string
/**
* 弹幕模式: 0: 滚动,1: 顶部,2: 底部
+ * Danmaku mode: 0: scroll, 1: top, 2: bottom
*/
mode?: Mode
/**
* 弹幕可见的模式
+ * Visible danmaku modes
*/
modes?: Mode[]
/**
* 弹幕字体大小,支持像素数字和百分比
+ * Danmaku font size, supports pixel numbers and percentages
*/
fontSize?: number | `${number}%`
/**
* 弹幕是否防重叠
+ * Whether danmaku prevents overlap
*/
antiOverlap?: boolean
/**
* 是否同步播放速度
+ * Whether to synchronize with playback speed
*/
synchronousPlayback?: boolean
/**
* 弹幕发射器挂载点, 默认为播放器控制栏中部
+ * Danmaku emitter mount point, defaults to the middle of the player control bar
*/
mount?: HTMLDivElement | string
/**
* 是否开启弹幕热度图
+ * Whether to enable danmaku heatmap
*/
heatmap?:
| boolean
@@ -5167,136 +5355,159 @@ export interface Option {
/**
* 当播放器宽度小于此值时,弹幕发射器置于播放器底部
+ * When player width is less than this value, the danmaku emitter is placed at the bottom of the player
*/
width?: number
/**
* 热力图数据
+ * Heatmap data
*/
points?: { time: number, value: number }[]
/**
* 弹幕载入前的过滤器,只支持返回布尔值
+ * Filter before danmaku loads, only supports returning boolean
*/
filter?: (danmu: Danmu) => boolean
/**
* 弹幕发送前的过滤器,支持返回 Promise
+ * Filter before danmaku is sent, supports returning Promise
*/
beforeEmit?: (danmu: Danmu) => boolean | Promise
/**
* 弹幕显示前的过滤器,支持返回 Promise
+ * Filter before danmaku is displayed, supports returning Promise
*/
beforeVisible?: (danmu: Danmu) => boolean | Promise
/**
* 弹幕是否可见
+ * Whether danmaku is visible
*/
visible?: boolean
/**
* 是否开启弹幕发射器
+ * Whether to enable the danmaku emitter
*/
emitter?: boolean
/**
* 弹幕输入框最大长度, 范围在[1 ~ 1000]
+ * Danmaku input box maximum length, range [1 ~ 1000]
*/
maxLength?: number
/**
* 输入框锁定时间,范围在[1 ~ 60]
+ * Input box lock time, range [1 ~ 60]
*/
lockTime?: number
/**
* 弹幕主题,只在自定义挂载时生效
+ * Danmaku theme, only effective with custom mounting
*/
theme?: 'light' | 'dark'
/**
* 不透明度配置项
+ * Opacity configuration item
*/
OPACITY?: Slider
/**
* 弹幕速度配置项
+ * Danmaku speed configuration item
*/
SPEED?: Slider
/**
* 显示区域配置项
+ * Display area configuration item
*/
MARGIN?: Slider
/**
* 弹幕字号配置项
+ * Danmaku font size configuration item
*/
FONT_SIZE?: Slider
/**
* 颜色列表配置项
+ * Color list configuration item
*/
COLOR?: string[]
}
-Danmaku plugin result with extensive control methods:
export interface Result {
name: 'artplayerPluginDanmuku'
/**
* 发送一条实时弹幕
+ * Send a real-time danmaku
*/
emit: (danmu: Danmu) => Result
/**
* 重载弹幕源,或者切换新弹幕
+ * Reload danmaku source, or switch to new danmaku
*/
load: (danmuku?: Danmuku) => Promise
/**
* 实时改变弹幕配置
+ * Change danmaku configuration in real time
*/
config: (option: Option) => Result
/**
* 隐藏弹幕层
+ * Hide danmaku layer
*/
hide: () => Result
/**
* 显示弹幕层
+ * Show danmaku layer
*/
show: () => Result
/**
* 挂载弹幕输入框
+ * Mount danmaku input box
*/
mount: (el?: HTMLDivElement | string) => void
/**
* 重置弹幕
+ * Reset danmaku
*/
reset: () => Result
/**
* 弹幕配置
+ * Danmaku configuration
*/
option: Option
/**
* 是否隐藏弹幕层
+ * Whether the danmaku layer is hidden
*/
isHide: boolean
/**
* 是否弹幕层停止状态
+ * Whether the danmaku layer is in stopped state
*/
isStop: boolean
}
-Plugin declaration:
declare const artplayerPluginDanmuku: (option: Option) => (art: Artplayer) => Result
export default artplayerPluginDanmuku
@@ -5306,9 +5517,12 @@ export as namespace artplayerPluginDanmuku;
artplayer-plugin-dash-control.d.ts
-This plugin provides DASH streaming quality and audio control.
+This plugin appears to provide control interfaces for DASH (Dynamic Adaptive Streaming over HTTP) playback. The declaration file is incomplete in the provided input.
+
+artplayer-plugin-dash-control.d.ts
+
+This file defines a plugin for controlling DASH (Dynamic Adaptive Streaming over HTTP) quality and audio settings in ArtPlayer.
-Configuration interface for DASH controls:
interface Config {
control?: boolean
setting?: boolean
@@ -5317,22 +5531,32 @@ interface Config {
getName?: (level: object) => string
}
-Plugin declaration with quality and audio configuration:
+The Config interface defines options for a quality or audio control panel.
+- `control`: Whether to show the control element (e.g., a button in the control bar).
+- `setting`: Whether to include this option in the player's settings menu.
+- `title`: The display title for this setting.
+- `auto`: A label for an "Auto" or default selection.
+- `getName`: A function that takes a quality/audio level object and returns a display name for it.
+
declare const artplayerPluginDashControl: (option: { quality?: Config, audio?: Config }) => (art: Artplayer) => {
name: 'artplayerPluginDashControl'
update: () => void
}
-export default artplayerPluginDashControl
+The plugin is a function that takes an options object. This object can have `quality` and/or `audio` properties, each of type `Config`. It returns another function that takes an `Artplayer` instance and returns a plugin object.
+- `name`: Identifies the plugin.
+- `update`: A method to manually refresh the control's state, useful if the available quality/audio levels change dynamically.
+export default artplayerPluginDashControl
export = artplayerPluginDashControl
export as namespace artplayerPluginDashControl;
-artplayer-plugin-document-pip.d.ts
+The plugin is exported for use in different module systems (ES modules, CommonJS) and as a global variable.
-This plugin enables Document Picture-in-Picture (PiP) functionality.
+===== artplayer-plugin-document-pip.d.ts =====
+
+This file defines a plugin for using the Document Picture-in-Picture (PiP) API with ArtPlayer.
-Document PiP configuration options:
interface Option {
width?: number
height?: number
@@ -5340,7 +5564,11 @@ interface Option {
fallbackToVideoPiP?: boolean
}
-Result interface with PiP control methods and status properties:
+The Option interface configures the PiP window.
+- `width` / `height`: The initial dimensions of the PiP window.
+- `placeholder`: A string (likely a URL or CSS value) for a placeholder image.
+- `fallbackToVideoPiP`: If the Document PiP API is not supported, attempt to use the standard Video element PiP API instead.
+
interface Result {
name: 'artplayerPluginDocumentPip'
isSupported: boolean
@@ -5350,225 +5578,525 @@ interface Result {
toggle: () => void
}
-ARTPLAYER TYPE DECLARATION FILES ANALYSIS
+The plugin returns an object with these properties and methods.
+- `name`: Identifies the plugin.
+- `isSupported`: Boolean indicating if the Document PiP API is available in the current browser.
+- `isActive`: Boolean indicating if the PiP window is currently open.
+- `open`: Opens the PiP window.
+- `close`: Closes the PiP window.
+- `toggle`: Toggles the PiP window open or closed.
-===== artplayer-plugin-document-pip.d.ts =====
-
-// Plugin for document-level Picture-in-Picture functionality
declare const artplayerPluginDocumentPip: (option: Option) => (art: Artplayer) => Result
+The plugin function takes an `Option` object and returns a function that takes an `Artplayer` instance and returns the `Result` object.
+
export default artplayerPluginDocumentPip
export = artplayerPluginDocumentPip
export as namespace artplayerPluginDocumentPip;
===== artplayer-plugin-hls-control.d.ts =====
-// Configuration interface for HLS quality and audio controls
+This file defines a plugin for controlling HLS (HTTP Live Streaming) quality and audio settings in ArtPlayer. Its structure is identical to the DASH control plugin.
+
interface Config {
- control?: boolean // Enable control element
- setting?: boolean // Enable settings menu
- title?: string // Display title
- auto?: string // Auto selection label
- getName?: (level: object) => string // Custom name formatter for quality levels
+ control?: boolean
+ setting?: boolean
+ title?: string
+ auto?: string
+ getName?: (level: object) => string
}
-// HLS quality and audio control plugin
declare const artplayerPluginHlsControl: (option: { quality?: Config, audio?: Config }) => (art: Artplayer) => {
name: 'artplayerPluginHlsControl'
- update: () => void // Method to update control states
+ update: () => void
}
export default artplayerPluginHlsControl
export = artplayerPluginHlsControl
export as namespace artplayerPluginHlsControl;
-===== artplayer-tool-iframe.d.ts =====
+===== artplayer-plugin-jassub.d.ts =====
-// Message structure for iframe communication
-interface Message {
- type: string // Message type identifier
- data: any // Message payload
- id?: number // Optional message ID for request-response pattern
+This file defines a plugin for rendering ASS/SSA subtitles using the JASSUB (libass) library in ArtPlayer.
+
+export interface JassubOption {
+ workerUrl: string
+ wasmUrl: string
+ modernWasmUrl: string
+ subUrl?: string
+ subContent?: string
+ timeOffset?: number
+ debug?: boolean
+ prescaleFactor?: number
+ prescaleHeightLimit?: number
+ maxRenderHeight?: number
+ fonts?: string[] | Uint8Array[]
+ availableFonts?: Record
+ fallbackFont?: string
+ useLocalFonts?: boolean
+ libassMemoryLimit?: number
+ libassGlyphLimit?: number
+ [key: string]: any
}
-// Iframe communication plugin for cross-origin player control
-declare class ArtplayerToolIframe {
- constructor(option: { iframe: HTMLIFrameElement, url: string })
+The JassubOption interface configures the subtitle renderer. Key required properties are the URLs for the Web Worker and WebAssembly files.
+- `subUrl` / `subContent`: Provide the subtitle data via URL or direct string content.
+- `fonts`: An array of font URLs or binary data to load.
+- `availableFonts`: A map of font names to their data, pre-loaded for use.
+- Various performance and rendering tuning options like `prescaleFactor`, `libassMemoryLimit`.
- // Static properties and methods
- static iframe: boolean
- static postMessage(message: Message): void
- static onMessage(event: MessageEvent & { data: Message }): void
- static inject(): void
-
- // Instance properties
- readonly promises: Record any, reject: (...args: any[]) => any }>
- readonly injected: boolean // Whether iframe script is injected
- readonly destroyed: boolean // Whether instance is destroyed
- readonly $iframe: HTMLIFrameElement
- readonly url: string
- readonly messageCallback: (...args: any[]) => any
-
- // Instance methods
- onMessage(event: MessageEvent & { data: Message }): void
- postMessage(message: Message): Promise // Send message and await response
- commit any>(callback: T): Promise> // Execute function in iframe context
- message(callback: (...args: any[]) => any): void // Set message handler
- destroy(): void // Cleanup resources
+export interface JassubInstance {
+ resize: (force?: boolean, width?: number, height?: number, top?: number, left?: number) => Promise
+ setVideo: (video: HTMLVideoElement) => Promise
+ destroy: () => Promise
+ [key: string]: any
}
-export default ArtplayerToolIframe
-export = artplayerPluginIframe
-export as namespace artplayerPluginIframe;
+The JassubInstance interface represents the underlying subtitle renderer object, providing methods to control its lifecycle and positioning.
+
+interface Result {
+ name: 'artplayerPluginJassub'
+ instance: JassubInstance
+}
+
+The plugin returns an object containing its name and a reference to the `JassubInstance`, allowing direct access to the renderer's methods.
+
+declare const artplayerPluginJassub: (option: JassubOption) => (art: Artplayer) => Result
+
+export default artplayerPluginJassub
+export = artplayerPluginJassub
+export as namespace artplayerPluginJassub;
===== artplayer-plugin-multiple-subtitles.d.ts =====
-// Plugin for managing multiple subtitle tracks
+This file defines a plugin for managing multiple subtitle tracks in ArtPlayer.
+
declare const artplayerPluginMultipleSubtitles: (option: {
subtitles: {
- url?: string // Subtitle file URL
- name?: string // Display name
- type?: 'vtt' | 'srt' | 'ass' // Subtitle format
- encoding?: string // Text encoding (default: utf-8)
- onParser?: (...args: object[]) => object // Custom parser function
+ url?: string
+ name?: string
+ type?: 'vtt' | 'srt' | 'ass'
+ encoding?: string
+ onParser?: (...args: object[]) => object
}[]
}) => (art: Artplayer) => {
name: 'multipleSubtitles'
}
+The plugin takes an option object with a `subtitles` array. Each item in the array defines a subtitle track.
+- `url`: The source URL of the subtitle file.
+- `name`: The display name for the track.
+- `type`: The format of the subtitle file (WebVTT, SubRip, or ASS/SSA).
+- `encoding`: The text encoding of the file (e.g., 'utf-8').
+- `onParser`: A custom function to parse the subtitle data; receives the raw data and should return a parsed object.
+
+The plugin returns a simple object with its name.
+
export default artplayerPluginMultipleSubtitles
export = artplayerPluginMultipleSubtitles
export as namespace artplayerPluginMultipleSubtitles;
===== artplayer-plugin-vast.d.ts =====
-// VAST (Video Ad Serving Template) plugin for IMA (Interactive Media Ads)
+This file defines a plugin for integrating VAST (Video Ad Serving Template) ads, typically using Google IMA (Interactive Media Ads), into ArtPlayer.
+
declare global {
interface Window {
artplayerPluginVast?: typeof artplayerPluginVast
}
}
-// Function types for ad playback control
-type PlayUrlFn = (url: string) => void
-type PlayResFn = (res: string) => void
+This extends the global Window interface to optionally include the plugin as a property, allowing for global script access.
+
+type PlayUrlFn = (url: string, config?: any) => void
+type PlayResFn = (res: string, config?: any) => void
+
+These are function types for playing an ad by URL (`PlayUrlFn`) or by a VAST response resource (`PlayResFn`).
-// VAST plugin execution context
interface VastPluginContext {
- art: Artplayer // Artplayer instance
- ima: any // Google IMA instance (type any due to external dependency)
- imaPlayer: Player // IMA player instance
- playUrl: PlayUrlFn // Function to play ad by URL
- playRes: PlayResFn // Function to play ad by response
- container: HTMLDivElement | null // Ad container element
+ art: Artplayer
+ ima: any
+ imaPlayer: Player | null
+ playUrl: PlayUrlFn
+ playRes: PlayResFn
+ init: () => Player
+ adsRenderingSettings: any
+ playerOptions: PlayerOptions
+ container: HTMLDivElement | null
}
-// VAST plugin option function type
+The `VastPluginContext` object is passed to the plugin's option function. It provides:
+- The ArtPlayer instance (`art`).
+- References to the IMA SDK (`ima`) and the IMA player instance (`imaPlayer`).
+- Helper functions to play ads (`playUrl`, `playRes`).
+- An `init` function to set up the IMA player.
+- Configuration objects for ads and the player.
+- The DOM container element for the ads.
+
export type ArtplayerPluginVastOption = (params: VastPluginContext) => void | Promise
-// VAST plugin instance interface
+The plugin's option is not a configuration object, but a *function*. This function receives the fully constructed `VastPluginContext` and is responsible for setting up ad events, loading ad tags, etc. It can be async.
+
export interface ArtplayerPluginVastInstance {
name: 'artplayerPluginVast'
- destroy?: () => void // Optional cleanup method
+ destroy?: () => void
}
-// VAST plugin main function
+The plugin instance returned to ArtPlayer. It includes a `destroy` hook for cleanup.
+
declare function artplayerPluginVast(
option: ArtplayerPluginVastOption,
): (art: Artplayer) => ArtplayerPluginVastInstance
+The main plugin function. It takes the setup function (`ArtplayerPluginVastOption`) and returns the standard plugin factory function.
+
export default artplayerPluginVast
export = artplayerPluginVast
export as namespace artplayerPluginVast;
===== artplayer-plugin-vtt-thumbnail.d.ts =====
-// VTT-based thumbnail preview plugin for seek bar
+This file defines a plugin for displaying preview thumbnails on the progress bar using a WebVTT (Web Video Text Tracks) cue file.
+
declare const artplayerPluginVttThumbnail: (option: { vtt?: string, style?: Partial }) => (
art: Artplayer,
) => {
name: 'artplayerPluginVttThumbnail'
}
+The plugin takes an option object.
+- `vtt`: The URL of the WebVTT file that contains the thumbnail cues (mapping time ranges to image URLs).
+- `style`: Optional CSS styles to apply to the thumbnail preview element.
+
+The plugin returns an object with its name.
+
export default artplayerPluginVttThumbnail
export = artplayerPluginVttThumbnail
export as namespace artplayerPluginVttThumbnail;
-===== artplayer.d.ts =====
+===== artplayer-plugin-websr.d.ts =====
+
+This file defines a plugin for real-time video upscaling/super-resolution in the browser using a WebAssembly/WebWorker model.
+
+interface Option {
+ compare?: boolean
+ networkSize?: 'small' | 'medium' | 'large'
+ weightsBaseUrl?: string
+ workerUrl?: string
+ videoScale?: number
+}
+
+Configuration for the upscaler.
+- `compare`: Whether to show a side-by-side comparison of original vs upscaled video.
+- `networkSize`: The size of the neural network model, affecting quality and performance.
+- `weightsBaseUrl`: Base URL for loading the model weight files.
+- `workerUrl`: URL of the Web Worker script.
+- `videoScale`: The scaling factor (e.g., 2 for 2x upscale).
+
+interface Result {
+ name: 'artplayerPluginWebsr'
+ upscaler: any
+ update: (option: Option) => void
+}
+
+The plugin returns its name, a reference to the internal `upscaler` object, and an `update` method to change configuration on the fly.
+
+declare const artplayerPluginWebsr: (option?: Option) => (art: Artplayer) => Result
+
+export default artplayerPluginWebsr
+export = artplayerPluginWebsr
+export as namespace artplayerPluginWebsr;
+
+===== artplayer-proxy-canvas.d.ts =====
+
+This file defines a utility that proxies video playback through an HTMLCanvasElement, allowing for frame-by-frame manipulation.
+
+type Option = (ctx: CanvasRenderingContext2D, video: HTMLVideoElement) => void
+
+The `Option` is a function (a render callback). It receives the canvas's 2D context and the source video element. This function is called repeatedly (e.g., on `requestAnimationFrame`) to draw each video frame onto the canvas, enabling custom filters or effects.
+
+type Result = HTMLCanvasElement
+
+The utility returns the canvas element that is now displaying the processed video.
+
+declare const artplayerProxyCanvas: (option?: Option) => (art: Artplayer) => Result
+
+The main function. If no `option` (render callback) is provided, it likely just copies the video frames to the canvas. It returns a factory function that takes an Artplayer instance and returns the proxy canvas.
+
+export default artplayerProxyCanvas
+export = artplayerProxyCanvas
+export as namespace artplayerProxyCanvas;
+
+===== artplayer-proxy-mediabunny.d.ts =====
+
+This file defines a proxy utility that uses the MediaBunny library (or similar logic) to handle media playback, offering features like precise loading control and AV sync.
+
+interface Option {
+ /**
+ * Timeout for loading media in milliseconds
+ * @default 0
+ */
+ loadTimeout?: number
+
+ /**
+ * Interval for timeupdate events in milliseconds
+ * @default 250
+ */
+ timeupdateInterval?: number
+
+ /**
+ * Audio-video synchronization tolerance in seconds
+ * @default 0.12
+ */
+ avSyncTolerance?: number
+
+ /**
+ * Whether to drop late video frames
+ * @default false
+ */
+ dropLateFrames?: boolean
+
+ /**
+ * Poster image URL
+ */
+ poster?: string
+
+ /**
+ * Media source (URL, Blob, or ReadableStream)
+ */
+ source?: string | Blob | ReadableStream
+
+ /**
+ * Check if server supports range requests before loading
+ * @default false
+ */
+ preflightRange?: boolean
+
+ /**
+ * Initial volume (0-1)
+ * @default 0.7
+ */
+ volume?: number
+
+ /**
+ * Initial muted state
+ * @default false
+ */
+ muted?: boolean
+
+ /**
+ * Autoplay
+ * @default false
+ */
+ autoplay?: boolean
+
+ /**
+ * Loop playback
+ * @default false
+ */
+ loop?: boolean
+
+ /**
+ * Cross-origin setting
+ */
+ crossOrigin?: string
+}
+
+The Option interface provides detailed control over media loading and playback behavior, with JSDoc comments explaining each property.
+
+type Result = HTMLCanvasElement
+
+Similar to `artplayerProxyCanvas`, this utility also outputs a canvas element, which serves as the video render target for the proxied media.
+
+declare const artplayerProxyMediabunny: (option?: Option) => (art: Artplayer) => Result
+
+export default artplayerProxyMediabunny
+export = artplayerProxyMediabunny
+export as namespace artplayerProxyMediabunny;
+
+===== artplayer-tool-iframe.d.ts =====
+
+This file defines a utility class for secure, promise-based communication between a parent page and an ArtPlayer instance embedded within an iframe.
+
+interface Message {
+ type: string
+ data: any
+ id?: number
+}
+
+The structure of messages sent between the window and iframe.
+
+declare class ArtplayerToolIframe {
+ constructor(option: { iframe: HTMLIFrameElement, url: string })
+
+ The constructor takes the target iframe element and a URL. The URL is likely used for origin validation or initial setup.
+
+ static iframe: boolean
+ static postMessage(message: Message): void
+ static onMessage(event: MessageEvent & { data: Message }): void
+ static inject(): void
+
+ Static members. `iframe: boolean` likely indicates if the code is running inside the iframe. `inject()` is called inside the iframe to set up the message listener. `postMessage` and `onMessage` are static handlers.
+
+ readonly promises: Record any, reject: (...args: any[]) => any }>
+ readonly injected: boolean
+ readonly destroyed: boolean
+ readonly $iframe: HTMLIFrameElement
+ readonly url: string
+ readonly messageCallback: (...args: any[]) => any
+
+ Instance properties. `promises` maps message IDs to promise callbacks for request/response patterns. `injected` and `destroyed` track state.
+
+ onMessage(event: MessageEvent & { data: Message }): void
+ postMessage(message: Message): Promise
+ commit any>(callback: T): Promise>
+ message(callback: (...args: any[]) => any): void
+ destroy(): void
+
+ Instance methods.
+ - `onMessage`: Handles incoming messages.
+ - `postMessage`: Sends a message and returns a promise that resolves with the response.
+ - `commit`: A helper that sends a function (as a string) to be executed in the other context and returns its result.
+ - `message`: Sets a general callback for all incoming messages.
+ - `destroy`: Cleans up event listeners.
+
+}
+
+export default ArtplayerToolIframe
+export = artplayerToolIframe
+export as namespace artplayerToolIframe;
+
+===== artplayer.d.ts (partial) =====
+
+This is a fragment from the main ArtPlayer type definitions, showing a utility object.
-// Core Artplayer utility functions
export interface Utils {
- // User agent detection
+ isBrowser: boolean
userAgent: string
isMobile: boolean
isSafari: boolean
isIOS: boolean
isIOS13: boolean
-
- // DOM manipulation utilities
- query: (selector: string, parent?: HTMLElement) => HTMLElement
- queryAll: (selector: string, parent?: HTMLElement) => HTMLElement[]
- addClass: (target: HTMLElement, className: string) => void
- removeClass: (target: HTMLElement, className: string) => void
- hasClass: (target: HTMLElement, className: string) => boolean
- append: (target: HTMLElement, child: HTMLElement) => HTMLElement
- remove: (target: HTMLElement) => void
- replaceElement: (newChild: HTMLElement, oldChild: HTMLElement) => HTMLElement
- siblings: (target: HTMLElement) => HTMLElement[]
- inverseClass: (target: HTMLElement, className: string) => void
- createElement: (tag: K) => HTMLElementTagNameMap[K]
- setStyle: (
- element: HTMLElement,
- key: T,
- value: CSSStyleDeclaration[T],
- ) => HTMLElement
- setStyles: (element: HTMLElement, styles: Partial) => HTMLElement
- getStyle: (
- element: HTMLElement,
- key: K,
- numberType?: boolean,
- ) => boolean extends true ? number : string
- setStyleText: (element: HTMLElement, text: string) => void
- getRect: (el: HTMLElement) => { top: number, left: number, width: number, height: number }
- tooltip: (target: HTMLElement, msg: string, pos?: string) => void
- isInViewport: (target: HTMLElement, offset?: number) => boolean
- includeFromEvent: (event: Event, target: HTMLElement) => boolean
-
- // Subtitle format conversion utilities
- srtToVtt: (srtText: string) => string
- vttToBlob: (vttText: string) => string
- assToVtt: (assText: string) => string
-
- // File and network utilities
- getExt: (url: string) => string
- download: (url: string, name: string) => void
- loadImg: (url: string, scale?: number) => Promise
-
- // Error handling and object utilities
- errorHandle: (condition: T, msg: string) => T extends true ? T : never
- def: (obj: object, name: string, value: unknown) => void
- has: (obj: object, name: PropertyKey) => boolean
- get: (obj: object, name: PropertyKey) => PropertyDescriptor | undefined
- mergeDeep: (...args: T) => T[number]
-
- // Timing and performance utilities
- sleep: (ms: number) => Promise
- debounce: any>(func: F, wait: number, context?: object) => (...args: Parameters) => ReturnType
- throttle: any>(func: F, wait: number) => (...args: Parameters) => ReturnType
-
- // Math and string utilities
- clamp: (num: number, a: number, b: number) => number
- secondToTime: (second: number) => string
- escape: (str: string) => string
- capitalize: (str: string) => string
-
- // UI utilities
- getIcon: (key: string, html: string | HTMLElement) => HTMLElement
- supportsFlex: () => boolean
}
-// Player template structure - references to DOM elements
+The `Utils` interface contains boolean flags and strings for feature and environment detection, useful for writing conditional code for different browsers or platforms.
+
+Here are the TypeScript declaration files for ArtPlayer's APIs, presented as plain text with developer explanations.
+
+UTILITY FUNCTIONS
+These are helper functions provided by ArtPlayer for DOM manipulation, event handling, and common utilities.
+
+query: (selector: string, parent?: Document | HTMLElement) => T | null
+// Selects a single DOM element. Returns null if not found.
+// Example: query('video', container)
+
+queryAll: (selector: string, parent?: Document | HTMLElement) => T[]
+// Selects all matching DOM elements. Returns empty array if none found.
+
+addClass: (target: HTMLElement, className: string) => void
+removeClass: (target: HTMLElement, className: string) => void
+hasClass: (target: HTMLElement, className: string) => boolean
+// Standard CSS class manipulation methods.
+
+append: (target: HTMLElement, child: HTMLElement | string) => Element | ChildNode
+remove: (target: HTMLElement) => HTMLElement
+replaceElement: (newChild: HTMLElement, oldChild: HTMLElement) => HTMLElement
+siblings: (target: HTMLElement) => HTMLElement[]
+inverseClass: (target: HTMLElement, className: string) => void
+// DOM manipulation methods for adding, removing, replacing elements and toggling classes.
+
+createElement: (tag: K) => HTMLElementTagNameMap[K]
+// Creates a typed HTML element with proper TypeScript inference.
+
+setStyle: (
+ element: HTMLElement,
+ key: T,
+ value: string | CSSStyleDeclaration[T],
+) => HTMLElement
+// Sets a single CSS style property with type safety.
+
+setStyles: (element: HTMLElement, styles: Partial) => HTMLElement
+// Sets multiple CSS style properties at once.
+
+getStyle: {
+ (element: HTMLElement, key: keyof CSSStyleDeclaration, numberType?: true): number
+ (element: HTMLElement, key: keyof CSSStyleDeclaration, numberType: false): string
+}
+// Gets computed style values. Can return as number (parsed) or string (raw).
+
+setStyleText: (id: string, cssText: string) => void
+// Injects CSS text into a style element with the given ID.
+
+getRect: (el: HTMLElement) => { top: number, left: number, width: number, height: number }
+// Gets element's bounding rectangle.
+
+tooltip: (target: HTMLElement, msg: string, pos?: string) => void
+// Creates a tooltip attached to an element.
+
+isInViewport: (target: HTMLElement, offset?: number) => boolean
+// Checks if element is visible in viewport.
+
+includeFromEvent: (event: Event, target: HTMLElement) => boolean
+// Checks if event target is within the specified element.
+
+srtToVtt: (srtText: string) => string
+vttToBlob: (vttText: string) => string
+assToVtt: (assText: string) => string
+// Subtitle format conversion utilities.
+
+getExt: (url: string) => string
+// Extracts file extension from URL.
+
+download: (url: string, name: string) => void
+// Triggers file download.
+
+loadImg: (url: string, scale?: number) => Promise
+// Loads image with optional scaling.
+
+errorHandle: (condition: T, msg: string) => T extends true ? T : never
+// Type-safe error handling that throws if condition is false.
+
+def: (obj: object, name: string, value: unknown) => void
+has: (obj: object, name: PropertyKey) => boolean
+get: (obj: object, name: PropertyKey) => PropertyDescriptor | undefined
+// Object property utilities similar to Object.defineProperty.
+
+mergeDeep: (...args: T) => T[number]
+// Deep merges multiple objects.
+
+sleep: (ms: number) => Promise
+// Returns a promise that resolves after specified milliseconds.
+
+debounce: any>(func: F, wait: number, context?: object) => (...args: Parameters) => ReturnType
+throttle: any>(func: F, wait: number) => (...args: Parameters) => ReturnType
+// Standard debounce and throttle implementations for event handlers.
+
+clamp: (num: number, a: number, b: number) => number
+// Restricts number between min and max values.
+
+secondToTime: (second: number) => string
+// Converts seconds to time string (HH:MM:SS).
+
+escape: (str: string) => string
+// Escapes HTML special characters.
+
+capitalize: (str: string) => string
+// Capitalizes first letter of string.
+
+getIcon: (key?: string, html?: string | HTMLElement) => HTMLElement
+// Gets icon element, either from built-in icons or custom HTML.
+
+getComposedPath: (event: Event) => EventTarget[]
+// Gets event path for shadow DOM compatibility.
+
+supportsFlex: () => boolean
+// Feature detection for flexbox support.
+
+TEMPLATE INTERFACE
+Contains references to all DOM elements in the player's template structure.
+
export interface Template {
+ readonly html: string
readonly $container: HTMLDivElement
readonly $player: HTMLDivElement
readonly $video: HTMLVideoElement
@@ -5580,6 +6108,7 @@ export interface Template {
readonly $progress: HTMLDivElement
readonly $controls: HTMLDivElement
readonly $controlsLeft: HTMLDivElement
+ readonly $controlsCenter: HTMLDivElement
readonly $controlsRight: HTMLDivElement
readonly $layer: HTMLDivElement
readonly $loading: HTMLDivElement
@@ -5592,10 +6121,11 @@ export interface Template {
readonly $infoPanel: HTMLDivElement
readonly $infoClose: HTMLDivElement
readonly $contextmenu: HTMLDivElement
- readonly $mini: HTMLDivElement
}
-// Subtitle configuration interface
+SUBTITLE INTERFACE
+Configuration for subtitle tracks.
+
export interface Subtitle {
/**
* The subtitle url
@@ -5622,30 +6152,19 @@ export interface Subtitle {
*/
encoding?: string
-Here are the TypeScript declaration files for ArtPlayer's API, presented as plain text with explanatory notes where helpful.
+ /**
+ * Whether use escape, default true
+ */
+ escape?: boolean
-The SettingOption type combines base properties with additional ones from the Setting type, excluding 'html', 'icon', and 'tooltip' which are redefined.
+ /**
+ * Change the vtt text
+ */
+ onVttLoad?: (vtt: string) => string
+}
-type Props = {
- html: string
- icon: string
- tooltip: string
- $item: HTMLDivElement
- $icon: HTMLDivElement
- $html: HTMLDivElement
- $tooltip: HTMLDivElement
- $switch: HTMLDivElement
- $range: HTMLInputElement
- $parent: Setting
- $parents: Setting[]
- $option: Setting[]
- $events: Array<(...args: unknown[]) => unknown>
- $formatted: boolean
-} & Omit
-
-export type SettingOption = Props
-
-The Setting interface defines the structure for customizable player settings, including display elements and interaction handlers.
+SETTING INTERFACE
+Configuration for player settings menu items.
export interface Setting {
/**
@@ -5724,7 +6243,28 @@ export interface Setting {
[key: string]: any
}
-The Quality interface defines video quality options with display and URL properties.
+SETTING OPTION INTERFACE
+Internal representation of setting items with DOM references.
+
+export interface SettingOption extends Omit {
+ html: string
+ icon: string | undefined
+ tooltip: string | undefined
+ $item: HTMLDivElement
+ $icon: HTMLDivElement | undefined
+ $html: HTMLDivElement
+ $tooltip: HTMLDivElement | undefined
+ $switch: HTMLDivElement | undefined
+ $range: HTMLInputElement | undefined
+ $parent: SettingOption | undefined
+ $parents: SettingOption[]
+ $option: SettingOption[]
+ $events: Array<() => void>
+ $formatted: boolean
+}
+
+QUALITY INTERFACE
+Configuration for video quality options.
export interface Quality {
/**
@@ -5743,57 +6283,80 @@ export interface Quality {
url: string
}
-These type definitions represent various player states and configurations with both predefined and custom values.
+TYPE ALIASES
+Common type definitions used throughout the player.
export type AspectRatio = 'default' | '4:3' | '16:9' | (`${number}:${number}` & Record)
export type PlaybackRate = 0.5 | 0.75 | 1.0 | 1.25 | 1.5 | 1.75 | 2.0 | (number & Record)
export type Flip = 'normal' | 'horizontal' | 'vertical' | (string & Record)
export type State = 'standard' | 'mini' | 'pip' | 'fullscreen' | 'fullscreenWeb'
-The Player class provides the main API for controlling video playback, managing player state, and accessing media properties.
+PLAYER CLASS
+Main player class with getters and setters for player state and properties.
export declare class Player {
get aspectRatio(): AspectRatio
set aspectRatio(ratio: AspectRatio)
+ // Controls video aspect ratio.
get state(): State
set state(state: State)
+ // Current player state (standard, mini, pip, etc.).
get type(): CustomType
set type(name: CustomType)
+ // Video MIME type or custom type.
get playbackRate(): PlaybackRate
set playbackRate(rate: PlaybackRate)
+ // Playback speed multiplier.
get currentTime(): number
set currentTime(time: number)
+ // Current playback time in seconds.
get duration(): number
+ // Total video duration in seconds.
+
get played(): number
+ // Amount of video played in seconds.
+
get playing(): boolean
+ // Whether video is currently playing.
get flip(): Flip
set flip(state: Flip)
+ // Video flip state (normal, horizontal, vertical).
get fullscreen(): boolean
set fullscreen(state: boolean)
+ // Native fullscreen state.
get fullscreenWeb(): boolean
set fullscreenWeb(state: boolean)
+ // Web page fullscreen state.
get loaded(): number
+ // Amount of video loaded as percentage (0-1).
+
get loadedTime(): number
+ // Amount of video loaded in seconds.
get mini(): boolean
set mini(state: boolean)
+ // Mini player mode state.
get pip(): boolean
set pip(state: boolean)
+ // Picture-in-picture mode state.
get poster(): string
set poster(url: string)
+ // Poster image URL.
get rect(): DOMRect
+ // Player's bounding rectangle.
+
get bottom(): number
get height(): number
get left(): number
@@ -5802,64 +6365,101 @@ export declare class Player {
get width(): number
get x(): number
get y(): number
+ // Individual position and dimension properties.
set seek(time: number)
get seek(): number
-
- set forward(time: number)
- get forward(): number
-
- set backward(time: number)
- get backward(): number
-
- get url(): string
- set url(url: string)
-
- get volume(): number
- set volume(percentage: number)
-
- get muted(): boolean
- set muted(state: boolean)
-
- get title(): string
- set title(title: string)
-
- get theme(): string
- set theme(theme: string)
-
- get subtitleOffset(): number
- set subtitleOffset(time: number)
-
- get switch(): string
- set switch(url: string)
-
- get quality(): Quality[]
- set quality(quality: Quality[])
-
- get thumbnails(): Thumbnails
- set thumbnails(thumbnails: Thumbnails)
-
- pause(): void
- play(): Promise
- toggle(): void
-
- attr(key: string, value?: unknown): unknown
- cssVar(key: T, value?: CssVar[T]): CssVar[T]
-
- switchUrl(url: string): Promise
- switchQuality(url: string): Promise
-
- getDataURL(): Promise
- getBlobUrl(): Promise
- screenshot(name?: string): Promise
-
- airplay(): void
- autoSize(): void
- autoHeight(): void
+ // Alias for currentTime, used for seeking.
}
-CustomType defines supported video formats with extensibility for custom types.
+The ArtPlayer class provides the main API for controlling video playback and player configuration.
+export class Artplayer {
+ // Sets the forward jump time in seconds
+ set forward(time: number)
+ // Gets the forward jump time in seconds
+ get forward(): number
+
+ // Sets the backward jump time in seconds
+ set backward(time: number)
+ // Gets the backward jump time in seconds
+ get backward(): number
+
+ // Gets the current video URL
+ get url(): string
+ // Sets the video URL
+ set url(url: string)
+
+ // Gets the current volume percentage (0-1)
+ get volume(): number
+ // Sets the volume percentage (0-1)
+ set volume(percentage: number)
+
+ // Gets whether audio is muted
+ get muted(): boolean
+ // Sets audio mute state
+ set muted(state: boolean)
+
+ // Gets the current theme color
+ get theme(): string
+ // Sets the theme color
+ set theme(theme: string)
+
+ // Gets the subtitle offset time in seconds
+ get subtitleOffset(): number
+ // Sets the subtitle offset time in seconds
+ set subtitleOffset(time: number)
+
+ // Gets the current switch URL
+ get switch(): string
+ // Sets the switch URL for video switching
+ set switch(url: string)
+
+ // Gets the available quality options
+ get quality(): Quality[]
+ // Sets the quality options
+ set quality(quality: Quality[])
+
+ // Gets the thumbnails configuration
+ get thumbnails(): Thumbnails
+ // Sets the thumbnails configuration
+ set thumbnails(thumbnails: Thumbnails)
+
+ // Pauses video playback
+ pause(): void
+ // Starts video playback, returns a promise
+ play(): Promise
+ // Toggles between play and pause states
+ toggle(): void
+
+ // Gets or sets custom attributes on the player element
+ attr(key: string, value?: unknown): unknown
+ // Gets or sets CSS custom properties
+ cssVar(key: T, value?: CssVar[T]): CssVar[T]
+
+ // Switches to a new video URL
+ switchUrl(url: string): Promise
+ // Switches video quality by URL
+ switchQuality(url: string): Promise
+
+ // Gets the video as a data URL
+ getDataURL(): Promise
+ // Gets the video as a blob URL
+ getBlobUrl(): Promise
+ // Takes a screenshot of the current video frame
+ screenshot(name?: string): Promise
+
+ // Initiates AirPlay streaming
+ airplay(): void
+ // Automatically resizes the player to fit its container
+ autoSize(): void
+ // Automatically adjusts player height
+ autoHeight(): void
+ // Resets the player to initial state
+ reset(): void
+}
+
+// CustomType defines supported video formats and allows for custom format extensions
export type CustomType
= | 'flv'
| 'm3u8'
@@ -5869,8 +6469,7 @@ export type CustomType
| 'torrent'
| (string & Record)
-The Thumbnails interface configures video thumbnail previews for seeking.
-
+// Thumbnails interface defines configuration for video preview thumbnails
export interface Thumbnails {
/**
* The thumbnail image url
@@ -5903,8 +6502,7 @@ export interface Thumbnails {
scale?: number
}
-The Option interface defines the complete configuration for initializing an ArtPlayer instance.
-
+// Option interface defines the complete configuration for initializing an ArtPlayer instance
export interface Option {
/**
* The player id
@@ -6084,48 +6682,42 @@ export interface Option {
/**
* Custom video proxy
*/
- proxy?: (this: Artplayer, art: Artplayer) => HTMLCanvasElement | HTMLVideoElement
+ proxy?: (this: Artplayer, art: Artplayer) => HTMLCanvasElement | HTMLVideoElement | undefined
/**
* Custom plugin list
*/
- plugins?: ((this: Artplayer, art: Artplayer) => unknown)[]
-}
+ plugins?: ((this: Artplayer, art: Artplayer) => unknown | Promise)[]
-Here are the TypeScript declaration files for ArtPlayer's API, presented as plain text with explanatory notes where helpful.
+ /**
+ * Custom layer list
+ */
+ layers?: ComponentOption[]
-CUSTOMIZATION OPTIONS
-These properties allow you to customize various aspects of the ArtPlayer interface and functionality.
+ /**
+ * Custom contextmenu list
+ */
+ contextmenu?: ComponentOption[]
-/**
- * Custom layer list
- */
-layers?: ComponentOption[]
+ /**
+ * Custom control list
+ */
+ controls?: ComponentOption[]
-/**
- * Custom contextmenu list
- */
-contextmenu?: ComponentOption[]
+ /**
+ * Custom setting list
+ */
+ settings?: Setting[]
-/**
- * Custom control list
- */
-controls?: ComponentOption[]
+ /**
+ * Custom video quality list
+ */
+ quality?: Quality[]
-/**
- * Custom setting list
- */
-settings?: Setting[]
-
-/**
- * Custom video quality list
- */
-quality?: Quality[]
-
-/**
- * Custom highlight list
- */
-highlight?: {
+ /**
+ * Custom highlight list
+ */
+ highlight?: {
/**
* The highlight time
*/
@@ -6135,95 +6727,90 @@ highlight?: {
* The highlight text
*/
text: string
-}[]
+ }[]
-/**
- * Custom thumbnail
- */
-thumbnails?: Thumbnails
+ /**
+ * Custom thumbnail
+ */
+ thumbnails?: Thumbnails
-/**
- * Custom subtitle option
- */
-subtitle?: Subtitle
+ /**
+ * Custom subtitle option
+ */
+ subtitle?: Subtitle
-/**
- * Other video attribute
- */
-moreVideoAttr?: Partial unknown
- ? never
- : K]: HTMLVideoElement[K]
-}>>
+ ? never
+ : K]: HTMLVideoElement[K]
+ }>>
-Note: moreVideoAttr allows setting additional HTML video element attributes while excluding methods.
+ /**
+ * Custom i18n
+ */
+ i18n?: I18n
-/**
- * Custom i18n
- */
-i18n?: I18n
-
-/**
- * Custom default icons
- */
-icons?: {
+ /**
+ * Custom default icons
+ */
+ icons?: {
[key in keyof Icons]?: HTMLElement | string
-}
+ }
-/**
- * Custom css variables
- */
-cssVar?: Partial
+ /**
+ * Custom css variables
+ */
+ cssVar?: Partial
-/**
- * Custom video type function
- */
-customType?: Partial<
+ /**
+ * Custom video type function
+ */
+ customType?: Partial<
Record<
- CustomType,
- (this: Artplayer, video: HTMLVideoElement, url: string, art: Artplayer) => unknown
+ CustomType,
+ (this: Artplayer, video: HTMLVideoElement, url: string, art: Artplayer) => unknown | Promise
>
->
-
-ICONS INTERFACE
-Defines all available icons in ArtPlayer as HTMLDivElements.
-
-export interface Icons {
- readonly loading: HTMLDivElement
- readonly state: HTMLDivElement
- readonly play: HTMLDivElement
- readonly pause: HTMLDivElement
- readonly check: HTMLDivElement
- readonly volume: HTMLDivElement
- readonly volumeClose: HTMLDivElement
- readonly screenshot: HTMLDivElement
- readonly setting: HTMLDivElement
- readonly pip: HTMLDivElement
- readonly arrowLeft: HTMLDivElement
- readonly arrowRight: HTMLDivElement
- readonly playbackRate: HTMLDivElement
- readonly aspectRatio: HTMLDivElement
- readonly config: HTMLDivElement
- readonly lock: HTMLDivElement
- readonly flip: HTMLDivElement
- readonly unlock: HTMLDivElement
- readonly fullscreenOff: HTMLDivElement
- readonly fullscreenOn: HTMLDivElement
- readonly fullscreenWebOff: HTMLDivElement
- readonly fullscreenWebOn: HTMLDivElement
- readonly switchOn: HTMLDivElement
- readonly switchOff: HTMLDivElement
- readonly error: HTMLDivElement
- readonly close: HTMLDivElement
- readonly airplay: HTMLDivElement
- readonly [key: string]: HTMLDivElement
+ >
}
-I18N INTERNATIONALIZATION
-Defines supported languages and translatable text keys.
+// Icons interface defines all icon elements used in the player UI
+export interface Icons {
+ readonly loading: HTMLDivElement
+ readonly state: HTMLDivElement
+ readonly play: HTMLDivElement
+ readonly pause: HTMLDivElement
+ readonly check: HTMLDivElement
+ readonly volume: HTMLDivElement
+ readonly volumeClose: HTMLDivElement
+ readonly screenshot: HTMLDivElement
+ readonly setting: HTMLDivElement
+ readonly pip: HTMLDivElement
+ readonly arrowLeft: HTMLDivElement
+ readonly arrowRight: HTMLDivElement
+ readonly playbackRate: HTMLDivElement
+ readonly aspectRatio: HTMLDivElement
+ readonly config: HTMLDivElement
+ readonly lock: HTMLDivElement
+ readonly flip: HTMLDivElement
+ readonly unlock: HTMLDivElement
+ readonly fullscreenOff: HTMLDivElement
+ readonly fullscreenOn: HTMLDivElement
+ readonly fullscreenWebOff: HTMLDivElement
+ readonly fullscreenWebOn: HTMLDivElement
+ readonly switchOn: HTMLDivElement
+ readonly switchOff: HTMLDivElement
+ readonly error: HTMLDivElement
+ readonly close: HTMLDivElement
+ readonly airplay: HTMLDivElement
+ readonly [key: string]: HTMLDivElement
+}
+// I18nKeys defines supported language codes with extensibility for custom languages
type I18nKeys
- = | 'en'
+ = | 'en'
| 'zh-cn'
| 'zh-tw'
| 'pl'
@@ -6238,215 +6825,206 @@ type I18nKeys
| 'vi'
| (string & Record)
+// I18nValue defines all translatable text keys used throughout the player interface
interface I18nValue {
- 'Video Info': string
- 'Close': string
- 'Video Load Failed': string
- 'Volume': string
- 'Play': string
- 'Pause': string
- 'Rate': string
- 'Mute': string
- 'Video Flip': string
- 'Horizontal': string
- 'Vertical': string
- 'Reconnect': string
- 'Show Setting': string
- 'Hide Setting': string
- 'Screenshot': string
- 'Play Speed': string
- 'Aspect Ratio': string
- 'Default': string
- 'Normal': string
- 'Open': string
- 'Switch Video': string
- 'Switch Subtitle': string
- 'Fullscreen': string
- 'Exit Fullscreen': string
- 'Web Fullscreen': string
- 'Exit Web Fullscreen': string
- 'Mini Player': string
- 'PIP Mode': string
- 'Exit PIP Mode': string
- 'PIP Not Supported': string
- 'Fullscreen Not Supported': string
- 'Subtitle Offset': string
- 'Last Seen': string
- 'Jump Play': string
- 'AirPlay': string
- 'AirPlay Not Available': string
+ 'Video Info': string
+ 'Close': string
+ 'Video Load Failed': string
+ 'Volume': string
+ 'Play': string
+ 'Pause': string
+ 'Rate': string
+ 'Mute': string
+ 'Video Flip': string
+ 'Horizontal': string
+ 'Vertical': string
+ 'Reconnect': string
+ 'Show Setting': string
+ 'Hide Setting': string
+ 'Screenshot': string
+ 'Play Speed': string
+ 'Aspect Ratio': string
+ 'Default': string
+ 'Normal': string
+ 'Open': string
+ 'Switch Video': string
+ 'Switch Subtitle': string
+ 'Fullscreen': string
+ 'Exit Fullscreen': string
+ 'Web Fullscreen': string
+ 'Exit Web Fullscreen': string
+ 'Mini Player': string
+ 'PIP Mode': string
+ 'Exit PIP Mode': string
+ 'PIP Not Supported': string
+ 'Fullscreen Not Supported': string
+ 'Subtitle Offset': string
+ 'Last Seen': string
+ 'Jump Play': string
+ 'AirPlay': string
+ 'AirPlay Not Available': string
}
+// I18n type defines the structure for internationalization support with partial overrides
export type I18n = Partial>>
-I18N MODULE DECLARATION
-For importing language files from the artplayer/i18n directory.
-
+// Module declaration for importing language files from the i18n directory
declare module 'artplayer/i18n/*' {
- const lang: Partial
- // @ts-expect-error TS2666
- export default lang
+ const lang: Partial
+ // @ts-expect-error TS2666
+ export default lang
}
-PROGRESS BAR TYPES
+// Bar type defines the different progress bar segments in the player
export type Bar = 'loaded' | 'played' | 'hover'
-EVENTS INTERFACE
-Defines all events that ArtPlayer can emit, categorized by source.
+The Events interface defines all the events that can be emitted by the ArtPlayer instance. Each property key is the event name, and its value is a tuple type describing the arguments passed to the event listener.
export interface Events {
- // Document events
- 'document:click': [event: Event]
- 'document:mouseup': [event: Event]
- 'document:keydown': [event: Event]
- 'document:touchend': [event: Event]
- 'document:touchmove': [event: Event]
- 'document:mousemove': [event: Event]
- 'document:pointerup': [event: Event]
- 'document:contextmenu': [event: Event]
- 'document:pointermove': [event: Event]
- 'document:visibilitychange': [event: Event]
- 'document:webkitfullscreenchange': [event: Event]
+ 'document:click': [event: Event]
+ 'document:mouseup': [event: Event]
+ 'document:keydown': [event: Event]
+ 'document:touchend': [event: Event]
+ 'document:touchmove': [event: Event]
+ 'document:mousemove': [event: Event]
+ 'document:pointerup': [event: Event]
+ 'document:contextmenu': [event: Event]
+ 'document:pointermove': [event: Event]
+ 'document:visibilitychange': [event: Event]
+ 'document:webkitfullscreenchange': [event: Event]
- // Window events
- 'window:resize': [event: Event]
- 'window:scroll': [event: Event]
- 'window:orientationchange': [event: Event]
+ 'window:resize': [event: Event]
+ 'window:scroll': [event: Event]
+ 'window:orientationchange': [event: Event]
- // Video element events
- 'video:canplay': [event: Event]
- 'video:canplaythrough': [event: Event]
- 'video:complete': [event: Event]
- 'video:durationchange': [event: Event]
- 'video:emptied': [event: Event]
- 'video:ended': [event: Event]
- 'video:error': [error: Error]
- 'video:loadeddata': [event: Event]
- 'video:loadedmetadata': [event: Event]
- 'video:pause': [event: Event]
- 'video:play': [event: Event]
- 'video:playing': [event: Event]
- 'video:progress': [event: Event]
- 'video:ratechange': [event: Event]
- 'video:seeked': [event: Event]
- 'video:seeking': [event: Event]
- 'video:stalled': [event: Event]
- 'video:suspend': [event: Event]
- 'video:timeupdate': [event: Event]
- 'video:volumechange': [event: Event]
- 'video:waiting': [event: Event]
+ 'video:abort': [event: Event]
+ 'video:canplay': [event: Event]
+ 'video:canplaythrough': [event: Event]
+ 'video:complete': [event: Event]
+ 'video:durationchange': [event: Event]
+ 'video:emptied': [event: Event]
+ 'video:encrypted': [event: Event]
+ 'video:ended': [event: Event]
+ 'video:error': [error: Error]
+ 'video:loadeddata': [event: Event]
+ 'video:loadedmetadata': [event: Event]
+ 'video:loadstart': [event: Event]
+ 'video:pause': [event: Event]
+ 'video:play': [event: Event]
+ 'video:playing': [event: Event]
+ 'video:progress': [event: Event]
+ 'video:ratechange': [event: Event]
+ 'video:seeked': [event: Event]
+ 'video:seeking': [event: Event]
+ 'video:stalled': [event: Event]
+ 'video:suspend': [event: Event]
+ 'video:timeupdate': [event: Event]
+ 'video:volumechange': [event: Event]
+ 'video:waiting': [event: Event]
- // UI state events
- 'info': [state: boolean]
- 'layer': [state: boolean]
- 'loading': [state: boolean]
- 'mask': [state: boolean]
- 'subtitle': [state: boolean]
- 'contextmenu': [state: boolean]
- 'control': [state: boolean]
- 'setting': [state: boolean]
- 'hotkey': [event: Event]
+ 'info': [state: boolean]
+ 'layer': [state: boolean]
+ 'loading': [state: boolean]
+ 'mask': [state: boolean]
+ 'subtitle': [state: boolean]
+ 'contextmenu': [state: boolean]
+ 'control': [state: boolean]
+ 'setting': [state: boolean]
+ 'hotkey': [event: KeyboardEvent]
- // Player lifecycle events
- 'destroy': []
+ 'destroy': []
- // Subtitle events
- 'subtitleOffset': [offset: number]
- 'subtitleBeforeUpdate': [cue: VTTCue]
- 'subtitleAfterUpdate': [cue: VTTCue]
- 'subtitleLoad': [cues: VTTCue[], option: Subtitle]
+ 'subtitleOffset': [offset: number]
+ 'subtitleBeforeUpdate': [cue: VTTCue]
+ 'subtitleAfterUpdate': [cue: VTTCue]
+ 'subtitleLoad': [cues: VTTCue[], option: Subtitle]
- // User interaction events
- 'focus': [event: Event]
- 'blur': [event: Event]
- 'dblclick': [event: Event]
- 'click': [event: Event]
- 'hover': [state: boolean, event: Event]
- 'mousemove': [event: Event]
+ 'focus': [event: Event]
+ 'blur': [event: Event]
+ 'dblclick': [event: Event]
+ 'click': [event: Event]
+ 'hover': [state: boolean, event: Event]
+ 'mousemove': [event: Event]
- // Player state events
- 'resize': []
- 'view': [state: boolean]
- 'lock': [state: boolean]
- 'aspectRatio': [aspectRatio: AspectRatio]
- 'autoHeight': [height: number]
- 'autoSize': []
- 'ready': []
+ 'resize': []
+ 'view': [state: boolean]
+ 'lock': [state: boolean]
+ 'aspectRatio': [aspectRatio: AspectRatio]
+ 'autoHeight': [height: number]
+ 'autoSize': [size: { width: number, height: number }]
+ 'ready': []
+ 'airplay': []
+ 'raf': []
- // Player functionality events
- 'error': [error: Error, reconnectTime: number]
- 'flip': [flip: Flip]
- 'fullscreen': [state: boolean]
- 'fullscreenError': [event: Event]
- 'fullscreenWeb': [state: boolean]
- 'mini': [state: boolean]
- 'pause': []
- 'pip': [state: boolean]
- 'play': []
- 'screenshot': [dataUri: string]
- 'seek': [currentTime: number]
- 'restart': [url: string]
- 'muted': [state: boolean]
- 'setBar': [type: Bar, percentage: number, event?: Event | undefined]
- 'keydown': [event: KeyboardEvent]
+ 'error': [error: Error, reconnectTime: number]
+ 'flip': [flip: Flip]
+ 'fullscreen': [state: boolean]
+ 'fullscreenError': [event: Event]
+ 'fullscreenWeb': [state: boolean]
+ 'mini': [state: boolean]
+ 'pause': []
+ 'pip': [state: boolean]
+ 'play': []
+ 'screenshot': [dataUri: string]
+ 'seek': [currentTime: number, time: number]
+ 'restart': [url: string]
+ 'muted': [state: boolean]
+ 'setBar': [type: Bar, percentage: number, event?: Event | undefined]
+ 'keydown': [event: KeyboardEvent]
}
-CSS VARIABLES INTERFACE
-Defines all customizable CSS variables for styling the player.
+The CssVar interface defines a set of CSS custom properties (variables) used to theme and style the ArtPlayer UI. These variables control colors, sizes, spacing, and other visual aspects.
export interface CssVar {
- '--art-theme': string
- '--art-font-color': string
- '--art-background-color': string
- '--art-text-shadow-color': string
- '--art-transition-duration': string
- '--art-padding': string
- '--art-border-radius': string
- '--art-progress-height': string
- '--art-progress-color': string
- '--art-progress-top-gap': string
- '--art-hover-color': string
- '--art-loaded-color': string
- '--art-state-size': string
- '--art-state-opacity': number
- '--art-bottom-height': string
- '--art-bottom-offset': string
- '--art-bottom-gap': string
- '--art-highlight-width': string
- '--art-highlight-color': string
- '--art-control-height': string
- '--art-control-opacity': number
- '--art-control-icon-size': string
- '--art-control-icon-scale': number
- '--art-volume-height': string
- '--art-volume-handle-size': string
- '--art-lock-size': string
- '--art-indicator-scale': number
- '--art-indicator-size': string
- '--art-fullscreen-web-index': 9999
- '--art-settings-icon-size': string
- '--art-settings-max-height': string
- '--art-selector-max-height': string
- '--art-contextmenus-min-width': string
- '--art-subtitle-font-size': string
- '--art-subtitle-gap': string
- '--art-subtitle-bottom': string
- '--art-subtitle-border': string
- '--art-widget-background': string
- '--art-tip-background': string
- '--art-scrollbar-size': string
- '--art-scrollbar-background': string
- '--art-scrollbar-background-hover': string
- '--art-mini-progress-height': string
+ '--art-theme': string
+ '--art-font-color': string
+ '--art-background-color': string
+ '--art-text-shadow-color': string
+ '--art-transition-duration': string
+ '--art-padding': string
+ '--art-border-radius': string
+ '--art-progress-height': string
+ '--art-progress-color': string
+ '--art-progress-top-gap': string
+ '--art-hover-color': string
+ '--art-loaded-color': string
+ '--art-state-size': string
+ '--art-state-opacity': number
+ '--art-bottom-height': string
+ '--art-bottom-offset': string
+ '--art-bottom-gap': string
+ '--art-highlight-width': string
+ '--art-highlight-color': string
+ '--art-control-height': string
+ '--art-control-opacity': number
+ '--art-control-icon-size': string
+ '--art-control-icon-scale': number
+ '--art-volume-height': string
+ '--art-volume-handle-size': string
+ '--art-lock-size': string
+ '--art-indicator-scale': number
+ '--art-indicator-size': string
+ '--art-fullscreen-web-index': 9999
+ '--art-settings-icon-size': string
+ '--art-settings-max-height': string
+ '--art-selector-max-height': string
+ '--art-contextmenus-min-width': string
+ '--art-subtitle-font-size': string
+ '--art-subtitle-gap': string
+ '--art-subtitle-bottom': string
+ '--art-subtitle-border': string
+ '--art-widget-background': string
+ '--art-tip-background': string
+ '--art-scrollbar-size': string
+ '--art-scrollbar-background': string
+ '--art-scrollbar-background-hover': string
+ '--art-mini-progress-height': string
}
-Here are the TypeScript declaration files for ArtPlayer with developer explanations:
-
-CONFIG INTERFACE
-The Config interface defines the core HTML5 video API properties, methods, events, and prototypes that ArtPlayer supports.
+The Config interface defines a readonly structure that categorizes the properties, methods, events, and prototypes that ArtPlayer can proxy from the underlying video element. This is used for internal management and validation.
export interface Config {
- properties: [
+ readonly properties: readonly [
'audioTracks',
'autoplay',
'buffered',
@@ -6477,8 +7055,8 @@ export interface Config {
'videoTracks',
'volume',
]
- methods: ['addTextTrack', 'canPlayType', 'load', 'play', 'pause']
- events: [
+ readonly methods: readonly ['addTextTrack', 'canPlayType', 'load', 'play', 'pause']
+ readonly events: readonly [
'abort',
'canplay',
'canplaythrough',
@@ -6502,7 +7080,7 @@ export interface Config {
'volumechange',
'waiting',
]
- prototypes: [
+ readonly prototypes: readonly [
'width',
'height',
'videoWidth',
@@ -6527,8 +7105,7 @@ export interface Config {
]
}
-SELECTOR INTERFACE
-Used for custom dropdown selectors in controls, allowing HTML content and custom properties.
+The Selector interface defines the structure for an item within a dropdown or selection component, such as a settings menu item.
export interface Selector {
/**
@@ -6541,14 +7118,18 @@ export interface Selector {
*/
html: string | HTMLElement
+ /**
+ * Value of selector item
+ */
+ value?: string | number
+
/**
* Allow custom properties
*/
[key: string]: any
}
-COMPONENT INTERFACE
-Represents UI components that can be added to the player controls with lifecycle methods.
+The Component interface represents an instance of a UI component (like a button or control) within ArtPlayer. It provides methods to manage the component's visibility and lifecycle.
export interface Component {
/**
@@ -6584,7 +7165,7 @@ export interface Component {
/**
* Dynamic add a component
*/
- add: (option: ComponentOption) => HTMLElement
+ add: (option: ComponentOption | ((art: Artplayer) => ComponentOption)) => HTMLElement | undefined
/**
* Dynamic remove a component by name
@@ -6594,11 +7175,10 @@ export interface Component {
/**
* Dynamic update a component
*/
- update: (option: ComponentOption) => HTMLElement
+ update: (option: ComponentOption) => HTMLElement | undefined
}
-COMPONENT OPTION INTERFACE
-Configuration options for creating custom components with events, styling, and positioning.
+The ComponentOption interface defines the configuration object used to create or update a UI component. It includes the component's content, behavior, and lifecycle hooks.
export interface ComponentOption {
/**
@@ -6650,21 +7230,23 @@ export interface ComponentOption {
* Component position, use in controls
*/
position?: 'top' | 'left' | 'right' | (string & Record)
-
- /**
- * Custom selector list, use in controls
- */
- selector?: Selector[]
-
- /**
- * When selector item click, use in controls
- */
- onSelect?: (this: Artplayer, selector: Selector, element: HTMLElement, event: Event) => void
}
-TYPE EXPORTS
-These types are defined elsewhere but exported for external use.
+/**
+ * Custom selector list, used in controls for dropdowns or menus.
+ * Each selector item typically includes a label and a value.
+ */
+selector?: Selector[]
+/**
+ * Callback when a selector item is clicked, used in controls.
+ * Provides the ArtPlayer instance, the clicked selector item, its HTML element, and the event.
+ */
+onSelect?: (this: Artplayer, selector: Selector, element: HTMLElement, event: Event) => void
+
+}
+
+// Export all major types for external use.
export type {
Config,
Events,
@@ -6679,31 +7261,26 @@ export type {
Utils,
}
-ART PLAYER CLASS
-The main ArtPlayer class that extends the base Player with extensive configuration and plugin support.
-
+// The main ArtPlayer class, extending the base Player class.
export default class Artplayer extends Player {
+ // Constructor: initializes the player with an option object and an optional ready callback.
constructor(option: Option, readyCallback?: (this: Artplayer, art: Artplayer) => unknown)
-STATIC PROPERTIES
-Global static properties shared across all ArtPlayer instances.
-
- static readonly instances: Artplayer[]
- static readonly version: string
- static readonly env: string
- static readonly build: string
- static readonly config: Config
- static readonly utils: Utils
- static readonly scheme: Record
- static readonly Emitter: new (...args: unknown[]) => unknown
- static readonly validator: (option: T, scheme: object) => T
- static readonly kindOf: (item: unknown) => string
- static readonly html: Artplayer['template']['html']
- static readonly option: Option
-
-CONSTANTS
-Configuration constants that control player behavior and timing.
+ // Static properties: global across all ArtPlayer instances.
+ static readonly instances: Artplayer[] // Array of all active ArtPlayer instances.
+ static readonly version: string // Current version string.
+ static readonly env: 'development' | 'production' // Build environment.
+ static readonly build: string // Build identifier or timestamp.
+ static readonly config: Config // Global configuration object.
+ static readonly utils: Utils // Utility functions.
+ static readonly scheme: Record // Schema for option validation.
+ static readonly Emitter: new (...args: unknown[]) => unknown // Event emitter constructor.
+ static readonly validator: (option: T, scheme: object) => T // Validates options against a scheme.
+ static readonly kindOf: (item: unknown) => string // Type detection utility.
+ static readonly html: Artplayer['template']['html'] // HTML template string.
+ static readonly option: Option // Default option object.
+ // Static constants: configuration defaults for the player.
static STYLE: string
static DEBUG: boolean
static CONTEXTMENU: boolean
@@ -6739,21 +7316,17 @@ Configuration constants that control player behavior and timing.
static USE_RAF: boolean
static REMOVE_SRC_WHEN_DESTROY: boolean
-INSTANCE PROPERTIES
-Read-only properties for individual player instances.
-
- readonly id: number
- readonly option: Option
- readonly isLock: boolean
- readonly isReady: boolean
- readonly isFocus: boolean
- readonly isInput: boolean
- readonly isRotate: boolean
- readonly isDestroy: boolean
-
-PLUGIN SUPPORT
-Optional properties for various video format plugins.
+ // Instance properties: state flags and identifiers for a single player.
+ readonly id: number // Unique identifier for this instance.
+ readonly option: Option // The option object used to create this instance.
+ readonly isLock: boolean // Whether the player is locked (e.g., during loading).
+ readonly isReady: boolean // Whether the player is fully initialized.
+ readonly isFocus: boolean // Whether the player has focus.
+ readonly isInput: boolean // Whether an input element within the player is focused.
+ readonly isRotate: boolean // Whether the video is rotated (e.g., for mobile orientation).
+ readonly isDestroy: boolean // Whether the player has been destroyed.
+ // Optional properties for external libraries (e.g., for streaming formats).
flv?: unknown
m3u8?: unknown
hls?: unknown
@@ -6761,9 +7334,9 @@ Optional properties for various video format plugins.
mpd?: unknown
torrent?: unknown
-EVENT SYSTEM
-Typed event system for handling player events with generic and string-based overloads.
-
+ // Event handling methods: on, once, emit, and off.
+ // These allow binding, triggering, and removing event listeners.
+ // Generic versions for typed events and fallback for custom string events.
on(name: T, fn: (...args: Events[T]) => unknown, ctx?: object): this
on(name: string, fn: (...args: unknown[]) => unknown, ctx?: object): this
@@ -6776,156 +7349,121 @@ Typed event system for handling player events with generic and string-based over
off(name: T, callback?: (...args: Events[T]) => unknown): this
off(name: string, callback?: (...args: unknown[]) => unknown): this
-CONVENIENCE PROPERTIES
-Shortcut properties for commonly accessed functionality.
-
- query: Artplayer['template']['query']
- proxy: Artplayer['events']['proxy']
- video: Artplayer['template']['$video']
-
-INTERNAL EVENT STORAGE
-Internal structure for storing event listeners.
+ // Convenience shortcuts to commonly accessed properties.
+ query: Artplayer['template']['query'] // Query selector within the player's template.
+ proxy: Artplayer['events']['proxy'] // Event proxy utility.
+ video: Artplayer['template']['$video'] // Reference to the video element.
+ // Internal event storage: maps event names to arrays of listener functions and contexts.
e: { [K in keyof Events]?: { fn: (...args: Events[K]) => unknown, ctx: unknown }[] }
-DESTRUCTION METHOD
-Clean up the player instance and optionally remove HTML from DOM.
-
+ // Lifecycle methods: destroy removes the player, reset returns it to initial state.
destroy(removeHtml?: boolean): void
+ reset(): void
-TEMPLATE SYSTEM
-Handles the player's HTML structure and DOM queries.
-
+ // Template property: provides HTML and DOM querying for the player's UI.
readonly template: {
- get html(): string
- query: (str: string) => HTMLElement
- } & Template
-
-EVENT MANAGEMENT
-Comprehensive event handling system with proxy, hover, and global event binding.
+ get html(): string // Returns the HTML string of the player's template.
+ query: (selector: string) => T | null // Queries elements within the template.
+ } & Template // Extends with additional template-related methods.
+ // Events property: manages event listeners and global event binding.
readonly events: {
- proxy: (
- element: HTMLDivElement | Document | Window,
- eventName: KW | KH,
- handler: (event: WindowEventMap[KW] | HTMLElementEventMap[KH] | Event) => void,
- options?: boolean | AddEventListenerOptions,
- ) => () => void
- hover: (element: HTMLElement, mouseenter?: (event: Event) => any, mouseleave?: (event: Event) => any) => void
- remove: (event: Event) => void
- bindGlobalEvents: (source?: { window?: Window, document?: Document }) => void
+ proxy: {
+ // Proxies an event listener, returning a removal function. Can handle single or multiple event names.
+ (target: EventTarget, eventName: string, handler: (event: Event) => void, options?: boolean | AddEventListenerOptions): () => void
+ (target: EventTarget, eventName: string[], handler: (event: Event) => void, options?: boolean | AddEventListenerOptions): Array<() => void>
+ }
+ hover: (element: HTMLElement, mouseenter?: (event: Event) => any, mouseleave?: (event: Event) => any) => void // Binds hover events.
+ remove: (destroyEvent: () => void) => void // Removes a specific event listener.
+ destroy: () => void // Removes all event listeners.
+ bindGlobalEvents: (source?: { window?: Window, document?: Document }) => void // Binds global window/document events.
}
-STORAGE SYSTEM
-Persistent storage for player settings and user preferences.
-
+ // Storage property: manages persistent settings (e.g., volume, playback speed) via localStorage.
readonly storage: {
- name: string
- settings: Record
- get: (key: string) => unknown
- set: (key: string, value: unknown) => void
- del: (key: string) => boolean
- clear: () => void
+ name: string // Storage key prefix.
+ settings: Record // Current settings in memory.
+ get: {
+ (key: string): unknown // Gets a value by key.
+ (): Record // Gets all settings.
+ }
+ set: (key: string, value: unknown) => void // Sets a value.
+ del: (key: string) => void // Deletes a key.
+ clear: () => void // Clears all settings.
}
-ICON MANAGEMENT
-Handles player icons and UI symbols.
-
+ // Icons property: contains SVG icon strings for UI elements.
readonly icons: Icons
-INTERNATIONALIZATION (I18N)
-Multi-language support system for player UI text.
-
+ // i18n property: handles internationalization and language switching.
readonly i18n: {
- readonly languages: I18n
- get: (key: string) => string
- update: (language: Partial) => void
+ languages: I18n // All available language packs.
+ language: Partial> // Current language dictionary.
+ init: () => void // Initializes i18n with default language.
+ get: (key: string) => string // Gets a translated string by key.
+ update: (language: Partial) => void // Updates the language pack.
}
-NOTIFICATION SYSTEM
-Temporary message display system for user feedback.
-
+ // Notice property: manages temporary notification messages.
readonly notice: {
- timer: number
- set show(msg: string)
+ timer: number | null // Timer ID for auto-hiding.
+ get show(): boolean // Returns whether a notice is currently showing.
+ set show(msg: string | Error | false | '') // Shows a notice (string or Error) or hides it (false or empty string).
+ destroy: () => void // Clears any active notice.
}
-Below is the plain text output of the TypeScript declaration file for ArtPlayer's API, with added explanations for clarity.
+ // Layers, controls, and contextmenu: UI components that can be added or removed.
+ // Each is a Record of HTML elements by name, extended with Component methods (add, remove, show, hide).
+ readonly layers: Record & Component
+ readonly controls: Record & Component
+ readonly contextmenu: Record & Component
-// ArtPlayer class definition containing core player components and methods
-class Artplayer {
- // Layers component: a record of named HTML elements combined with Component functionality for UI layers
- readonly layers: Record & Component
-
- // Controls component: manages player control elements (e.g., play, pause buttons) as HTML elements with Component features
- readonly controls: Record & Component
-
- // Contextmenu component: handles right-click context menu items as HTML elements with Component behavior
- readonly contextmenu: Record & Component
-
- // Subtitle component: provides subtitle management, including URL handling, text track access, and styling
+ // Subtitle property: manages subtitle loading, switching, and styling.
readonly subtitle: {
- // Gets the current subtitle URL
- get url(): string
- // Sets the subtitle URL to load new subtitles
- set url(url: string)
- // Retrieves the active TextTrack object for subtitles
- get textTrack(): TextTrack
- // Returns an array of currently active VTTCue objects (visible subtitle cues)
- get activeCues(): VTTCue[]
- // Returns all VTTCue objects in the subtitle track
- get cues(): VTTCue[]
- // Applies CSS styles to subtitles; can set a single property or multiple via a partial style object
- style: (name: string | Partial, value?: string) => void
- // Switches to a new subtitle URL with optional configuration, returning a promise that resolves to the URL
- switch: (url: string, option?: Subtitle) => Promise
- } & Component
+ get url(): string // Current subtitle URL.
+ set url(url: string) // Sets subtitle URL and loads it.
+ get textTrack(): TextTrack | undefined // The underlying TextTrack object.
+ get activeCues(): VTTCue[] // Currently active subtitle cues.
+ get cues(): VTTCue[] // All subtitle cues.
+ style: (name: string | Partial, value?: string) => void // Applies CSS styles to subtitles.
+ switch: (url: string, option?: Subtitle) => Promise // Switches to a new subtitle.
+ init: (subtitle: Subtitle) => Promise // Initializes subtitles from an option.
+ } & Component // Extended with Component methods.
- // Info component: displays player information (e.g., title, duration) as a Component
+ // Info and loading: simple UI components for displaying video info and loading indicators.
readonly info: Component
-
- // Loading component: shows loading indicators or states during media buffering
readonly loading: Component
- // Hotkey component: manages keyboard shortcuts with methods to add or remove key event listeners
+ // Hotkey property: manages keyboard shortcuts.
readonly hotkey: {
- // Record of key names to arrays of callback functions triggered on key events
- keys: Record any)[]>
- // Adds a hotkey listener for a specific key, with a callback that has Artplayer context
- add: (key: string, callback: (this: Artplayer, event: Event) => any) => Artplayer['hotkey']
- // Removes a specific callback for a key event
- remove: (key: string, callback: (event: Event) => any) => Artplayer['hotkey']
+ keys: Record any)[]> // Map of key names to callback arrays.
+ add: (key: string, callback: (this: Artplayer, event: KeyboardEvent) => any) => Artplayer['hotkey'] // Adds a hotkey.
+ remove: (key: string, callback: (event: KeyboardEvent) => any) => Artplayer['hotkey'] // Removes a hotkey.
}
- // Mask component: typically used for overlays like error messages or custom UI masks
+ // Mask property: a UI component for overlays (e.g., for ads or pauses).
readonly mask: Component
- // Setting component: handles player settings menu, including options management and UI updates
+ // Setting property: manages the settings menu (e.g., playback speed, quality).
readonly setting: {
- // Array of setting options available in the player
- option: SettingOption[]
- // Updates the styling of the settings menu, optionally adjusting width
- updateStyle: (width?: number) => void
- // Finds a setting option by its name
- find: (name: string) => SettingOption
- // Adds a new setting to the menu
- add: (setting: Setting) => SettingOption[]
- // Updates existing settings with new values
- update: (settings: Setting) => SettingOption[]
- // Removes a setting by name
- remove: (name: string) => SettingOption[]
- } & Component
+ option: SettingOption[] // Array of available setting options.
+ updateStyle: (width?: number) => void // Updates the menu's width.
+ find: (name: string) => SettingOption | undefined // Finds a setting by name.
+ add: (setting: Setting) => Artplayer['setting'] // Adds a new setting.
+ update: (settings: Setting) => Artplayer['setting'] // Updates existing settings.
+ remove: (name: string) => Artplayer['setting'] // Removes a setting by name.
+ } & Component // Extended with Component methods.
- // Plugins component: allows extending player functionality with custom plugins
+ // Plugins property: allows extending the player with custom functionality.
readonly plugins: {
- // Adds a plugin function that receives the Artplayer instance; can be synchronous or asynchronous
add: (
plugin: (this: Artplayer, art: Artplayer) => unknown | Promise,
- ) => Promise | Artplayer['plugins']
- } & Record // Also acts as a record for storing plugin instances by name
+ ) => Promise // Adds a plugin, which can be synchronous or asynchronous.
+ } & Record // Plugins are stored as key-value pairs.
}
-// Exports Artplayer for use in modules and as a global namespace in non-module contexts
+// Export for CommonJS and as a global variable in browser environments.
export = Artplayer
export as namespace Artplayer;
@@ -6933,7 +7471,11 @@ export as namespace Artplayer;
===== Examples Summary =====
-ads.js example code:
+ads.js example: This example demonstrates how to integrate the artplayer-plugin-ads plugin to display HTML or video advertisements before or during video playback. It uses the Artplayer constructor and the artplayerPluginAds plugin API. The configuration shows setting an HTML image ad, a video ad URL, a click-through link, mandatory watch duration, and total ad duration. It also attaches event listeners for when the ad is clicked or skipped.
+
+// npm i artplayer-plugin-ads
+// import artplayerPluginAds from 'artplayer-plugin-ads';
+
const art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -6980,9 +7522,11 @@ art.on('artplayerPluginAds:skip', (ads) => {
console.info('广告被跳过', ads)
})
-This example demonstrates the ads plugin for ArtPlayer, showing how to configure and display advertisements before video playback. It uses the artplayerPluginAds API to set up both HTML and video ads with configurable duration, skip options, and internationalization. The code also shows event handling for ad clicks and skips.
+ambilight.js example: This example shows the use of the artplayer-plugin-ambilight plugin to create an ambient lighting effect around the video player. It uses the Artplayer constructor and the artplayerPluginAmbilight plugin API. The feature demonstrated is a dynamic color border that samples video content, with configurable blur, opacity, update frequency, and transition duration.
+
+// npm i artplayer-plugin-ambilight
+// import artplayerPluginAmbilight from 'artplayer-plugin-ambilight';
-ambilight.js example code:
const art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -6997,9 +7541,8 @@ const art = new Artplayer({
],
})
-This example demonstrates the ambilight plugin for ArtPlayer, which creates ambient lighting effects around the video player. It uses the artplayerPluginAmbilight API with configurable blur, opacity, frequency, and duration parameters to customize the lighting effect.
+asr.js example: This example demonstrates using a plugin (presumably artplayer-plugin-asr) for Automatic Speech Recognition (ASR) to generate live subtitles from video audio. It uses the Artplayer constructor and a plugin configuration that processes audio chunks. The example includes a custom WebSocket implementation to send PCM audio data to an external ASR service and append the recognized text to the player as subtitles.
-asr.js example code:
const art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/steve-jobs.mp4',
@@ -7062,9 +7605,28 @@ async function startAsr(buffer) {
art.on('destroy', stopAsr)
-This example demonstrates automatic speech recognition (ASR) integration with ArtPlayer using the artplayerPluginAsr plugin. It shows real-time audio processing and WebSocket communication with an ASR service to generate live subtitles. The plugin captures audio chunks and sends them to a speech recognition API.
+audio.track.js example: This example demonstrates using the artplayer-plugin-audio-track plugin to add an external audio track (like a commentary or dubbed track) synchronized with the main video. It uses the Artplayer constructor and the artplayerPluginAudioTrack plugin API. The feature shown is playing an AAC audio file alongside the video with configurable offset and sync parameters.
+
+// npm i artplayer-plugin-audio-track
+// import artplayerPluginAudioTrack from 'artplayer-plugin-audio-track';
+
+var art = new Artplayer({
+ container: '.artplayer-app',
+ url: '/assets/sample/sprite-fight.mp4',
+ plugins: [
+ artplayerPluginAudioTrack({
+ url: '/assets/sample/sprite-fight.aac',
+ offset: 0,
+ sync: 0.3,
+ }),
+ ],
+});
+
+auto.thumbnail.js example: This example demonstrates using the artplayer-plugin-auto-thumbnail plugin to automatically generate video thumbnails for the progress bar. It uses the Artplayer constructor and the artplayerPluginAutoThumbnail plugin API. The feature shown is enabling a visual preview of the video content on hover over the progress bar.
+
+// npm i artplayer-plugin-auto-thumbnail
+// import artplayerPluginAutoThumbnail from 'artplayer-plugin-auto-thumbnail';
-auto.thumbnail.js example code:
const art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -7075,9 +7637,11 @@ const art = new Artplayer({
],
})
-This example demonstrates the auto-thumbnail plugin for ArtPlayer, which automatically generates video thumbnails for the progress bar. It uses the artplayerPluginAutoThumbnail API with default configuration to create thumbnail previews.
+canvas.js example: This example demonstrates using the artplayer-proxy-canvas proxy to enable canvas-based video rendering, which can be used for advanced visual effects or processing. It uses the Artplayer constructor and the artplayerProxyCanvas proxy API. The example also enables many built-in Artplayer features like thumbnails, screenshot, settings, and playback controls.
+
+// npm i artplayer-proxy-canvas
+// import artplayerProxyCanvas from 'artplayer-proxy-canvas';
-canvas.js example code:
const art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -7106,9 +7670,11 @@ const art = new Artplayer({
proxy: artplayerProxyCanvas(),
})
-This example demonstrates the canvas proxy plugin for ArtPlayer, which enables advanced video manipulation and effects using HTML5 Canvas. It uses the artplayerProxyCanvas API along with comprehensive player configuration including thumbnails, playback controls, and various display features.
+chapter.js example: This example demonstrates using the artplayer-plugin-chapter plugin to add chapter markers and navigation to the video progress bar. It uses the Artplayer constructor and the artplayerPluginChapter plugin API. The feature shown is defining video segments with start/end times and titles, allowing users to jump between chapters.
+
+// npm i artplayer-plugin-chapter
+// import artplayerPluginChapter from 'artplayer-plugin-chapter';
-chapter.js example code:
const art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -7135,9 +7701,11 @@ const art = new Artplayer({
],
})
-This example demonstrates the chapter plugin for ArtPlayer, which adds chapter navigation to videos. It uses the artplayerPluginChapter API to define video segments with start/end times and titles, enabling users to jump between different sections of the video.
+chromecast.js example: This example demonstrates using the artplayer-plugin-chromecast plugin to enable Google Chromecast support for casting video to external devices. It uses the Artplayer constructor and the artplayerPluginChromecast plugin API. The feature shown is integrating casting capability, with optional configuration for the Cast SDK URL and media MIME type.
+
+// npm i artplayer-plugin-chromecast
+// import artplayerPluginChromecast from 'artplayer-plugin-chromecast';
-chromecast.js example code:
const art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -7151,9 +7719,12 @@ const art = new Artplayer({
],
})
-This example demonstrates the Chromecast plugin for ArtPlayer, enabling video casting to Chromecast devices. It uses the artplayerPluginChromecast API with optional SDK and MIME type configuration for casting functionality.
+danmuku.js example: This example demonstrates using the artplayer-plugin-danmuku plugin to display danmaku (bullet comments) over the video player. It uses the Artplayer constructor and the artplayerPluginDanmuku plugin API. The feature shown is loading danmaku from an XML file, with extensive configuration for appearance, behavior, filtering, and a custom async function to handle sending new comments.
+
+// npm i artplayer-plugin-danmuku
+// import artplayerPluginDanmuku from 'artplayer-plugin-danmuku';
+// 使用文档 https://artplayer.org/document/plugin/danmuku.html
-danmuku.js example code:
const art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -7205,12 +7776,17 @@ const art = new Artplayer({
],
})
-This example demonstrates the danmuku (bullet comments) plugin for ArtPlayer, showing comprehensive configuration for displaying user comments over video playback. It uses the artplayerPluginDanmuku API with extensive customization options for appearance, behavior, filtering, and real-time comment submission.
+danmuku.mask.js example: This example demonstrates using both the artplayer-plugin-danmuku and artplayer-plugin-danmuku-mask plugins together. The mask plugin uses MediaPipe Selfie Segmentation to create a background mask, allowing danmaku comments to appear behind the speaker in the video. It uses the Artplayer constructor and both plugin APIs, showing integration of computer vision for enhanced danmaku display.
+
+// npm i artplayer-plugin-danmuku-mask
+// import artplayerPluginDanmukuMask from 'artplayer-plugin-danmuku-mask';
+
+// npm i @mediapipe/selfie_segmentation
+// 把 node_modules/@mediapipe/selfie_segmentation 目录复制到你的项目下
-danmuku.mask.js example code:
const art = new Artplayer({
container: '.artplayer-app',
- url: '/assets/sample/video.mp4',
+ url: '/assets/sample/steve-jobs.mp4',
autoSize: true,
fullscreen: true,
fullscreenWeb: true,
@@ -7225,19 +7801,16 @@ const art = new Artplayer({
],
})
-This example demonstrates the combination of danmuku and danmuku mask plugins for ArtPlayer. It uses both artplayerPluginDanmuku and artplayerPluginDanmukuMask APIs to create bullet comments with person segmentation masking, where comments appear behind detected human figures in the video using MediaPipe selfie segmentation.
+dash.control.js example: This example demonstrates the setup for using the artplayer-plugin-dash-control plugin alongside the dash.js library to play MPEG-DASH adaptive streaming videos. It shows the import statements and dependencies required but does not include the full player instantiation code. The feature indicated is control and playback of DASH streams.
-dash.control.js example code:
// npm i dashjs
// npm i artplayer-plugin-dash-control
// import dashjs from 'dashjs';
// import artplayerPluginDashControl from 'artplayer-plugin-dash-control';
-This example demonstrates the DASH (Dynamic Adaptive Streaming over HTTP) control plugin for ArtPlayer. It shows the import statements for integrating dash.js with the artplayerPluginDashControl API to enable adaptive bitrate streaming with DASH protocol support.
-
-Example 1: ArtPlayer with DASH plugin and custom type handler
-This example shows how to initialize ArtPlayer with DASH streaming support using dash.js library and the artplayerPluginDashControl plugin for quality and audio track selection.
+Example 1: ArtPlayer with DASH plugin and custom playback handler
+This example shows how to set up ArtPlayer with a DASH stream, using the dash.js library and a custom plugin for quality and audio track selection. It demonstrates the customType API for handling non-native video formats and the plugin system for extended controls.
const art = new Artplayer({
container: '.artplayer-app',
@@ -7288,8 +7861,8 @@ const art = new Artplayer({
===== dash.js =====
-Example 2: Basic DASH.js integration
-This example demonstrates a standalone DASH.js implementation with ArtPlayer, showing how to handle MPD format streams with custom type definition.
+Example 2: Basic DASH playback with dash.js
+This example demonstrates a minimal setup for playing a DASH stream using dash.js. It shows the customType API for defining a playback handler and the 'ready' event to access the dash.js instance.
// npm i dashjs
// import dashjs from 'dashjs';
@@ -7324,7 +7897,7 @@ art.on('ready', () => {
===== document.pip.js =====
Example 3: Document Picture-in-Picture plugin
-This example shows how to use the artplayerPluginDocumentPip plugin to enable Document Picture-in-Picture functionality with custom dimensions and fallback options.
+This example shows how to use the artplayer-plugin-document-pip plugin to enable Document Picture-in-Picture mode. It demonstrates plugin configuration and listening for the custom 'document-pip' event.
// npm i artplayer-plugin-document-pip
// import artplayerPluginDocumentPip from 'artplayer-plugin-document-pip';
@@ -7348,8 +7921,8 @@ art.on('document-pip', (state) => {
===== flv.js =====
-Example 4: FLV.js integration
-This example demonstrates FLV format playback using flv.js library with custom type handler for FLV streams.
+Example 4: FLV playback with flv.js
+This example demonstrates playing an FLV stream using the flv.js library. It shows the customType API and the 'ready' event to access the flv.js player instance.
// npm i flv.js
// import flvjs from 'flv.js';
@@ -7384,8 +7957,8 @@ art.on('ready', () => {
===== hls.control.js =====
-Example 5: HLS with quality and audio control plugin
-This example shows HLS streaming with artplayerPluginHlsControl plugin for quality selection and audio track management, including native HLS fallback for Safari.
+Example 5: HLS playback with quality and audio controls
+This example shows HLS playback using hls.js with the artplayer-plugin-hls-control plugin for quality and audio track selection. It demonstrates a comprehensive customType handler with fallback support for native HLS.
// npm i hls.js
// npm i artplayer-plugin-hls-control
@@ -7446,8 +8019,8 @@ const art = new Artplayer({
===== hls.js =====
-Example 6: Basic HLS.js integration
-This example shows a standalone HLS.js implementation with ArtPlayer for handling M3U8 streams with browser compatibility checks.
+Example 6: Basic HLS playback with hls.js
+This example shows a minimal setup for HLS playback using hls.js. It demonstrates the customType API and the 'ready' event to access the Hls instance.
// npm i hls.js
// import Hls from 'hls.js';
@@ -7485,8 +8058,8 @@ art.on('ready', () => {
===== iframe.js =====
-Example 7: Iframe plugin for embedded ArtPlayer instances
-This example demonstrates how to use ArtplayerToolIframe to embed ArtPlayer within an iframe and handle cross-frame communication for fullscreen functionality.
+Example 7: Embedding ArtPlayer within an iframe using a tool
+This example demonstrates how to embed and control an ArtPlayer instance inside an iframe using the artplayer-tool-iframe utility. It shows cross-document communication via postMessage for features like fullscreenWeb mode.
// npm i artplayer-tool-iframe
// import ArtplayerToolIframe from 'artplayer-tool-iframe';
@@ -7538,11 +8111,8 @@ iframe.commit(() => {
===== index.js =====
-Example 8: Basic ArtPlayer initialization
-This example shows a minimal ArtPlayer setup with default configuration for basic video playback.
-
-// Basic ArtPlayer initialization code would go here
-// This serves as a placeholder for the main index.js file
+Example 8: Placeholder file
+This appears to be a placeholder or index file with no code, likely indicating the start of the examples or a file to be populated.
var art = new Artplayer({
container: '.artplayer-app',
@@ -7735,10 +8305,78 @@ var art = new Artplayer({
},
})
-// This example demonstrates a comprehensive ArtPlayer configuration with multiple features including custom settings, context menu, layers, quality switching, thumbnails, subtitles, highlights, and custom controls.
+This example shows a comprehensive configuration of the ArtPlayer instance. It demonstrates the core player API with a wide array of built-in features and custom UI components. Key features shown include: basic player setup with URL and poster; enabling numerous player controls like screenshot, loop, flip, playback rate, and fullscreen; custom settings panels with subtitle selector, switch, slider, and button components; custom context menu items; custom UI layers; multiple video quality options; thumbnail previews; subtitle styling and loading; video highlight markers; custom control bar buttons; and custom icon overrides for loading, state, and seek indicator.
+
+===== jassub.js =====
+
+// https://github.com/ThaUnknown/jassub
+// npm i artplayer-plugin-jassub
+// import artplayerPluginJassub from 'artplayer-plugin-jassub';
+
+var art = new Artplayer({
+ container: '.artplayer-app',
+ url: '/assets/jassub/FGOBD.mp4',
+ autoSize: true,
+ fullscreen: true,
+ fullscreenWeb: true,
+ plugins: [
+ artplayerPluginJassub({
+ subUrl: '/assets/jassub/FGOBD.ass',
+ workerUrl: '/assets/jassub/jassub-worker.js',
+ wasmUrl: '/assets/jassub/jassub-worker.wasm',
+ modernWasmUrl: '/assets/jassub/jassub-worker-modern.wasm',
+ availableFonts: {
+ 'liberation sans': '/assets/jassub/default.woff2'
+ },
+ fonts: [
+ '/assets/jassub/fonts/Averia Sans Libre Light.ttf',
+ '/assets/jassub/fonts/Averia Serif Simple Light.ttf',
+ '/assets/jassub/fonts/Gramond.ttf'
+ ],
+ timeOffset: -0.041
+ }),
+ ],
+});
+
+This example demonstrates the integration of the jassub plugin for advanced ASS/SSA subtitle rendering. It uses the plugins API to add the artplayerPluginJassub. The plugin configuration shows how to load ASS subtitle files, provide the required WebAssembly and worker scripts for subtitle rendering, specify custom fonts for accurate subtitle styling, and apply a timing offset to sync the subtitles with the video.
+
+===== mediabunny.js =====
+
+// npm i artplayer-proxy-mediabunny
+// import artplayerProxyMediabunny from 'artplayer-proxy-mediabunny';
+
+const art = new Artplayer({
+ container: '.artplayer-app',
+ url: 'https://artplayer.org/assets/sample/frag_bunny.mp4',
+ autoSize: true,
+ screenshot: true,
+ setting: true,
+ loop: true,
+ flip: true,
+ playbackRate: true,
+ fullscreen: true,
+ fullscreenWeb: true,
+ miniProgressBar: true,
+ autoPlayback: true,
+ autoOrientation: true,
+ thumbnails: {
+ url: '/assets/sample/frag_bunny.png',
+ number: 60,
+ column: 10,
+ scale: 0.85,
+ },
+ proxy: artplayerProxyMediabunny(),
+})
+
+This example shows the use of the mediabunny proxy plugin. It uses the proxy API to integrate artplayerProxyMediabunny. The feature demonstrated is the ability to proxy video data, which is often used for handling specific streaming protocols, adding DRM support, or modifying network requests. The player is configured with common UI features like thumbnails, screenshot, and playback controls, with the proxy handling the underlying video delivery.
===== mobile.js =====
+This file appears to be incomplete in the provided input. A typical mobile.js example would demonstrate configuration options optimized for mobile devices, such as touch controls, playsInline for iOS, and autoOrientation. Since the code is not present, no analysis can be provided.
+
+Example 1: Basic ArtPlayer Configuration
+This example shows a comprehensive ArtPlayer setup with many built-in features enabled. It uses the core ArtPlayer constructor and demonstrates common configuration options, custom thumbnails, subtitles, layers, icons, and a custom settings menu.
+
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -7838,10 +8476,11 @@ var art = new Artplayer({
],
})
-// This example demonstrates mobile-optimized ArtPlayer configuration with Chinese localization, mobile-specific video attributes for QQ browser, and responsive design features.
-
===== mpegts.js =====
+Example 2: Custom Playback for FLV Format with mpegts.js
+This example demonstrates using a custom playback function for FLV video files via the mpegts.js library. It uses the `customType` configuration option and the player's `on` event hook.
+
// npm i mpegts
// import mpegts from 'mpegts';
@@ -7857,18 +8496,7 @@ function playFlv(video, url, art) {
flv.attachMediaElement(video)
flv.load()
flv.play()
-}
-// This example shows how to integrate mpegts.js for FLV video playback support, including proper cleanup of previous FLV instances and media element attachment.
-
-custom.flv.js
-This example demonstrates how to add custom FLV playback support using the flv.js library. It shows the customType API to register a custom video type handler.
-
-function playFlv(video, url, art) {
- if (flvjs.isSupported()) {
- const flv = flvjs.createPlayer({ type: 'flv', url })
- flv.attachMediaElement(video)
- flv.load()
art.flv = flv
art.on('destroy', () => flv.destroy())
}
@@ -7892,7 +8520,8 @@ art.on('ready', () => {
===== multiple.subtitles.js =====
-This example shows how to use the multiple subtitles plugin to display multiple subtitle tracks with custom styling and settings controls.
+Example 3: Multiple Subtitles Plugin
+This example shows the integration of the `artplayer-plugin-multiple-subtitles` plugin. It demonstrates loading multiple subtitle tracks, creating a settings menu to control them, and applying custom CSS styles to different subtitle languages.
// npm i artplayer-plugin-multiple-subtitles
// import artplayerPluginMultipleSubtitles from 'artplayer-plugin-multiple-subtitles';
@@ -8010,8 +8639,6 @@ else {
===== setting.test.js =====
-This example demonstrates comprehensive settings configuration including subtitle controls, custom switches, sliders, and dynamic settings manipulation through the settings API.
-
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
@@ -8153,9 +8780,9 @@ var art = new Artplayer({
}
})
-===== thumbnail.js =====
+This example demonstrates the advanced customization of the ArtPlayer settings panel. It shows how to add custom settings items, including a subtitle selector with a toggle switch, a custom boolean switch, and a range slider. The second function argument uses the Artplayer.utils.sleep method and demonstrates the Setting API, including methods like show, builtin, find, resize, inactivate, remove, update, and add, to dynamically manipulate settings at runtime.
-This example demonstrates the thumbnail plugin which shows video preview thumbnails when hovering over the progress bar.
+===== thumbnail.js =====
// npm i artplayer-plugin-thumbnail
// import artplayerPluginThumbnail from 'artplayer-plugin-thumbnail';
@@ -8172,9 +8799,83 @@ const art = new Artplayer({
],
})
-===== vast.js =====
+This example shows the basic integration of the artplayer-plugin-thumbnail. It initializes a player with the thumbnail plugin, which generates a preview strip from the video. The plugin configuration includes options for thumbnail width, the total number of thumbnails, and the scale.
-This example shows how to integrate VAST advertising using Google's IMA SDK through the vast plugin.
+===== tool.thumbnail.js =====
+
+if (window.lastThumbnail) {
+ window.lastThumbnail.destroy();
+}
+
+var $popups = document.querySelector('.popups');
+var $popinner = document.querySelector('.popinner');
+var $artplayer = document.querySelector('.artplayer-app');
+
+$artplayer.innerHTML = 'Drop video file here or click to upload.';
+var thumbnail = new ArtplayerToolThumbnail({
+ fileInput: $artplayer,
+ number: 60, // 数量
+ width: 160, // 宽度
+ column: 10, // 列数
+ begin: 0, // 开始
+ end: NaN, // 结束
+});
+
+window.lastThumbnail = thumbnail;
+
+thumbnail.on('file', function (file) {
+ console.log('Read video successfully: ' + file.name);
+});
+
+thumbnail.on('video', function (video) {
+ console.log('Video size: ' + video.videoWidth + ' x ' + video.videoHeight);
+ console.log('Video duration: ' + video.duration + 's');
+ thumbnail.start();
+});
+
+thumbnail.on('canvas', function (canvas) {
+ console.log('Build canvas successfully');
+ console.log('Canvas size: ' + canvas.width + ' x ' + canvas.height);
+ console.log('Preview density: ' + thumbnail.density + ' p/s');
+});
+
+thumbnail.on('update', function (url, percentage) {
+ console.log('Processing: ' + Math.floor(percentage.toFixed(2) * 100) + '%');
+ $popups.style.display = 'flex';
+ $popinner.style.backgroundImage = 'url(' + url + ')';
+});
+
+thumbnail.on('download', function (name) {
+ console.log('Start download preview: ' + name);
+});
+
+thumbnail.on('done', function () {
+ $popups.style.display = 'none';
+ thumbnail.download();
+ console.log('Build preview image complete');
+
+ [...Artplayer.instances].forEach(function (art) {
+ art.destroy(true);
+ });
+
+ new Artplayer({
+ container: $artplayer,
+ url: thumbnail.videoUrl,
+ autoSize: true,
+ poster: thumbnail.thumbnailUrl,
+ thumbnails: {
+ url: thumbnail.thumbnailUrl,
+ number: thumbnail.option.number,
+ column: thumbnail.option.column,
+ },
+ });
+
+ console.log('Build player complete');
+});
+
+This example demonstrates the standalone ArtplayerToolThumbnail utility for generating a thumbnail sprite from a user-uploaded video file. It uses the tool's event-driven API (on('file'), on('video'), on('canvas'), on('update'), on('download'), on('done')) to handle the workflow. The final step creates a new ArtPlayer instance configured with the generated thumbnail sprite and the original video.
+
+===== vast.js =====
// Depends on:
// https://glomex.github.io/vast-ima-player/
@@ -8201,9 +8902,9 @@ var art = new Artplayer({
],
})
-===== vtt.thumbnail.js =====
+This example shows integration with the artplayer-plugin-vast for VAST/IMA ad playback. The plugin is configured with a callback that receives helper functions. The example uses art.once to listen for the first 'play' event and then triggers an ad playback from a VAST XML URL using the provided playUrl function.
-This example demonstrates VTT-based thumbnail previews using the vtt-thumbnail plugin with WebVTT format thumbnail files.
+===== vtt.thumbnail.js =====
// npm i artplayer-plugin-vtt-thumbnail
// import artplayerPluginVttThumbnail from 'artplayer-plugin-vtt-thumbnail';
@@ -8218,15 +8919,13 @@ const art = new Artplayer({
],
})
-===== webtorrent.js =====
+This example demonstrates the use of the artplayer-plugin-vtt-thumbnail plugin. It loads a WebVTT file that contains thumbnail image coordinates and timing data, allowing the player to display a preview image on the progress bar that corresponds to the specific time in the video.
-This example shows WebTorrent integration for streaming torrent-based video content (implementation code not shown).
+===== webtorrent.js =====
// npm i webtorrent
// import WebTorrent from 'webtorrent';
-Full example code:
-
async function playTorrent(video, url, art) {
if (WebTorrent.WEBRTC_SUPPORT) {
if (art.torrent)
@@ -8250,6 +8949,8 @@ async function playTorrent(video, url, art) {
}
}
+This example provides a utility function, playTorrent, for streaming video from a torrent file using the WebTorrent library. It checks for WebRTC support, initializes a new WebTorrent client, registers a service worker, and adds the torrent. It finds the first .mp4 file within the torrent and streams it directly to a video element. It also sets up a listener to destroy the torrent client when the ArtPlayer instance is destroyed.
+
const art = new Artplayer({
container: '.artplayer-app',
url: 'magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel.torrent',
@@ -8263,4 +8964,4 @@ art.on('ready', () => {
console.info(art.torrent)
})
-This example demonstrates WebTorrent integration with ArtPlayer, showing how to stream torrent content directly in the video player. The playTorrent function checks for WebRTC support, initializes WebTorrent, registers a service worker, and streams MP4 files from torrents to the video element. The ArtPlayer configuration uses a magnet URI as the video source and defines a custom 'torrent' type that calls the playTorrent function. The example also shows proper cleanup by destroying the torrent instance when the player is destroyed, and demonstrates using the 'ready' event to access the torrent instance.
\ No newline at end of file
+This example shows how to initialize an ArtPlayer instance to stream a video from a torrent magnet link. It uses the Artplayer constructor API with the 'url', 'type', and 'customType' options. The 'type' is set to 'torrent', and a 'customType' handler named 'playTorrent' (a function assumed to be defined elsewhere) is provided to handle the torrent playback logic. This demonstrates the player's extensibility for custom video sources, specifically integrating WebTorrent functionality. The event listener for the 'ready' event logs the torrent instance to the console, showing how to access the internal torrent object after the player is set up.
\ No newline at end of file
diff --git a/scripts/build-llm.js b/scripts/build-llm.js
index 0e388dba0..c2832edd6 100644
--- a/scripts/build-llm.js
+++ b/scripts/build-llm.js
@@ -12,11 +12,13 @@ const rootDir = path.resolve(__dirname, '../packages/artplayer-vitepress')
const dostDir = path.resolve(__dirname, '../docs')
const outputFile = path.resolve(__dirname, '../docs/llms.txt')
const API_URL = 'https://api.deepseek.com/v1/chat/completions'
-const API_KEY = process.env.DEEPL_API_KEY
+const API_KEY = process.env.DEEPSEEK_API_KEY
const MAX_CONCURRENT_REQUESTS = 3 // 每类并发请求数
+const REQUEST_TIMEOUT = 60000 // 请求超时时间 60秒
+const MAX_RETRIES = 3 // 最大重试次数
if (!API_KEY) {
- console.error('❌ Missing DEEPL_API_KEY in .env file')
+ console.error('❌ Missing DEEPSEEK_API_KEY in .env file')
process.exit(1)
}
@@ -35,7 +37,7 @@ function readFiles(files) {
return content
}
-function splitText(text, maxLen = 5000) {
+function splitText(text, maxLen = 8000) {
const paragraphs = text.split(/\n{2,}/)
const chunks = []
let buffer = ''
@@ -52,31 +54,62 @@ function splitText(text, maxLen = 5000) {
}
async function askDeepSeek(prompt, text, tag, id) {
- console.log(`🧠 [${tag}] Sending chunk ${id}`)
- const res = await fetch(API_URL, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': `Bearer ${API_KEY}`,
- },
- body: JSON.stringify({
- model: 'deepseek-chat',
- messages: [
- { role: 'system', content: 'You are a professional technical writer.' },
- { role: 'user', content: `${prompt}\n\n${text}` },
- ],
- temperature: 0.3,
- }),
- })
+ for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
+ try {
+ console.log(`🧠 [${tag}] Sending chunk ${id} (attempt ${attempt}/${MAX_RETRIES})`)
+ const controller = new AbortController()
+ const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT)
- if (!res.ok) {
- const err = await res.text()
- console.error(`[${tag}] API Error:`, err)
- throw new Error(`DeepSeek API error: ${res.status}`)
+ const res = await fetch(API_URL, {
+ method: 'POST',
+ signal: controller.signal,
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': `Bearer ${API_KEY}`,
+ },
+ body: JSON.stringify({
+ model: 'deepseek-chat',
+ messages: [
+ { role: 'system', content: 'You are a professional technical writer.' },
+ { role: 'user', content: `${prompt}\n\n${text}` },
+ ],
+ temperature: 0.3,
+ }),
+ })
+ clearTimeout(timeout)
+
+ // 处理限流情况
+ if (res.status === 429) {
+ const delay = Math.pow(2, attempt) * 1000
+ console.log(`⏳ [${tag}] Rate limited, waiting ${delay}ms...`)
+ await new Promise(r => setTimeout(r, delay))
+ continue
+ }
+
+ if (!res.ok) {
+ const err = await res.text()
+ console.error(`[${tag}] API Error:`, err)
+ throw new Error(`DeepSeek API error: ${res.status}`)
+ }
+
+ const data = await res.json()
+ if (!data.choices || !data.choices[0]) {
+ throw new Error('Invalid API response: missing choices')
+ }
+ return data.choices[0].message?.content?.trim() || ''
+ }
+ catch (err) {
+ if (err.name === 'AbortError') {
+ console.error(`[${tag}] Request timeout for chunk ${id}`)
+ }
+ if (attempt === MAX_RETRIES) {
+ throw err
+ }
+ const delay = 1000 * attempt
+ console.log(`⚠️ [${tag}] Retry ${attempt}/${MAX_RETRIES} after ${delay}ms...`)
+ await new Promise(r => setTimeout(r, delay))
+ }
}
-
- const data = await res.json()
- return data.choices?.[0]?.message?.content?.trim() || ''
}
async function runConcurrent(tasks, limit = MAX_CONCURRENT_REQUESTS) {