diff --git a/docs/llms.manifest.json b/docs/llms.manifest.json new file mode 100644 index 000000000..da932bee7 --- /dev/null +++ b/docs/llms.manifest.json @@ -0,0 +1,271 @@ +{ + "schemaVersion": 1, + "generation": "offline-source-preserving", + "sources": [ + { + "file": "packages/artplayer-vitepress/docs/en/advanced/built-in.md", + "sha256Lf": "5d56bce1f12b10363643edb8f655bbda1ed656b9646561c2e422ca9eb9a7b055" + }, + { + "file": "packages/artplayer-vitepress/docs/en/advanced/class.md", + "sha256Lf": "57ae1273515faa31ae28672f80a44d7b6f4aee918b59b814c638e3fd311f56ba" + }, + { + "file": "packages/artplayer-vitepress/docs/en/advanced/event.md", + "sha256Lf": "e11360c89bc91ed4f68ce9a40d335c1726ef006a23950d5d9ce4475789aecb7e" + }, + { + "file": "packages/artplayer-vitepress/docs/en/advanced/global.md", + "sha256Lf": "01380ae04fedd94dd91f5f31c51d4894c458dad3268cf38119b54a8fe73ee46c" + }, + { + "file": "packages/artplayer-vitepress/docs/en/advanced/plugin.md", + "sha256Lf": "b6defaab71f22becbc8d3141a2b2ac746c9fbe24eba31326837c2e8ce8b59057" + }, + { + "file": "packages/artplayer-vitepress/docs/en/advanced/property.md", + "sha256Lf": "041d33b8d81cbb928ea07504885ceccab4becf3476bf82120013d5f2840c31b7" + }, + { + "file": "packages/artplayer-vitepress/docs/en/component/contextmenu.md", + "sha256Lf": "df86b1d08d01288e68fa861e3f645109d6305868785a9005906c95dc86280f1f" + }, + { + "file": "packages/artplayer-vitepress/docs/en/component/controls.md", + "sha256Lf": "cd516c25f6d27c52da58e41dd98b360975f1e43b1d42b460ea3a2e21c6a3c2b2" + }, + { + "file": "packages/artplayer-vitepress/docs/en/component/layers.md", + "sha256Lf": "bd8a5d0b996159b1fb563caa9f74cce3bcf97c4bca9eea99f1cd75ceacc6a0d3" + }, + { + "file": "packages/artplayer-vitepress/docs/en/component/setting.md", + "sha256Lf": "652e85b02f9de60ff794cb3527a3e4ae514a3441cacebf340c1a82d09ce06f08" + }, + { + "file": "packages/artplayer-vitepress/docs/en/index.md", + "sha256Lf": "adec563b74e5d690f97a710bf58478d04092f0de199674152e68da817f412ee5" + }, + { + "file": "packages/artplayer-vitepress/docs/en/start/i18n.md", + "sha256Lf": "1551bf939aab1ee942d8480df891640109d18aa9adc016adf1d075bee5ef1de9" + }, + { + "file": "packages/artplayer-vitepress/docs/en/start/option.md", + "sha256Lf": "72776482f31a3240462d72d56912b2e9f96583a12f36b6556abdf379ca1d3fdf" + }, + { + "file": "docs/assets/ts/artplayer-plugin-ads.d.ts", + "sha256Lf": "bf128828d5b104fc844a4f134a02162e57472d8c927a50df7b3878f4c5ed7652" + }, + { + "file": "docs/assets/ts/artplayer-plugin-ambilight.d.ts", + "sha256Lf": "9f06ccb7398053dca642ca369aa47f54cbb3e4dd4d5e252e999e59e496d8eee8" + }, + { + "file": "docs/assets/ts/artplayer-plugin-asr.d.ts", + "sha256Lf": "5096f097636c018bc05c497324c271af3fefaebccda7fa3e9cd43b63477704ad" + }, + { + "file": "docs/assets/ts/artplayer-plugin-audio-track.d.ts", + "sha256Lf": "604af2a3790eb7c583ba150c402dca0a3e458469cc74913b51fee2f3d3882541" + }, + { + "file": "docs/assets/ts/artplayer-plugin-auto-thumbnail.d.ts", + "sha256Lf": "f66bba7f633202c2ef359a989269c643b75d91594364f7ed6fb67f9898aeac03" + }, + { + "file": "docs/assets/ts/artplayer-plugin-chapter.d.ts", + "sha256Lf": "d5bd68579659afa44158c894e12372cedd6f958415ced370a65c294550aa828d" + }, + { + "file": "docs/assets/ts/artplayer-plugin-chromecast.d.ts", + "sha256Lf": "0a0b932081cac0efbcedea28dc1077484963b7f406808378704062661a4c0338" + }, + { + "file": "docs/assets/ts/artplayer-plugin-danmuku-mask.d.ts", + "sha256Lf": "06c6e938876edcc0ac2c8dcd1e1be4596b0f056685a3523d4c9836f2f2f90362" + }, + { + "file": "docs/assets/ts/artplayer-plugin-danmuku.d.ts", + "sha256Lf": "e3421bdbdfc6bea1b0b633300350fff1a745d8bc21c1430b6154a23fa3ad0415" + }, + { + "file": "docs/assets/ts/artplayer-plugin-dash-control.d.ts", + "sha256Lf": "c7e3c83f3377b615e503a270af12915dcc82fe3f2cfabdae396632855a27f73f" + }, + { + "file": "docs/assets/ts/artplayer-plugin-document-pip.d.ts", + "sha256Lf": "42faa0a6549149efd01b46c3c59246bd4dc33f2383b63b04e9f5376de29fdb8e" + }, + { + "file": "docs/assets/ts/artplayer-plugin-hls-control.d.ts", + "sha256Lf": "6a623bb6ba4cc0598a3dd1aab5ef7ca4fbae11973a787885eccba10cc7aa2c7c" + }, + { + "file": "docs/assets/ts/artplayer-plugin-jassub.d.ts", + "sha256Lf": "ce713e0a61a81bfc31087ea1a880a99398ef7c2b833e567c91e4e98f5ae6f621" + }, + { + "file": "docs/assets/ts/artplayer-plugin-multiple-subtitles.d.ts", + "sha256Lf": "edb15207df69a695311e849555cf989bfc32da20c2456731b6814de5400567bb" + }, + { + "file": "docs/assets/ts/artplayer-plugin-vast.d.ts", + "sha256Lf": "b21ed9a852b3ec3cc9b409cce08e91905e42abdc1d642acc9b412c33c83287b7" + }, + { + "file": "docs/assets/ts/artplayer-plugin-vtt-thumbnail.d.ts", + "sha256Lf": "d82c0fe08bcf9c60e2a634e9f1fd8ccc75dc8e0ddbfa8262cccaefc9604aa61b" + }, + { + "file": "docs/assets/ts/artplayer-proxy-canvas.d.ts", + "sha256Lf": "83c408e0724a598f9ff32d68d752f39e03feb69ba4f6a49ba02f9d4df898453e" + }, + { + "file": "docs/assets/ts/artplayer-proxy-mediabunny.d.ts", + "sha256Lf": "acbaa0a25f20ac15b3d79db00b3a16167f84452ab58933110f42dcb3262fbd3e" + }, + { + "file": "docs/assets/ts/artplayer-tool-iframe.d.ts", + "sha256Lf": "c06c6819146ba64bd6ee498871d9e19ab5a9e88c9cc7bed2c0c4968fa39dfed7" + }, + { + "file": "docs/assets/ts/artplayer-tool-thumbnail.d.ts", + "sha256Lf": "9b72d10a1fe964d54fcf4774770074058ea739b4f734b52b8f4adebb37fc83e6" + }, + { + "file": "docs/assets/ts/artplayer.d.ts", + "sha256Lf": "652c0fdf605e87203526777a05851bd69c95c1660d5ff29eab19c00967c9a985" + }, + { + "file": "docs/assets/ts/artplayer-i18n.d.ts", + "sha256Lf": "60851e22ea50ed540f1be0f5a110077cdd5e6ab87345a675838f6c6333517405" + }, + { + "file": "docs/assets/example/ads.js", + "sha256Lf": "c84a97d2b1970c323a0c2538b846312bff38513e10de271fe5f239953da88cd3" + }, + { + "file": "docs/assets/example/ambilight.js", + "sha256Lf": "f97c1404886ba6474b4e14339c563fd2de50b7d50fdc4c9d59d85a3142a1ad52" + }, + { + "file": "docs/assets/example/asr.js", + "sha256Lf": "bb7fd5eee3df887b7e0c72a6f42f74f0253350f9bc884f73cb9c2996f0e35724" + }, + { + "file": "docs/assets/example/asr.local.js", + "sha256Lf": "32371e51ac5f55edaa146002e7e4594ec056bf198db8b1e62e6d68ec2ea48f30" + }, + { + "file": "docs/assets/example/audio.track.js", + "sha256Lf": "9ed26b2ee006e1a430db68b2a1b308c4801dd3a4cc87c74e8a8f5ccf3456ac8d" + }, + { + "file": "docs/assets/example/auto.thumbnail.js", + "sha256Lf": "e0f706bbbab8e2d0f3201ea6b91f1d5530c6bb65f5c1745dc8ade9acc6d66295" + }, + { + "file": "docs/assets/example/canvas.js", + "sha256Lf": "95a971773e93cfb340a07eebcd49e333825f49ce0d167514ad98a188cd027799" + }, + { + "file": "docs/assets/example/chapter.js", + "sha256Lf": "93f2378a1b7a105721511d34fd632ec7745b4b20c472072c410f76b25383c96b" + }, + { + "file": "docs/assets/example/chromecast.js", + "sha256Lf": "edd4d232a667a3ca5bae247dca3c557431975b9ae38dc56cc590b57e327d048f" + }, + { + "file": "docs/assets/example/danmuku.js", + "sha256Lf": "3f91461e2466f13ed4e72e6bd69986461192d8c6a9ca866fa347599f6958e021" + }, + { + "file": "docs/assets/example/danmuku.mask.js", + "sha256Lf": "c0fe4f2d4cd60738583c4bfeebc24bc3365d8ca382e6f4ff86e1056f5a2729a8" + }, + { + "file": "docs/assets/example/dash.control.js", + "sha256Lf": "edc4326f03262a222e06bb780aab05c903ee162829dec60970e738c1e260eef2" + }, + { + "file": "docs/assets/example/dash.js", + "sha256Lf": "49a7837016b6f0e8ac045e6aba7bb95e1997e6fd834243b4c62d0c97a2938776" + }, + { + "file": "docs/assets/example/document.pip.js", + "sha256Lf": "2600948ff0128e2e77fe08fbefa9be96543d8fcd81421534dfbfe9cb84e91fde" + }, + { + "file": "docs/assets/example/flv.js", + "sha256Lf": "51e052e5423318aa25c69eae90a5181c1325edf2d0975fa169308eadb6b395eb" + }, + { + "file": "docs/assets/example/hls.control.js", + "sha256Lf": "b02fd290d79999790501447fad95736642344b9b30af3ccdbe353f80c7d53a6e" + }, + { + "file": "docs/assets/example/hls.js", + "sha256Lf": "7f82d60442223ced637daa896199607ca9bd52ac50dabbb47c75561f84e9ff48" + }, + { + "file": "docs/assets/example/iframe.js", + "sha256Lf": "a2129e0ce772a58ae635fe1b784d65324155655cd2fc3c537ed511dffcb2be7a" + }, + { + "file": "docs/assets/example/index.js", + "sha256Lf": "7fd8b85433ced107add0e0b3731ef192113435330d976166cbb63992b7625571" + }, + { + "file": "docs/assets/example/jassub.js", + "sha256Lf": "4c93c554aa0a65ac19c1386bb0cfd9df6545f95b8a6f65541a0db8c072975f6d" + }, + { + "file": "docs/assets/example/mediabunny.js", + "sha256Lf": "dad4cecb76b2e5ce9164a4da715793911123e8fd2bc4b93f4bcc86a7053bad7d" + }, + { + "file": "docs/assets/example/mobile.js", + "sha256Lf": "c117fcd0e8b0f3da3745f5b97d2544b52aea49f28a7779704b0455f2a54d00e3" + }, + { + "file": "docs/assets/example/mpegts.js", + "sha256Lf": "2e819af74536e02fdbccbf3379467dec7b1cf6f3aff7e46c370355320485a482" + }, + { + "file": "docs/assets/example/multiple.subtitles.js", + "sha256Lf": "d9ccbd334d4c77f26826144870d6700e4b62f1f00b7f8f49817b3ac2583e5cc4" + }, + { + "file": "docs/assets/example/setting.test.js", + "sha256Lf": "84d6489b87556df556cbf567c9e72895366e0abeba524b9bb67ef9561d1dda60" + }, + { + "file": "docs/assets/example/thumbnail.js", + "sha256Lf": "e166845905f131dea0979eb77471f5531a59b93ab2dc28fef1b6791adb42fc30" + }, + { + "file": "docs/assets/example/tool.thumbnail.js", + "sha256Lf": "ef830a5f499e14c09d51aa31aaa0a194ea1f910b27f14ef97c0ca8f67d529a54" + }, + { + "file": "docs/assets/example/vast.js", + "sha256Lf": "ce93b48fabc2f1fd39fdaa8af3ae9f86a420c9aa65551e2e196d754070f36064" + }, + { + "file": "docs/assets/example/vtt.thumbnail.js", + "sha256Lf": "05465b0da63b23626a3032a9c1f44d3e78ed501a313aaed885ac232ab720ffee" + }, + { + "file": "docs/assets/example/webtorrent.js", + "sha256Lf": "11e6541fbaeb2f854b43ed4ea2bea36f411505343dc79a3f3a9ede9d856b2226" + }, + { + "file": "docs/assets/ts/artplayer-plugin-vast.LICENSE.txt", + "sha256Lf": "967db6e5026a2fd3cc24d8a04e5c78859f543d0c0f6d4f9599c103e4e93c9b29" + } + ], + "outputSha256Lf": "2dac26861645bdf8f449eb8a3b5e197ecf0bb93e124a4f038ef3d71e6783ad08" +} diff --git a/docs/llms.txt b/docs/llms.txt index 77a67f110..583223e0b 100644 --- a/docs/llms.txt +++ b/docs/llms.txt @@ -1,28 +1,43 @@ - +ArtPlayer documentation source bundle +Generated offline by yarn build:llm. Source text is preserved after LF normalization. +These are source references, not proof that every example or documented feature has passed release review. ===== Documentation Summary ===== -Advanced Properties +===== packages/artplayer-vitepress/docs/en/advanced/built-in.md ===== -The Advanced Properties refer to the secondary properties attached to the instance, which are less commonly used. +# Advanced Properties -option +The `Advanced Properties` here refer to the `secondary properties` attached to the `instance`, which are less commonly used. + +## `option` The player's options. +
▶ Run Code
+ +```js var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', }); console.info(art.option); +``` -Note: If you directly modify this option object, the player will not respond immediately. +:::warning Note -template +If you directly modify this `option` object, the player will not respond immediately. -Manages all DOM elements of the player. +::: +## `template` + +Manages all `DOM` elements of the player. + +
▶ Run Code
+ +```js var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -30,18 +45,26 @@ var art = new Artplayer({ console.info(art.template); console.info(art.template.$video); +``` -Note: To easily distinguish between DOM elements and regular objects, all DOM elements within the player are named with a $ prefix. +:::warning Note -This is the definition of all DOM elements: artplayer/types/template.d.ts +To easily distinguish between `DOM` elements and regular objects, all `DOM` elements within the player are named with a `$` prefix. -events +This is the definition of all `DOM` elements: [artplayer/types/template.d.ts](https://github.com/zhw2590582/ArtPlayer/blob/master/packages/artplayer/types/template.d.ts) -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. +## `events` +Manages all `DOM` events for the player. It essentially proxies `addEventListener` and `removeEventListener`. When using the following methods to handle events, the events will also 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. + +
▶ Run Code
+ +```js var container = document.querySelector('.artplayer-app'); var art = new Artplayer({ @@ -50,7 +73,7 @@ var art = new Artplayer({ }); art.events.proxy(container, 'click', event => { - console.info('click', event); + console.info('click', event); }); art.events.hover(container, (event) => { @@ -58,19 +81,27 @@ art.events.hover(container, (event) => { }, (event) => { console.info('mouseleave', event); }); +``` -Note: If you need DOM events that only exist during the player's lifecycle, it is strongly recommended to use these functions to avoid memory leaks. +:::warning Note -storage +If you need `DOM` events that should only exist during the player's lifecycle, it is strongly recommended to use these functions to avoid memory leaks. + +::: + +## `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. +- The `get` method is used to retrieve a cache. +- The `del` method is used to delete a cache. +- The `clear` method is used to clear all caches. +
▶ Run Code
+ +```js var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -81,11 +112,19 @@ const test = art.storage.get('test'); console.info(test); art.storage.del('test'); art.storage.clear(); +``` -Note: By default, all player instances share the same localStorage, and the default key is artplayer_settings. +:::warning Note -If you want different players to use different localStorage, you can modify art.storage.name. +By default, all player instances share the same `localStorage`, and the default `key` is `artplayer_settings`. +If you want different players to use different `localStorage`, you can modify `art.storage.name`. + +::: + +
▶ Run Code
+ +```js var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -93,27 +132,39 @@ var art = new Artplayer({ art.storage.name = 'your-storage-key'; art.storage.set('test', { foo: 'bar' }); +``` -icons +## `icons` -Manages all svg icons for the player. +Manages all `svg` icons for the player. +
▶ Run Code
+ +```js var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', }); console.info(art.icons.loading); +``` -This is the definition of all icons: artplayer/types/icons.d.ts +:::warning This is the definition of all icons: -i18n +[artplayer/types/icons.d.ts](https://github.com/zhw2590582/ArtPlayer/blob/master/packages/artplayer/types/icons.d.ts) -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. +## `i18n` +Manages the player's `i18n`. + +- The `get` method is used to retrieve an `i18n` value. +- The `update` method is used to update the `i18n` object. + +
▶ Run Code
+ +```js var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -126,13 +177,21 @@ art.i18n.update({ Play: 'Your Play' } }); +``` -Note: Using art.i18n.update can only update the i18n after instantiation. If you want to update the i18n before instantiation, please use the i18n option in the basic options. +:::warning -notice +Using `art.i18n.update` can only update the `i18n` after instantiation. If you want to update `i18n` before instantiation, please use the `i18n` option in the basic settings. -Manages the player's notifications. It only has a show property for displaying notifications. +::: +## `notice` + +Manages the player's notifications. It only has a `show` property for displaying notifications. + +
▶ Run Code
+ +```js var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -141,19 +200,27 @@ var art = new Artplayer({ art.on('ready', () => { art.notice.show = 'Video Ready To Play'; }) +``` -Note: If you want to hide the notice immediately: art.notice.show = ''; +:::warning -layers +If you want to hide the `notice` immediately: `art.notice.show = '';` + +::: + +## `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 displayed. +- The `toggle` method is used to toggle the display of all layers. +
▶ Run Code
+ +```js var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -164,23 +231,32 @@ 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 +:::warning For `Component Configuration`, please refer to: -controls +[/component/layers.html](/component/layers.html) + +::: + +## `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 + +
▶ Run Code
+ +```js var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -192,23 +268,31 @@ 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 +:::warning For `Component Configuration`, please refer to: -contextmenu +[/component/controls.html](/component/controls.html) -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. +## `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 + +
▶ Run Code
+ +```js var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -220,24 +304,32 @@ 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 +:::warning For `Component Configuration`, please refer to: -subtitle +[/component/contextmenu.html](/component/contextmenu.html) -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. +## `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 + +
▶ Run Code
+ +```js var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -249,19 +341,18 @@ art.on('ready', () => { color: 'red', }); }); +``` -info +## `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. -ArtPlayer Documentation +- Control the panel's visibility via `art.info.show` +- The triggered event is named `info` (see the event documentation for details) -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: +
▶ Run Code
+```js var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -274,13 +365,18 @@ art.on('ready', () => { art.info.show = false; }, 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. +Manages the player's loading layer -Example code: +- 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
+ +```js var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -288,17 +384,22 @@ var art = new Artplayer({ art.on('ready', () => { art.loading.show = true; - setTimeout(() => { - art.loading.show = false; - }, 1000); + setTimeout(() => { + art.loading.show = false; + }, 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. +Manages the player's hotkey functionality -Example code: +- The `add` method is used to add hotkeys +- The `remove` method is used to remove hotkeys +
▶ Run Code
+ +```js var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -311,18 +412,27 @@ function hotkeyEvent(event) { art.on('ready', () => { art.hotkey.add(32, hotkeyEvent); setTimeout(() => { - art.hotkey.remove(32, hotkeyEvent); - }, 5000); + art.hotkey.remove(32, hotkeyEvent); + }, 5000); }); +``` -Note: These hotkeys only take effect after the player gains focus (e.g., after clicking on the player). +:::warning Note -Mask Layer +These hotkeys only take effect after the player gains focus (e.g., after clicking on the player) -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. +::: -Example code: +## `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
+ +```js var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -330,17 +440,25 @@ var art = new Artplayer({ art.on('ready', () => { art.mask.show = false; - setTimeout(() => { - art.mask.show = true; - }, 1000); + setTimeout(() => { + art.mask.show = true; + }, 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. +Manages the player's settings panel -Example code: +- 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
+ +```js var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -353,19 +471,25 @@ var art = new Artplayer({ art.on('ready', () => { art.setting.show = true; - setTimeout(() => { - art.setting.show = false; - }, 1000); + setTimeout(() => { + art.setting.show = false; + }, 1000); }); +``` -For the Settings Panel, please refer to: /component/setting.html +:::warning For `Settings Panel`, please refer to -Plugins +[/component/setting.html](/component/setting.html) -Manages the player's plugin functionality, with only the add method for dynamically adding plugins. +::: -Example code: +## `plugins` +Manages the player's plugin functionality, with only one method `add` for dynamically adding plugins + +
▶ Run Code
+ +```js var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -385,17 +509,21 @@ function myPlugin(art) { art.on('ready', () => { art.plugins.add(myPlugin); }); +``` -Static Properties +===== packages/artplayer-vitepress/docs/en/advanced/class.md ===== -Static Properties refer to the top-level properties mounted on the constructor function, which are very rarely used. +# Static Properties -Instances +Here, `static properties` refer to the `first-level properties` attached to the `constructor`, which are rarely used. -Returns an array of all player instances. This property can be useful when you need to manage multiple player instances simultaneously. +## `instances` -Example code: +Returns an array of all player instances. This property can be useful when you need to manage multiple players simultaneously. +
▶ Run Code
+ +```js console.info([...Artplayer.instances]); var art = new Artplayer({ @@ -404,105 +532,135 @@ var art = new Artplayer({ }); console.info([...Artplayer.instances]); +``` -Version +## `version` Returns the version information of the player. -Example code: +
▶ Run Code
+```js console.info(Artplayer.version); +``` -Env +## `env` Returns the environment variables of the player. -Example code: +
▶ Run Code
+```js console.info(Artplayer.env); +``` -Build +## `build` -Returns the build time of the player. +Returns the build timestamp of the player. -Example code: +
▶ Run Code
+```js console.info(Artplayer.build); +``` -Config +## `config` Returns the default configuration for videos. -Example code: +
▶ Run Code
+```js console.info(Artplayer.config); +``` -Utils +## `utils` Returns the collection of utility functions for the player. -Example code: +
▶ Run Code
+```js console.info(Artplayer.utils); +``` -For all utility functions, please refer to the following address: artplayer/types/utils.d.ts +:::warning For all utility functions, please refer to the following address: -Scheme +[artplayer/types/utils.d.ts](https://github.com/zhw2590582/ArtPlayer/blob/master/packages/artplayer/types/utils.d.ts) + +::: + +## `scheme` Returns the validation schema for player options. -Example code: +
▶ Run Code
+```js console.info(Artplayer.scheme); +``` -Emitter +## `Emitter` -Returns the constructor function for the event emitter. +Returns the constructor of the event emitter. -Example code: +
▶ Run Code
+```js console.info(Artplayer.Emitter); +``` -Validator +## `validator` Returns the validation function for options. -Example code: +
▶ Run Code
+```js console.info(Artplayer.validator); +``` -KindOf +## `kindOf` -Returns the utility function for type detection. +Returns the type detection utility function. -Example code: +
▶ Run Code
+```js console.info(Artplayer.kindOf); +``` -Html +## `html` -Returns the html string required by the player. +Returns the `html` string required by the player. -Example code: +
▶ Run Code
+```js console.info(Artplayer.html); +``` -Option +## `option` -Returns the default options for the player. +Returns the default options of the player. -Example code: +
▶ Run Code
+```js console.info(Artplayer.option); +``` -Instance Events +===== packages/artplayer-vitepress/docs/en/advanced/event.md ===== -Player events are divided into two types: native events (prefixed with video:) and custom events. +# Instance Events -Listen to an event: +Player events are divided into two types: `native events` of the video (prefixed with `video:`), and `custom events`. -Example code: +Listening to events: +
▶ Run Code
+ +```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -511,11 +669,13 @@ var art = new Artplayer({ art.on('video:canplay', () => { console.info('video:canplay'); }); +``` -Listen to an event only once: +Listening to an event only once: -Example code: +
▶ Run Code
+```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -524,22 +684,26 @@ var art = new Artplayer({ art.once('video:canplay', () => { console.info('video:canplay'); }); +``` -Manually trigger an event: +Manually triggering an event: -Example code: +
▶ Run Code
+```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', }); art.emit('focus'); +``` -Remove an event listener: +Removing an event: -Example code: +
▶ Run Code
+```js{8} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -551,15 +715,21 @@ const onReady = () => { } art.on('ready', onReady); +``` -For a complete list of events, please refer to: artplayer/types/events.d.ts +:::warning For a complete list of events, please refer to: -Ready Event +[artplayer/types/events.d.ts](https://github.com/zhw2590582/ArtPlayer/blob/master/packages/artplayer/types/events.d.ts) + +::: + +## `ready` Triggered when the player is ready for the first time. -Example code: +
▶ Run Code
+```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -568,13 +738,15 @@ var art = new Artplayer({ art.on('ready', () => { console.info('ready'); }); +``` -Restart Event +## `restart` -Triggered when the player switches URL and becomes playable. +Triggered when the player switches URLs and becomes ready to play. -Example code: +
▶ Run Code
+```js{10} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -587,13 +759,15 @@ art.on('ready', () => { art.on('restart', (url) => { console.info('restart', url); }); +``` -Pause Event +## `pause` Triggered when the player is paused. -Example code: +
▶ Run Code
+```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -602,28 +776,15 @@ var art = new Artplayer({ art.on('pause', () => { console.info('pause'); }); +``` -ArtPlayer Event Documentation +## `play` -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: +
▶ Run Code
+ +```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -632,11 +793,15 @@ var art = new Artplayer({ art.on('play', () => { console.info('play'); }); +``` -Event: hotkey -Triggered when a hotkey is pressed on the player. The event object contains details about the key press. +## `hotkey` -Example code: +Triggered when a player hotkey is pressed. + +
▶ Run Code
+ +```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -645,11 +810,15 @@ var art = new Artplayer({ art.on('hotkey', (event) => { console.info('hotkey', event); }); +``` -Event: destroy -Triggered when the player instance is destroyed. This example shows destroying the player in the ready event handler. +## `destroy` -Example code: +Triggered when the player is destroyed. + +
▶ Run Code
+ +```js{10} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -662,11 +831,15 @@ art.on('ready', () => { art.on('destroy', () => { console.info('destroy'); }); +``` -Event: focus -Triggered when the player element gains focus. +## `focus` -Example code: +Triggered when the player gains focus. + +
▶ Run Code
+ +```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -675,11 +848,15 @@ var art = new Artplayer({ art.on('focus', (event) => { console.info('focus', event); }); +``` -Event: blur -Triggered when the player element loses focus. +## `blur` -Example code: +Triggered when the player loses focus. + +
▶ Run Code
+ +```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -688,11 +865,15 @@ var art = new Artplayer({ art.on('blur', (event) => { console.info('blur', event); }); +``` + +## `dblclick` -Event: dblclick Triggered when the player is double-clicked. -Example code: +
▶ Run Code
+ +```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -701,11 +882,15 @@ var art = new Artplayer({ art.on('dblclick', (event) => { console.info('dblclick', event); }); +``` + +## `click` -Event: click Triggered when the player is clicked. -Example code: +
▶ Run Code
+ +```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -714,11 +899,15 @@ var art = new Artplayer({ art.on('click', (event) => { console.info('click', event); }); +``` -Event: error -Triggered when an error occurs while loading the video. The callback provides the error and a reconnectTime parameter. +## `error` -Example code: +Triggered when an error occurs while the player is loading a video. + +
▶ Run Code
+ +```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/404.mp4', @@ -728,10 +917,15 @@ art.on('error', (error, reconnectTime) => { console.info(error, reconnectTime); }); -Event: hover -Triggered when the mouse enters or leaves the player area. The state parameter indicates 'enter' or 'leave'. +``` -Example code: +## `hover` + +Triggered when the mouse enters or leaves the player. + +
▶ Run Code
+ +```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -740,11 +934,15 @@ var art = new Artplayer({ art.on('hover', (state, event) => { console.info('hover', state, event); }); +``` + +## `mousemove` -Event: mousemove Triggered when the mouse moves over the player. -Example code: +
▶ Run Code
+ +```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -753,11 +951,15 @@ var art = new Artplayer({ art.on('mousemove', (event) => { console.info('mousemove', event); }); +``` -Event: resize -Triggered when the player's container dimensions change. +## `resize` -Example code: +Triggered when the player's dimensions change. + +
▶ Run Code
+ +```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -766,11 +968,15 @@ var art = new Artplayer({ art.on('resize', () => { console.info('resize'); }); +``` -Event: view -Triggered when the player enters or leaves the browser viewport. The state parameter indicates the visibility. +## `view` -Example code: +Triggered when the player enters the viewport. + +
▶ Run Code
+ +```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -779,11 +985,15 @@ var art = new Artplayer({ art.on('view', (state) => { console.info('view', state); }); +``` -Event: lock -Triggered when the screen lock state changes, primarily on mobile devices. Requires the lock option to be enabled. +## `lock` -Example code: +Triggered when the lock state changes on mobile devices. + +
▶ Run Code
+ +```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -793,11 +1003,15 @@ var art = new Artplayer({ art.on('lock', (state) => { console.info('lock', state); }); +``` -Event: aspectRatio -Triggered when the player's aspect ratio changes. Requires the aspectRatio and setting options to be enabled. +## `aspectRatio` -Example code: +Triggered when the player's aspect ratio changes. + +
▶ Run Code
+ +```js{8} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -808,11 +1022,15 @@ var art = new Artplayer({ art.on('aspectRatio', (aspectRatio) => { console.info('aspectRatio', aspectRatio); }); +``` -Event: autoHeight -Triggered when the player automatically adjusts its height, typically after calling the art.autoHeight() method. +## `autoHeight` -Example code: +Triggered when the player's height is automatically set. + +
▶ Run Code
+ +```js{10} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -825,11 +1043,15 @@ art.on('ready', () => { art.on('autoHeight', (height) => { console.info('autoHeight', height); }); +``` -Event: autoSize -Triggered when the player automatically adjusts its size. Requires the autoSize option to be enabled. +## `autoSize` -Example code: +Triggered when the player's size is automatically set. + +
▶ Run Code
+ +```js{7} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -839,11 +1061,15 @@ var art = new Artplayer({ art.on('autoSize', () => { console.info('autoSize'); }); +``` -Event: flip -Triggered when the video flip state changes. Requires the flip and setting options to be enabled. +## `flip` -Example code: +Triggered when the player is flipped. + +
▶ Run Code
+ +```js{8} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -854,11 +1080,15 @@ var art = new Artplayer({ art.on('flip', (flip) => { console.info('flip', flip); }); +``` -Event: fullscreen -Triggered when the player enters or exits traditional window fullscreen mode. Requires the fullscreen option. +## `fullscreen` -Example code: +Triggered when the player enters or exits windowed fullscreen mode. + +
▶ Run Code
+ +```js{7} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -868,28 +1098,36 @@ var art = new Artplayer({ art.on('fullscreen', (state) => { console.info('fullscreen', state); }); +``` -Event: fullscreenError -Triggered when an error occurs while attempting to enter window fullscreen mode. +## `fullscreenError` -Example code: +Triggered when a windowed fullscreen error occurs. + +
▶ Run Code
+ +```js var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', }); art.on('ready', () => { - art.fullscreen = true; + art.fullscreen = true; }); art.on('fullscreenError', (event) => { console.info('fullscreenError', event); }); +``` -Event: fullscreenWeb -Triggered when the player enters or exits web fullscreen mode (fullscreen within the browser). Requires the fullscreenWeb option. +## `fullscreenWeb` -Example code: +Triggered when the player enters or exits web fullscreen mode. + +
▶ Run Code
+ +```js{7} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -899,11 +1137,15 @@ var art = new Artplayer({ art.on('fullscreenWeb', (state) => { console.info('fullscreenWeb', state); }); +``` -Event: mini -Triggered when the player enters or exits mini-player mode. +## `mini` -Example code: +Triggered when the player enters or exits mini mode. + +
▶ Run Code
+ +```js{10} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -916,11 +1158,15 @@ art.on('ready', () => { art.on('mini', (state) => { console.info('mini', state); }); +``` -Event: pip -Triggered when the player enters or exits picture-in-picture mode. Requires the pip option. +## `pip` -Example code: +Triggered when the player enters or exits Picture-in-Picture mode. + +
▶ Run Code
+ +```js{7} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -931,10 +1177,15 @@ art.on('pip', (state) => { console.info('pip', state); }); -Event: screenshot -Triggered when a screenshot is captured. Requires the screenshot option. The callback receives the image as a Data URI. +``` -Example code: +## `screenshot` + +Triggered when the player takes a screenshot. + +
▶ Run Code
+ +```js{7} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -944,11 +1195,15 @@ var art = new Artplayer({ art.on('screenshot', (dataUri) => { console.info('screenshot', dataUri); }); +``` -Event: seek -Triggered when the playback time is sought, either by dragging the progress bar or calling a method. +## `seek` -Example code: +Triggered when the player performs a time seek. + +
▶ Run Code
+ +```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -957,11 +1212,15 @@ var art = new Artplayer({ art.on('seek', (currentTime) => { console.info('seek', currentTime); }); +``` -Event: subtitleOffset -Triggered when the subtitle synchronization offset is changed. Requires the subtitleOffset option and a subtitle track. +## `subtitleOffset` -Example code: +Triggered when the subtitle offset changes in the player. + +
▶ Run Code
+ +```js{11} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -972,23 +1231,18 @@ var art = new Artplayer({ setting: true, }); -ArtPlayer Event: subtitleOffset - -Triggered when the subtitle offset changes. - -Example usage: - art.on('subtitleOffset', (offset) => { console.info('subtitleOffset', offset); }); +``` - -ArtPlayer Event: subtitleBeforeUpdate +## `subtitleBeforeUpdate` Triggered before subtitles are updated. -Example usage: +
▶ Run Code
+```js{9} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -1000,14 +1254,15 @@ var art = new Artplayer({ art.on('subtitleBeforeUpdate', (cues) => { console.info('subtitleBeforeUpdate', cues); }); +``` - -ArtPlayer Event: subtitleAfterUpdate +## `subtitleAfterUpdate` Triggered after subtitles are updated. -Example usage: +
▶ Run Code
+```js{9} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -1019,14 +1274,15 @@ var art = new Artplayer({ art.on('subtitleAfterUpdate', (cues) => { console.info('subtitleAfterUpdate', cues); }); +``` - -ArtPlayer Event: subtitleLoad +## `subtitleLoad` Triggered when subtitles are loaded. -Example usage: +
▶ Run Code
+```js{9} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -1038,14 +1294,15 @@ var art = new Artplayer({ art.on('subtitleLoad', (option, cues) => { console.info('subtitleLoad', cues, option); }); +``` - -ArtPlayer Event: info +## `info` Triggered when the info panel is shown or hidden. -Example usage: +
▶ Run Code
+```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -1054,14 +1311,15 @@ var art = new Artplayer({ art.on('info', (state) => { console.log(state); }); +``` +## `layer` -ArtPlayer Event: layer +Triggered when a custom layer is shown or hidden. -Triggered when custom layers are shown or hidden. - -Example usage: +
▶ Run Code
+```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -1070,14 +1328,15 @@ var art = new Artplayer({ art.on('layer', (state) => { console.log(state); }); +``` - -ArtPlayer Event: loading +## `loading` Triggered when the loader is shown or hidden. -Example usage: +
▶ Run Code
+```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -1086,14 +1345,15 @@ var art = new Artplayer({ art.on('loading', (state) => { console.log(state); }); +``` - -ArtPlayer Event: mask +## `mask` Triggered when the mask layer is shown or hidden. -Example usage: +
▶ Run Code
+```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -1102,14 +1362,15 @@ var art = new Artplayer({ art.on('mask', (state) => { console.log(state); }); +``` - -ArtPlayer Event: subtitle +## `subtitle` Triggered when the subtitle layer is shown or hidden. -Example usage: +
▶ Run Code
+```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -1118,14 +1379,15 @@ var art = new Artplayer({ art.on('subtitle', (state) => { console.log(state); }); +``` - -ArtPlayer Event: contextmenu +## `contextmenu` Triggered when the context menu is shown or hidden. -Example usage: +
▶ Run Code
+```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -1134,14 +1396,15 @@ var art = new Artplayer({ art.on('contextmenu', (state) => { console.log(state); }); +``` +## `control` -ArtPlayer Event: control +Triggered when the control bar is shown or hidden. -Triggered when the controls are shown or hidden. - -Example usage: +
▶ Run Code
+```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -1150,14 +1413,15 @@ var art = new Artplayer({ art.on('control', (state) => { console.log(state); }); +``` - -ArtPlayer Event: setting +## `setting` Triggered when the settings panel is shown or hidden. -Example usage: +
▶ Run Code
+```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -1168,13 +1432,15 @@ art.on('setting', (state) => { console.log(state); }); +``` -ArtPlayer Event: muted +## `muted` -Triggered when the mute state changes. +Triggered when the muted state changes. -Example usage: +
▶ Run Code
+```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -1183,14 +1449,15 @@ var art = new Artplayer({ art.on('muted', (state) => { console.log(state); }); +``` +## `keydown` -ArtPlayer Event: keydown +Listens for the `keydown` event from the `document`. -Listens for keydown events from the document. - -Example usage: +
▶ Run Code
+```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -1199,106 +1466,160 @@ var art = new Artplayer({ art.on('keydown', (event) => { console.log(event.code); }); +``` +## `video:canplay` -Video Element Events +The browser can start playing the media, but estimates there is not enough data to play through to the end without stopping for further buffering. -The following are standard HTML5 video events that ArtPlayer can listen to. +## `video:canplaythrough` -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. +The browser estimates it can play the media through to the end without stopping for buffering. -video:canplaythrough - The browser estimates it can play the media through to the end without stopping to buffer content. +## `video:complete` -video:complete - OfflineAudioContext rendering is complete. +The OfflineAudioContext rendering is complete. -video:durationchange - Triggered when the value of the duration property changes. +## `video:durationchange` -video:emptied - The media has become empty; for example, this event is sent when the media has already been loaded (or partially loaded), and the load() method is called to reload it. +Triggered when the value of the `duration` property changes. -video:ended - Playback has stopped because the media has reached its end point. +## `video:emptied` -video:error - An error occurred while fetching media data, or the resource type is not a supported media format. +The media has become empty; for example, this event is sent when the media has already been loaded (or partially loaded), and the `load()` method is called to reload it. -video:loadeddata - The first frame of the media has finished loading. +## `video:ended` -video:loadedmetadata - Metadata has been loaded. +Playback has stopped because the media has reached its end. -video:pause - Playback has been paused. +## `video:error` -video:play - Playback has begun. +An error occurred while fetching the media data, or the resource type is not a supported media format. -video:playing - Playback is ready to start after having been paused or delayed due to lack of data. +## `video:loadeddata` -video:progress - Periodically triggered while the browser is loading the resource. +The first frame of the media has finished loading. -video:ratechange - The playback rate has changed. +## `video:loadedmetadata` -video:seeked - A seek operation has completed. +Metadata has been loaded. -video:seeking - A seek operation has begun. +## `video:pause` -video:stalled - The user agent is trying to fetch media data, but data is unexpectedly not forthcoming. +Playback has been paused. -video:suspend - Media data loading has been suspended. +## `video:play` -video:timeupdate - The time indicated by the currentTime attribute has been updated. +Playback has begun. -video:volumechange - The volume has changed. +## `video:playing` -video:waiting - Playback has stopped due to temporary lack of data. +Playback is ready to start after having been paused or delayed due to lack of data. +## `video:progress` -Global Properties +Fired periodically as the browser loads the resource. -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. +## `video:ratechange` -DEBUG - Whether to enable debug mode, which can print all built-in events of the video. Default is off. +The playback rate has changed. -Example usage: +## `video:seeked` +A seek operation has completed. + +## `video:seeking` + +A seek operation has begun. + +## `video:stalled` + +The user agent is trying to fetch media data, but data is unexpectedly not forthcoming. + +## `video:suspend` + +Media data loading has been suspended. + +## `video:timeupdate` + +The time indicated by the `currentTime` property has changed. + +## `video:volumechange` + +The volume has changed. + +## `video:waiting` + +Playback has stopped because of a temporary lack of data. + +===== packages/artplayer-vitepress/docs/en/advanced/global.md ===== + +# Global Properties + +The `global properties` here refer to the `top-level properties` mounted on the `constructor`. All property names are in uppercase. These are subject to change in the future and are rarely used. + +## DEBUG + +Whether to enable `debug` mode, which can print all built-in video events. Default is off. + +
▶ Run Code
+ +```js Artplayer.DEBUG = true; var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', }); +``` +## STYLE -STYLE - Returns the player style text. +Returns the player style text. -Example usage: +
▶ Run Code
+```js console.log(Artplayer.STYLE); +``` +## CONTEXTMENU -CONTEXTMENU - Whether to enable the context menu. Default is on. +Whether to enable the context menu. Default is on. -Example usage: +
▶ Run Code
+```js Artplayer.CONTEXTMENU = false; var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', }); +``` +## NOTICE_TIME -NOTICE_TIME - The display duration for notification messages, in milliseconds. Default is 2000. +The display duration of notification messages, in milliseconds. Default is `2000`. -Example usage: +
▶ Run Code
+```js Artplayer.NOTICE_TIME = 5000; var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', }); +``` +## SETTING_WIDTH -SETTING_WIDTH - The default width of the settings panel, in pixels. Default is 250. +The default width of the settings panel, in pixels. Default is `250`. -Example usage: +
▶ Run Code
+```js Artplayer.SETTING_WIDTH = 300; var art = new Artplayer({ @@ -1310,12 +1631,15 @@ var art = new Artplayer({ playbackRate: true, aspectRatio: true, }); +``` +## SETTING_ITEM_WIDTH -SETTING_ITEM_WIDTH - The default width of settings items in the settings panel, in pixels. Default is 200. +The default width of a setting item in the settings panel, in pixels. Default is `200`. -Example usage: +
▶ Run Code
+```js Artplayer.SETTING_ITEM_WIDTH = 300; var art = new Artplayer({ @@ -1327,31 +1651,15 @@ var art = new Artplayer({ playbackRate: true, aspectRatio: true, }); +``` +## SETTING_ITEM_HEIGHT -SETTING_ITEM_HEIGHT - The default height of settings items in the settings panel, in pixels. Default is 35. +The default height of a setting item 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. - -Example of setting a custom height and initializing a player with various settings enabled: +
▶ Run Code
+```js Artplayer.SETTING_ITEM_HEIGHT = 40; var art = new Artplayer({ @@ -1363,12 +1671,15 @@ var art = new Artplayer({ playbackRate: true, aspectRatio: true, }); +``` -RESIZE_TIME -The throttle time for the resize event, in milliseconds. The default is 200. +## RESIZE_TIME -Example of setting a custom throttle time and listening for the resize event: +The throttle time for the `resize` event, in milliseconds. Default is `200`. +
▶ Run Code
+ +```js Artplayer.RESIZE_TIME = 500; var art = new Artplayer({ @@ -1379,12 +1690,15 @@ var art = new Artplayer({ art.on('resize', () => { console.log('resize'); }); +``` -SCROLL_TIME -The throttle time for the scroll event, in milliseconds. The default is 200. +## SCROLL_TIME -Example of setting a custom throttle time and listening for the scroll event: +The throttle time for the `scroll` event, in milliseconds. Default is `200`. +
▶ Run Code
+ +```js Artplayer.SCROLL_TIME = 500; var art = new Artplayer({ @@ -1395,12 +1709,15 @@ var art = new Artplayer({ art.on('scroll', () => { console.log('scroll'); }); +``` -SCROLL_GAP -The boundary tolerance distance for the view event, in pixels. The default is 50. +## SCROLL_GAP -Example of setting a custom gap and listening for the scroll event: +The boundary tolerance distance for the `view` event, in pixels. Default is `50`. +
▶ Run Code
+ +```js Artplayer.SCROLL_GAP = 100; var art = new Artplayer({ @@ -1411,12 +1728,15 @@ var art = new Artplayer({ art.on('scroll', () => { console.log('scroll'); }); +``` -AUTO_PLAYBACK_MAX -The maximum record count for the auto-playback feature. The default is 10. +## AUTO_PLAYBACK_MAX -Example of setting a custom maximum and enabling auto-playback: +The maximum record count for the auto-playback feature. Default is `10`. +
▶ Run Code
+ +```js Artplayer.AUTO_PLAYBACK_MAX = 20; var art = new Artplayer({ @@ -1424,12 +1744,15 @@ var art = new Artplayer({ url: '/assets/sample/video.mp4', autoPlayback: true, }); +``` -AUTO_PLAYBACK_MIN -The minimum record duration for the auto-playback feature, in seconds. The default is 5. +## AUTO_PLAYBACK_MIN -Example of setting a custom minimum duration and enabling auto-playback: +The minimum record duration for the auto-playback feature, in seconds. Default is `5`. +
▶ Run Code
+ +```js Artplayer.AUTO_PLAYBACK_MIN = 10; var art = new Artplayer({ @@ -1437,12 +1760,15 @@ var art = new Artplayer({ url: '/assets/sample/video.mp4', autoPlayback: true, }); +``` -AUTO_PLAYBACK_TIMEOUT -The hide delay duration for the auto-playback feature, in milliseconds. The default is 3000. +## AUTO_PLAYBACK_TIMEOUT -Example of setting a custom timeout and enabling auto-playback: +The hide delay duration for the auto-playback feature, in milliseconds. Default is `3000`. +
▶ Run Code
+ +```js Artplayer.AUTO_PLAYBACK_TIMEOUT = 5000; var art = new Artplayer({ @@ -1450,24 +1776,30 @@ var art = new Artplayer({ url: '/assets/sample/video.mp4', autoPlayback: true, }); +``` -RECONNECT_TIME_MAX -The maximum number of automatic reconnection attempts when a connection error occurs. The default is 5. +## RECONNECT_TIME_MAX -Example of setting a custom maximum reconnection count: +The maximum number of automatic reconnection attempts when a connection error occurs. Default is `5`. +
▶ Run Code
+ +```js Artplayer.RECONNECT_TIME_MAX = 10; var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/404.mp4', }); +``` -RECONNECT_SLEEP_TIME -The delay time for automatic reconnection when a connection error occurs, in milliseconds. The default is 1000. +## RECONNECT_SLEEP_TIME -Example of setting a custom reconnection delay: +The delay time for automatic reconnection when a connection error occurs, in milliseconds. Default is `1000`. +
▶ Run Code
+ +```js Artplayer.RECONNECT_SLEEP_TIME = 3000; var art = new Artplayer({ @@ -1475,23 +1807,30 @@ var art = new Artplayer({ url: '/assets/sample/404.mp4', }); -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: +## CONTROL_HIDE_TIME +The auto-hide delay time for the bottom control bar, in milliseconds. Default is `3000`. + +
▶ Run Code
+ +```js Artplayer.CONTROL_HIDE_TIME = 5000; var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', }); +``` -DBCLICK_TIME -The delay time in milliseconds for double-click events. The default is 300. +## DBCLICK_TIME -Example of setting a custom double-click delay and listening for the event: +The delay time for the double-click event, in milliseconds. Default is `300`. +
▶ Run Code
+ +```js Artplayer.DBCLICK_TIME = 500; var art = new Artplayer({ @@ -1502,48 +1841,60 @@ var art = new Artplayer({ art.on('dblclick', () => { console.log('dblclick'); }); +``` -DBCLICK_FULLSCREEN -On desktop, determines whether double-click toggles fullscreen mode. The default is true. +## DBCLICK_FULLSCREEN -Example of disabling double-click fullscreen: +On desktop, whether double-click toggles fullscreen. Default is `true`. +
▶ Run Code
+ +```js Artplayer.DBCLICK_FULLSCREEN = false; var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', }); +``` -MOBILE_DBCLICK_PLAY -On mobile devices, determines whether double-click toggles play/pause. The default is true. +## MOBILE_DBCLICK_PLAY -Example of disabling double-click play/pause on mobile: +On mobile, whether double-click toggles play/pause. Default is `true`. +
▶ Run Code
+ +```js Artplayer.MOBILE_DBCLICK_PLAY = false; var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', }); +``` -MOBILE_CLICK_PLAY -On mobile devices, determines whether single-click toggles play/pause. The default is false. +## MOBILE_CLICK_PLAY -Example of enabling single-click play/pause on mobile: +On mobile, whether single-click toggles play/pause. Default is `false`. +
▶ Run Code
+ +```js Artplayer.MOBILE_CLICK_PLAY = true; var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', }); +``` -AUTO_ORIENTATION_TIME -On mobile devices, the delay time in milliseconds for automatic screen rotation. The default is 200. +## AUTO_ORIENTATION_TIME -Example of setting a custom orientation delay and enabling auto-orientation: +On mobile, the delay time for auto-rotation, in milliseconds. Default is `200`. +
▶ Run Code
+ +```js Artplayer.AUTO_ORIENTATION_TIME = 500; var art = new Artplayer({ @@ -1551,12 +1902,15 @@ var art = new Artplayer({ url: '/assets/sample/video.mp4', autoOrientation: true, }); +``` -INFO_LOOP_TIME -The refresh interval in milliseconds for the information panel. The default is 1000. +## INFO_LOOP_TIME -Example of setting a custom refresh interval and showing the info panel: +The refresh interval for the info panel, in milliseconds. Default is `1000`. +
▶ Run Code
+ +```js Artplayer.INFO_LOOP_TIME = 2000; var art = new Artplayer({ @@ -1565,12 +1919,15 @@ var art = new Artplayer({ }); art.info.show = true; +``` -FAST_FORWARD_VALUE -On mobile devices, the speed multiplier for fast-forward during long-press. The default is 3. +## FAST_FORWARD_VALUE -Example of setting a custom fast-forward speed and enabling the feature: +On mobile, the speed multiplier for long-press fast-forward. Default is `3`. +
▶ Run Code
+ +```js Artplayer.FAST_FORWARD_VALUE = 5; var art = new Artplayer({ @@ -1578,12 +1935,15 @@ var art = new Artplayer({ url: '/assets/sample/video.mp4', fastForward: true, }); +``` -FAST_FORWARD_TIME -On mobile devices, the delay time in milliseconds for activating fast-forward during long-press. The default is 1000. +## FAST_FORWARD_TIME -Example of setting a custom activation delay and enabling fast-forward: +On mobile, the delay time for long-press fast-forward, in milliseconds. Default is `1000`. +
▶ Run Code
+ +```js Artplayer.FAST_FORWARD_TIME = 2000; var art = new Artplayer({ @@ -1591,48 +1951,60 @@ var art = new Artplayer({ url: '/assets/sample/video.mp4', fastForward: true, }); +``` -TOUCH_MOVE_RATIO -On mobile devices, the speed multiplier for seeking when swiping left/right. The default is 0.5. +## TOUCH_MOVE_RATIO -Example of setting a custom seek sensitivity: +On mobile, the speed multiplier for left/right swipe to seek. Default is `0.5`. +
▶ Run Code
+ +```js Artplayer.TOUCH_MOVE_RATIO = 1; var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', }); +``` -VOLUME_STEP -The volume adjustment step for keyboard shortcuts. The default is 0.1. +## VOLUME_STEP -Example of setting a custom volume step: +The step size for volume adjustment via keyboard shortcuts. Default is `0.1`. +
▶ Run Code
+ +```js Artplayer.VOLUME_STEP = 0.2; var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', }); +``` -SEEK_STEP -The seeking step in seconds for keyboard shortcuts. The default is 5. +## SEEK_STEP -Example of setting a custom seek step: +The step size for seeking via keyboard shortcuts, in seconds. Default is `5`. +
▶ Run Code
+ +```js Artplayer.SEEK_STEP = 10; var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', }); +``` -PLAYBACK_RATE -The built-in list of playback rates. The default is [0.5, 0.75, 1, 1.25, 1.5, 2]. +## PLAYBACK_RATE -Example of setting a custom playback rate list and enabling the feature in settings: +The built-in list of playback rates. Default is `[0.5, 0.75, 1, 1.25, 1.5, 2]`. +
▶ Run Code
+ +```js Artplayer.PLAYBACK_RATE = [0.5, 1, 2, 3, 4, 5]; var art = new Artplayer({ @@ -1644,12 +2016,15 @@ var art = new Artplayer({ art.contextmenu.show = true; art.setting.show = true; +``` -ASPECT_RATIO -The built-in list of video aspect ratios. The default is ['default', '4:3', '16:9']. +## ASPECT_RATIO -Example of setting a custom aspect ratio list and enabling the feature in settings: +The built-in list of video aspect ratios. Default is `['default', '4:3', '16:9']`. +
▶ Run Code
+ +```js Artplayer.ASPECT_RATIO = ['default', '1:1', '2:1', '4:3', '6:5']; var art = new Artplayer({ @@ -1661,12 +2036,15 @@ var art = new Artplayer({ art.contextmenu.show = true; art.setting.show = true; +``` -FLIP -The built-in list of video flip modes. The default is ['normal', 'horizontal', 'vertical']. +## FLIP -Example of setting a custom flip mode list and enabling the feature in settings: +The built-in list of video flip options. Default is `['normal', 'horizontal', 'vertical']`. +
▶ Run Code
+ +```js Artplayer.FLIP = ['normal', 'horizontal']; var art = new Artplayer({ @@ -1679,26 +2057,15 @@ 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. +``` -Example of setting this property: +## FULLSCREEN_WEB_IN_BODY -Artplayer.FULLSCREEN_WEB_IN_BODY = false; +Whether to mount the player under the `body` element during web fullscreen mode. Default is `true`. -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 is applied to the entire web page body. By default, it is set to false. - -Example: +
▶ Run Code
+```js Artplayer.FULLSCREEN_WEB_IN_BODY = false; var art = new Artplayer({ @@ -1706,26 +2073,30 @@ var art = new Artplayer({ url: '/assets/sample/video.mp4', fullscreenWeb: true, }); +``` -LOG_VERSION +## LOG_VERSION -Sets whether to print the player version in the console. The default value is true. +Sets whether to print the player version. Default is `true`. -Example: +
▶ Run Code
+```js Artplayer.LOG_VERSION = false; var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', }); +``` -USE_RAF +## USE_RAF -Sets whether to use requestAnimationFrame for smoother animations, such as the progress bar. The default value is false. +Sets whether to use `requestAnimationFrame`. Default is `false`. Currently, it is primarily used for smooth progress bar effects. -Example: +
▶ Run Code
+```js Artplayer.USE_RAF = true; var art = new Artplayer({ @@ -1733,13 +2104,17 @@ var art = new Artplayer({ url: '/assets/sample/video.mp4', miniProgressBar: true, }); +``` -REMOVE_SRC_WHEN_DESTROY +## REMOVE_SRC_WHEN_DESTROY -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. +Whether to remove the video's `src` attribute and call `load()` to actively release media resources when destroying the player. Default is `true`. -Example: +Enabling this can reduce video resource usage in single-page applications or scenarios where players are frequently created/destroyed. If you wish to preserve the state of the video element and only remove the UI, you can set this to `false`. +
▶ Run Code
+ +```js Artplayer.REMOVE_SRC_WHEN_DESTROY = false; var art = new Artplayer({ @@ -1747,15 +2122,21 @@ var art = new Artplayer({ url: '/assets/sample/video.mp4', }); -// Only destroys the UI, does not actively clear src +// Only destroy the UI, do not actively clear the src art.destroy(); +``` -Writing Plugins +===== packages/artplayer-vitepress/docs/en/advanced/plugin.md ===== -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. +# Writing Plugins -Loading a plugin during instantiation: +Once you are familiar with the player's `properties`, `methods`, and `events`, writing a plugin becomes a very straightforward task. +You can load a plugin function during instantiation. + +
▶ Run Code
+ +```js{15} function myPlugin(art) { console.info(art); return { @@ -1776,9 +2157,13 @@ var art = new Artplayer({ art.on('ready', () => { console.info(art.plugins.myPlugin); }); +``` -Loading a plugin after instantiation: +You can also load a plugin function after instantiation. +
▶ Run Code
+ +```js{17} function myPlugin(art) { console.info(art); return { @@ -1800,11 +2185,13 @@ art.plugins.add(myPlugin); art.on('ready', () => { console.info(art.plugins.myPlugin); }); +``` -Example Plugin: Displaying an Image Ad on Pause +For example, let's say I want to write a plugin that displays an image ad when the video is paused. -This plugin shows an image ad when the video is paused and provides controls to hide or show it. +
▶ Run Code
+```js function adsPlugin(option) { return (art) => { art.layers.add({ @@ -1865,18 +2252,23 @@ var art = new Artplayer({ }) ], }); +``` -Instance Properties +===== packages/artplayer-vitepress/docs/en/advanced/property.md ===== -These are first-level properties available on the player instance. +# Instance Properties -play +Here, `Instance Properties` refer to the `first-level properties` mounted on the `instance`, which are commonly used. -Type: Function -Plays the video. +## `play` -Example: +- Type: `Function` +Play the video. + +
▶ Run Code
+ +```js{8} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -1886,14 +2278,17 @@ var art = new Artplayer({ art.on('ready', () => { art.play(); }); +``` -pause +## `pause` -Type: Function -Pauses the video. +- Type: `Function` -Example: +Pause the video. +
▶ Run Code
+ +```js{11} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -1907,14 +2302,17 @@ art.on('ready', () => { art.pause(); }, 3000); }); +``` -toggle +## `toggle` -Type: Function -Toggles between play and pause. +- Type: `Function` -Example: +Toggle video play and pause. +
▶ Run Code
+ +```js{11} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -1928,15 +2326,18 @@ art.on('ready', () => { art.toggle(); }, 3000); }); +``` -destroy +## `destroy` -Type: Function -Parameter: Boolean -Destroys the player. Accepts a boolean parameter indicating whether to remove the player's HTML from the DOM after destruction. Defaults to true. +- Type: `Function` +- Parameter: `Boolean` -Example: +Destroy the player. Accepts a parameter indicating whether to also remove the player's `html` after destruction. Defaults to `true`. +
▶ Run Code
+ +```js{7} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -1945,14 +2346,19 @@ var art = new Artplayer({ art.on('ready', () => { art.destroy(); }); +``` -reset +## `reset` -Type: Function -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. +- Type: `Function` -Example: +Reset the player's video element: removes the current `src` and calls `load()` once. Commonly used to manually release media resources or reinitialize the video tag in single-page applications. +> Note: The global configuration `Artplayer.REMOVE_SRC_WHEN_DESTROY` will also automatically execute similar logic when `destroy()` is called. + +
▶ Run Code
+ +```js{9} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -1962,15 +2368,18 @@ art.on('ready', () => { // Only reset the video, do not remove the interface art.reset(); }); +``` -seek +## `seek` -Type: Setter -Parameter: Number -Seeks to a specific time in the video, in seconds. +- Type: `Setter` +- Parameter: `Number` -Example: +Seek to a specific time in the video, in seconds. +
▶ Run Code
+ +```js{7} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -1979,15 +2388,18 @@ var art = new Artplayer({ art.on('ready', () => { art.seek = 5; }); +``` -forward +## `forward` -Type: Setter -Parameter: Number -Fast-forwards the video by a specified number of seconds. +- Type: `Setter` +- Parameter: `Number` -Example: +Fast-forward the video time, in seconds. +
▶ Run Code
+ +```js{7} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -1996,15 +2408,18 @@ var art = new Artplayer({ art.on('ready', () => { art.forward = 5; }); +``` -backward +## `backward` -Type: Setter -Parameter: Number -Rewinds the video by a specified number of seconds. +- Type: `Setter` +- Parameter: `Number` -Example: +Rewind the video time, in seconds. +
▶ Run Code
+ +```js{10} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2017,15 +2432,18 @@ art.on('ready', () => { art.backward = 2; }, 3000); }); +``` -volume +## `volume` -Type: Setter/Getter -Parameter: Number -Sets or gets the video volume. The value must be between 0 and 1. +- Type: `Setter/Getter` +- Parameter: `Number` -Example: +Set and get the video volume, range: `[0, 1]`. +
▶ Run Code
+ +```js{8} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2036,37 +2454,38 @@ art.on('ready', () => { art.volume = 0.5; console.info(art.volume); }); +``` -url +## `url` -Type: Setter/Getter -Parameter: String -Sets or gets the video URL. +- Type: `Setter/Getter` +- Parameter: `String` -Example: +Set and get the video URL. +
▶ Run Code
+ +```js{7} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', }); -ArtPlayer Documentation - -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'; }); +``` -Property: switch -Type: Setter -Parameter: String -Description: Sets the video URL. Similar to `art.url` when setting, but performs some optimization operations. +## `switch` -Example: +- Type: `Setter` +- Parameter: `String` + +Set the video URL. Similar to `art.url` when setting, but performs some optimization operations. + +
▶ Run Code
+ +```js{9} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2078,13 +2497,18 @@ art.on('ready', () => { art.switch = '/assets/sample/video.mp4?t=0'; }, 3000); }); +``` -Method: switchUrl -Type: Function -Parameter: String -Description: Sets the video URL. Similar to `art.url` when setting, but performs some optimization operations. +## `switchUrl` -Example: +- Type: `Function` +- Parameter: `String` + +Set the video URL. Similar to `art.url` when setting, but performs some optimization operations. + +
▶ Run Code
+ +```js{9} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2097,14 +2521,24 @@ art.on('ready', () => { }, 3000); }); -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. +``` -Method: switchQuality -Type: Function -Parameter: String -Description: Sets the video quality URL. Similar to `art.switchUrl`, but retains the previous playback progress. +:::warning Note -Example: +`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` + +- Type: `Function` +- Parameter: `String` + +Sets the video quality URL. Similar to `art.switchUrl`, but retains the previous playback progress. + +
▶ Run Code
+ +```js{9} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2116,13 +2550,18 @@ art.on('ready', () => { art.switchQuality('/assets/sample/video.mp4?t=0'); }, 3000); }); +``` -Property: muted -Type: Setter/Getter -Parameter: Boolean -Description: Sets and gets whether the video is muted. +## `muted` -Example: +- Type: `Setter/Getter` +- Parameter: `Boolean` + +Sets or gets whether the video is muted. + +
▶ Run Code
+ +```js{8} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2133,13 +2572,18 @@ art.on('ready', () => { art.muted = true; console.info(art.muted); }); +``` -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. +## `currentTime` -Example: +- Type: `Setter/Getter` +- Parameter: `Number` + +Sets or gets the current playback time of the video. Setting the time is similar to `seek`, but it does not trigger additional events. + +
▶ Run Code
+ +```js{8} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2150,12 +2594,17 @@ art.on('ready', () => { art.currentTime = 5; console.info(art.currentTime); }); +``` -Property: duration -Type: Getter -Description: Gets the duration of the video. +## `duration` -Example: +- Type: `Getter` + +Gets the duration of the video. + +
▶ Run Code
+ +```js{7} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2164,14 +2613,23 @@ var art = new Artplayer({ 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`. +:::warning Note -Method: screenshot -Type: Function -Description: Downloads a screenshot of the current video frame. An optional parameter specifies the screenshot filename. +Some videos may not have a duration, such as live streams or videos that have not been fully decoded. In such cases, the obtained duration will be `0`. -Example: +::: + +## `screenshot` + +- Type: `Function` + +Downloads a screenshot of the current video frame. An optional parameter specifies the screenshot filename. + +
▶ Run Code
+ +```js{7} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2180,12 +2638,17 @@ var art = new Artplayer({ art.on('ready', () => { art.screenshot('your-name'); }); +``` -Method: getDataURL -Type: Function -Description: Gets the `base64` URL of a screenshot of the current video frame. Returns a `Promise`. +## `getDataURL` -Example: +- Type: `Function` + +Gets the `base64` URL of a screenshot of the current video frame. Returns a `Promise`. + +
▶ Run Code
+ +```js{7} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2193,14 +2656,19 @@ var art = new Artplayer({ art.on('ready', async () => { const url = await art.getDataURL(); - console.info(url) + console.info(url) }); +``` -Method: getBlobUrl -Type: Function -Description: Gets the `blob` URL of a screenshot of the current video frame. Returns a `Promise`. +## `getBlobUrl` -Example: +- Type: `Function` + +Gets the `blob` URL of a screenshot of the current video frame. Returns a `Promise`. + +
▶ Run Code
+ +```js{7} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2210,13 +2678,18 @@ art.on('ready', async () => { const url = await art.getBlobUrl(); console.info(url); }); +``` -Property: fullscreen -Type: Setter/Getter -Parameter: Boolean -Description: Sets and gets the player's window fullscreen state. +## `fullscreen` -Example: +- Type: `Setter/Getter` +- Parameter: `Boolean` + +Sets or gets the player's window fullscreen state. + +
▶ Run Code
+ +```js{9} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2230,15 +2703,24 @@ 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. +:::warning Note -Property: fullscreenWeb -Type: Setter/Getter -Parameter: Boolean -Description: Sets and gets the player's web page fullscreen state. +Due to browser security mechanisms, a user interaction (e.g., a click on the page) must occur before triggering window fullscreen. -Example: +::: + +## `fullscreenWeb` + +- Type: `Setter/Getter` +- Parameter: `Boolean` + +Sets or gets the player's web page fullscreen state. + +
▶ Run Code
+ +```js{8,11} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2252,13 +2734,18 @@ art.on('ready', () => { art.fullscreenWeb = false; }, 3000); }); +``` -Property: pip -Type: Setter/Getter -Parameter: Boolean -Description: Sets and gets the player's Picture-in-Picture mode. +## `pip` -Example: +- Type: `Setter/Getter` +- Parameter: `Boolean` + +Sets or gets the player's Picture-in-Picture (PIP) mode. + +
▶ Run Code
+ +```js{9} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2272,15 +2759,24 @@ 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. +:::warning Note -Property: poster -Type: Setter/Getter -Parameter: String -Description: Sets and gets the video poster. The poster effect is only visible before video playback starts. +Due to browser security mechanisms, a user interaction (e.g., a click on the page) must occur before triggering Picture-in-Picture. -Example: +::: + +## `poster` + +- Type: `Setter/Getter` +- Parameter: `String` + +Sets and gets the video poster. The poster effect is only visible before the video starts playing. + +
▶ Run Code
+ +```js{9} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2292,13 +2788,18 @@ art.on('ready', () => { art.poster = '/assets/sample/poster.jpg?t=0'; console.info(art.poster); }); +``` -Property: mini -Type: Setter/Getter -Parameter: Boolean -Description: Sets and gets the player's mini mode. +## `mini` -Example: +- Type: `Setter/Getter` +- Parameter: `Boolean` + +Sets and gets the player's mini mode. + +
▶ Run Code
+ +```js{7} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2307,13 +2808,18 @@ var art = new Artplayer({ art.on('ready', () => { art.mini = true; }); +``` -Property: playing -Type: Getter -Parameter: Boolean -Description: Gets whether the video is currently playing. +## `playing` -Example: +- Type: `Getter` +- Parameter: `Boolean` + +Gets whether the video is currently playing. + +
▶ Run Code
+ +```js{8} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2323,28 +2829,38 @@ var art = new Artplayer({ art.on('ready', () => { console.info(art.playing); }); +``` -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). +## `state` -Example: +- Type: `Setter/Getter` +- Parameter: `String` + +Gets or sets the player's current state. Supported values: `standard` (normal), `mini` (mini window), `pip` (picture-in-picture), `fullscreen` (window fullscreen), `fullscreenWeb` (webpage fullscreen). + +
▶ Run Code
+ +```js{8} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', }); art.on('ready', () => { - console.info(art.state); // Default: standard + console.info(art.state); // Default is 'standard' art.state = 'mini'; }); +``` -Method: autoSize -Type: Function -Description: Sets whether the video adapts its size automatically. +## `autoSize` -Example: +- Type: `Function` + +Sets whether the video adapts its size automatically. + +
▶ Run Code
+ +```js{8} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2353,21 +2869,17 @@ var art = new Artplayer({ art.on('ready', () => { art.autoSize(); }); +``` -Property: rect -Type: Getter -Description: Gets the player's dimensions and coordinate information. +## `rect` -Example: -var art = new Artplayer({ - container: '.artplayer-app', - url: '/assets/sample/video.mp4', -}); +- Type: `Getter` -Here is the documentation reorganized into a clean, plain text format. +Gets the player's dimensions and coordinate information. -First, an example of how to access the player's rect property, which contains its dimensions and coordinates. The information is obtained via getBoundingClientRect. +
▶ Run Code
+```js{7} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2376,9 +2888,26 @@ var art = new Artplayer({ art.on('ready', () => { console.info(JSON.stringify(art.rect)); }); +``` -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. +:::warning Note +The dimension and coordinate information is obtained via `getBoundingClientRect`. + +::: + +## `bottom` / `top` / `left` / `right` / `x` / `y` / `width` / `height` + +- Type: `Getter` + +These properties provide quick access to `rect`: + +- `bottom`, `top`, `left`, `right`, `x`, `y`: Correspond to the fields of the same name in `DOMRect`. +- `width`, `height`: The player's current visible width and height. + +
▶ Run Code
+ +```js{7} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2387,9 +2916,18 @@ var art = new Artplayer({ art.on('ready', () => { console.info(art.width, art.height, art.left, art.top); }); +``` -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. +## `flip` +- Type: `Setter/Getter` +- Parameter: `String` + +Sets and gets the player's flip state. Supported values: `normal`, `horizontal`, `vertical`. + +
▶ Run Code
+ +```js{8} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2400,9 +2938,18 @@ art.on('ready', () => { art.flip = 'horizontal'; console.info(art.flip); }); +``` -The playbackRate property is a setter and getter for the player's playback speed. It accepts a number parameter. +## `playbackRate` +- Type: `Setter/Getter` +- Parameter: `Number` + +Sets and gets the player's playback speed. + +
▶ Run Code
+ +```js{8} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2413,9 +2960,18 @@ art.on('ready', () => { art.playbackRate = 2; console.info(art.playbackRate); }); +``` -The aspectRatio property is a setter and getter for the player's aspect ratio. It accepts a string parameter. +## `aspectRatio` +- Type: `Setter/Getter` +- Parameter: `String` + +Sets and gets the player's aspect ratio. + +
▶ Run Code
+ +```js{8} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2426,9 +2982,17 @@ art.on('ready', () => { art.aspectRatio = '16:9'; console.info(art.aspectRatio); }); +``` -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. +## `autoHeight` +- Type: `Function` + +When the container only has a defined width, this property can automatically calculate and set the video's height. + +
▶ Run Code
+ +```js{7,11} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2441,9 +3005,24 @@ art.on('ready', () => { art.on('resize', () => { art.autoHeight(); }); +``` -The attr function dynamically gets and sets attributes of the video element. It accepts a string parameter for the attribute name. +:::warning Note +This property is useful when your container has only a width but the exact height is unknown. It can automatically calculate the video height, but you need to determine the timing for setting this property. + +::: + +## `attr` + +- Type: `Function` +- Parameter: `String` + +Dynamically get and set attributes of the video element. + +
▶ Run Code
+ +```js{8} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2454,9 +3033,18 @@ art.on('ready', () => { art.attr('playsInline', true); console.info(art.attr('playsInline')); }); +``` -The type property is a setter and getter for the video type. It accepts a string parameter. +## `type` +- Type: `Setter/Getter` +- Parameter: `String` + +Dynamically get and set the video type. + +
▶ Run Code
+ +```js{8} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2467,9 +3055,18 @@ art.on('ready', () => { art.type = 'm3u8'; console.info(art.type); }); +``` -The theme property is a setter and getter for the player's theme color. It accepts a string parameter. +## `theme` +- Type: `Setter/Getter` +- Parameter: `String` + +Dynamically get and set the player's theme color. + +
▶ Run Code
+ +```js{8} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2480,9 +3077,17 @@ art.on('ready', () => { art.theme = '#000'; console.info(art.theme); }); +``` -The airplay function initiates AirPlay. +## `airplay` +- Type: `Function` + +Initiate AirPlay. + +
▶ Run Code
+ +```js{9} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2496,9 +3101,17 @@ var art = new Artplayer({ }, ], }); +``` -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. +## `loaded` +- Type: `Getter` + +The proportion of video buffered, ranging from `[0, 1]`. Often used with the `video:timeupdate` event. + +
▶ Run Code
+ +```js{7} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2507,9 +3120,17 @@ var art = new Artplayer({ art.on('video:timeupdate', () => { console.info(art.loaded); }); +``` -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. +## `loadedTime` +- Type: `Getter` + +The buffered media duration in seconds. Typically used alongside `loaded` to display detailed buffering progress. + +
▶ Run Code
+ +```js{7} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2518,9 +3139,17 @@ var art = new Artplayer({ art.on('video:timeupdate', () => { console.info(art.loadedTime); }); +``` -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. +## `played` +- Type: `Getter` + +The proportion of video played, ranging from `[0, 1]`. Often used with the `video:timeupdate` event. + +
▶ Run Code
+ +```js{7} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2529,9 +3158,17 @@ var art = new Artplayer({ art.on('video:timeupdate', () => { console.info(art.played); }); +``` -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. +## `proxy` +- Type: `Function` + +A proxy function for `DOM` events, essentially proxying `addEventListener` and `removeEventListener`. When using `proxy` to handle events, the event is automatically cleaned up when the player is destroyed. + +
▶ Run Code
+ +```js{8-10} var container = document.querySelector('.artplayer-app'); var art = new Artplayer({ @@ -2542,27 +3179,57 @@ var art = new Artplayer({ art.proxy(container, 'click', event => { console.info(event); }); +``` -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. +:::warning Note +If you need certain `DOM` events to exist only for the player's lifecycle, it is strongly recommended to use this function to avoid memory leaks. + +::: + +## `query` + +- Type: `Function` + +A `DOM` query function, similar to `document.querySelector`, but the search is scoped to the current player, preventing errors with duplicate class names. + +
▶ Run Code
+ +```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', }); console.info(art.query('.art-video')); +``` -The video property quickly returns the player's video element. +## `video` +- Type: `Element` + +Quickly returns the player's `video` element. + +
▶ Run Code
+ +```js{6} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', }); console.info(art.video); +``` -The cssVar function dynamically gets or sets CSS variables. +## `cssVar` +- Type: `Function` + +Dynamically get or set `CSS` variables. + +
▶ Run Code
+ +```js{8} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2573,9 +3240,18 @@ art.on('ready', () => { art.cssVar('--art-theme', 'green'); console.log(art.cssVar('--art-theme')); }); +``` -The quality property is a setter that dynamically sets the list of available quality levels. It accepts an array parameter. +## `quality` +- Type: `Setter` +- Parameter: `Array` + +Dynamically set the quality list. + +
▶ Run Code
+ +```js{19-29} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2608,19 +3284,21 @@ art.on('ready', () => { }, 3000); }) -The thumbnails property is a setter and getter for dynamically setting thumbnails. It accepts an object parameter. +``` -Example code for thumbnails would be placed here. +## `thumbnails` -ArtPlayer Documentation +- Type: `Setter/Getter` +- Parameter: `Object` -Thumbnails Example +Dynamically set thumbnails. -This example shows how to set thumbnails for a video after the player is ready. +
▶ Run Code
+```js var art = new Artplayer({ - container: '.artplayer-app', - url: '/assets/sample/video.mp4', + container: '.artplayer-app', + url: '/assets/sample/video.mp4', }); art.on('ready', () => { @@ -2630,19 +3308,21 @@ art.on('ready', () => { column: 10, }; }); +``` -subtitleOffset +## `subtitleOffset` -Type: Setter/Getter -Parameter: Number +- Type: `Setter/Getter` +- Parameter: `Number` -This property allows you to dynamically set the subtitle offset in seconds. +Dynamically set subtitle offset. -Example of setting a subtitle offset: +
▶ Run Code
+```js var art = new Artplayer({ - container: '.artplayer-app', - url: '/assets/sample/video.mp4', + container: '.artplayer-app', + url: '/assets/sample/video.mp4', subtitle: { url: '/assets/sample/subtitle.srt', }, @@ -2651,27 +3331,30 @@ var art = new Artplayer({ art.on('ready', () => { art.subtitleOffset = 1; }); +``` -Context Menu +===== packages/artplayer-vitepress/docs/en/component/contextmenu.md ===== -Configuration +# Context Menu -The contextmenu component can be configured with the following properties: +## 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 +| 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` | DOM element of the component | +| `style` | `Object` | Component style object | +| `click` | `Function` | Component click event | +| `mounted` | `Function` | Triggered after component mount | +| `tooltip` | `String` | Tooltip text for the component | -Creation +## Creation -You can create context menu items during player initialization. +
▶ Run Code
+```js{4-13} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2691,11 +3374,13 @@ art.contextmenu.show = true; // Get the Element of contextmenu by name console.info(art.contextmenu['your-menu']); +``` -Addition +## Addition -You can add a context menu item after the player has been created. +
▶ Run Code
+```js{6-13} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2714,11 +3399,13 @@ art.contextmenu.show = true; // Get the Element of contextmenu by name console.info(art.contextmenu['your-menu']); +``` -Removal +## Deletion -You can remove a context menu item by its name. +
▶ Run Code
+```js{21} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2742,11 +3429,13 @@ art.on('ready', () => { art.contextmenu.remove('your-menu') }, 3000); }); +``` -Update +## Update -You can update the properties of an existing context menu item. +
▶ Run Code
+```js{21-24} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2773,30 +3462,33 @@ art.on('ready', () => { }) }, 3000); }); +``` -Controls +===== packages/artplayer-vitepress/docs/en/component/controls.md ===== -Configuration +# Controls -Controls can be configured with the following properties: +## Configuration -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 +| Property | Type | Description | +| ---------- | ------------------- | ------------------------------------------------ | +| `disable` | `Boolean` | Whether to disable the control | +| `name` | `String` | Unique name of the control, used for class marking | +| `index` | `Number` | Control index, determines display priority | +| `html` | `String`, `Element` | DOM element of the control | +| `style` | `Object` | Style object for the control | +| `click` | `Function` | Click event handler for the control | +| `mounted` | `Function` | Triggered after the control is mounted | +| `tooltip` | `String` | Tooltip text for the control | +| `position` | `String` | `left` or `right` - controls which side the control appears on | +| `selector` | `Array` | Array of objects for selection list | +| `onSelect` | `Function` | Function triggered when a selection list item is clicked | -Creation +## Creation -You can define controls during the player's initialization. +
▶ Run Code
+```js var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2841,11 +3533,13 @@ var art = new Artplayer({ // Get the Element of control by name console.info(art.controls['your-button']); console.info(art.controls['subtitle']); +``` -Adding +## Adding -You can add a new control to the player after it has been created. +
▶ Run Code
+```js{6-21} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2870,11 +3564,13 @@ art.controls.add({ // Get the Element of control by name console.info(art.controls['button1']); +``` -Removal +## Removal -You can remove a control by its name. +
▶ Run Code
+```js{21} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2898,11 +3594,13 @@ art.on('ready', () => { art.controls.remove('button1'); }, 3000); }); +``` -Updating +## Updating -You can update the properties of an existing control. +
▶ Run Code
+```js{26-40} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -2925,10 +3623,6 @@ var art = new Artplayer({ ] }); -ArtPlayer Documentation: Controls Update Example - -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(() => { // Update the control by name @@ -2949,27 +3643,30 @@ art.on('ready', () => { }); }, 3000); }); +``` -ArtPlayer Documentation: Layer Component +===== packages/artplayer-vitepress/docs/en/component/layers.md ===== -Layer Configuration +# Layers -The following properties can be used when creating or updating a layer component. +## 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 +| 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 +## Creation -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. +
▶ Run Code
+```js{5-22} var img = '/assets/sample/layer.png'; var art = new Artplayer({ container: '.artplayer-app', @@ -2996,11 +3693,13 @@ var art = new Artplayer({ // Get the Element of layer by name console.info(art.layers['potser']); +``` -Layer Addition +## Addition -This example shows how to add a layer after the Artplayer instance has been created, using the layers.add method. +
▶ Run Code
+```js{7-22} var img = '/assets/sample/layer.png'; var art = new Artplayer({ container: '.artplayer-app', @@ -3026,11 +3725,13 @@ art.layers.add({ // Get the Element of layer by name console.info(art.layers['potser']); +``` -Layer Removal +## Removal -This example shows how to remove a layer by its name after a delay, using the layers.remove method. +
▶ Run Code
+```js{21} var img = '/assets/sample/layer.png'; var art = new Artplayer({ container: '.artplayer-app', @@ -3054,11 +3755,13 @@ art.on('ready', () => { art.layers.remove('potser'); }, 3000); }); +``` -Layer Update +## Update -This example shows how to update an existing layer's properties, such as its HTML content and style, using the layers.update method. +
▶ Run Code
+```js{21-29} var img = '/assets/sample/layer.png'; var art = new Artplayer({ container: '.artplayer-app', @@ -3090,13 +3793,19 @@ art.on('ready', () => { }); }, 3000); }); +``` -ArtPlayer Documentation: Settings Panel +===== packages/artplayer-vitepress/docs/en/component/setting.md ===== -Built-in Settings +# Settings Panel -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. +## Built-in +First, you need to open the settings panel. It comes with four built-in items: `flip`, `playbackRate`, `aspectRatio`, `subtitleOffset`. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -3106,20 +3815,21 @@ var art = new Artplayer({ aspectRatio: true, subtitleOffset: true, }); +``` -Creating Button Settings +## Create - Button -A button in the settings panel can be configured with the following properties. +| Property | Type | Description | +| ---------- | ------------------- | -------------------- | +| `html` | `String`, `Element` | The DOM element | +| `icon` | `String`, `Element` | The icon element | +| `onClick` | `Function` | The click event | +| `width` | `Number` | The list width | +| `tooltip` | `String` | The 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 - -This example creates a simple button setting with a custom icon and a click handler. +
▶ Run Code
+```js var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -3131,26 +3841,27 @@ var art = new Artplayer({ tooltip: 'tooltip', onClick(item, $dom, event) { console.info(item, $dom, event); - return 'new tooltip' - } + return 'new tooltip'; + }, }, ], }); +``` -Creating Selection List Settings +## Create - Selection List -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` | The DOM element | +| `icon` | `String`, `Element` | The icon element | +| `selector` | `Array` | The list of elements | +| `onSelect` | `Function` | The click event | +| `width` | `Number` | The list width | +| `tooltip` | `String` | The 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 - -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. +
▶ Run Code
+```js var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -3204,146 +3915,13 @@ var art = new Artplayer({ }, ], }); +``` -Creating Nested Lists +## Create - Nested List -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 for AI Learning - -This documentation covers the installation, usage, and configuration of ArtPlayer, with a focus on creating and managing settings. - -Installation and Usage - -You can install ArtPlayer via several package managers or include it directly via script tag. - -Using npm: -npm install artplayer - -Using yarn: -yarn add artplayer - -Using pnpm: -pnpm add artplayer - -Using a script tag in HTML: - - -CDN Links - -You can also load ArtPlayer from a CDN. - -From jsdelivr.net: -https://cdn.jsdelivr.net/npm/artplayer/dist/artplayer.js - -From unpkg.com: -https://unpkg.com/artplayer/dist/artplayer.js - -Basic Usage Example - -Here is a basic HTML example to get started with ArtPlayer. - - - - ArtPlayer Demo - - - - -
- - - - - -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 detailed usage examples, you can visit the project's example directory. - -Vue.js Integration Example - -ArtPlayer can be integrated into a Vue.js application. Here is a component example. - -First, create a reusable Artplayer.vue component: - - - - - -Then, use the component in your app.vue file: - - - - - -Important Note: The Artplayer instance itself is not reactive. Manage its state through its own API methods. - -Creating Settings - -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. +
▶ Run Code
+```js var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -3389,32 +3967,21 @@ var art = new Artplayer({ ], }); -Creating a Toggle Button Setting +``` -A toggle button setting has a switch that can be on or off. Here are its properties. +## Create - Toggle Button -Property: html -Type: String, Element -Description: DOM element or text for the item. +| Property | Type | Description | +| ---------- | ------------------- | -------------------------- | +| `html` | `String`, `Element` | DOM element for the item | +| `icon` | `String`, `Element` | Icon for the item | +| `switch` | `Boolean` | Default state of the button | +| `onSwitch` | `Function` | Button toggle event | +| `tooltip` | `String` | Tooltip text | -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. +
▶ Run Code
+```js var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -3435,44 +4002,30 @@ var art = new Artplayer({ }, ], }); +``` -Creating a Range Slider Setting +## Create - Range Slider -A range slider setting allows users to select a numeric value. Here are its properties. +| Property | Type | Description | +| ---------- | ------------------- | -------------------------- | +| `html` | `String`, `Element` | DOM element for the item | +| `icon` | `String`, `Element` | Icon for the item | +| `range` | `Array` | Default state array | +| `onRange` | `Function` | Event triggered on completion | +| `onChange` | `Function` | Event triggered on change | +| `tooltip` | `String` | Tooltip text | -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: +```js const range = [5, 1, 10, 1]; -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) +const value = range[0]; +const min = range[1]; +const max = range[2]; +const step = range[3]; +``` -Here is an example of creating a playback speed slider. +
▶ Run Code
+```js var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -3490,11 +4043,13 @@ var art = new Artplayer({ }, ], }); +``` -Adding a Setting After Initialization +## Add -You can add a new setting to the player after it has been created using the `add` method. +
▶ Run Code
+```js{9-14} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -3509,11 +4064,13 @@ art.setting.add({ icon: '', range: [5, 1, 10, 1], }); +``` -Removing a Setting +## Remove -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. +
▶ Run Code
+```js{22} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -3538,11 +4095,13 @@ art.on('ready', () => { art.setting.remove('slider'); }, 3000); }); +``` -Updating a Setting +## Update -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. +
▶ Run Code
+```js{21-27} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -3572,15 +4131,172 @@ art.on('ready', () => { }); }, 3000); }); +``` -ArtPlayer Documentation +===== packages/artplayer-vitepress/docs/en/index.md ===== -React.js +# Installation and Usage -Here is an example of using ArtPlayer in a React.js component. +## Installation -Artplayer.jsx: +::: code-group +```bash [npm] +npm install artplayer +``` + +```bash [yarn] +yarn add artplayer +``` + +```bash [pnpm] +pnpm add artplayer +``` + +```bash [bun] +bun add artplayer +``` + +```html [script] + +``` + +::: + +## `CDN` + +::: code-group + +```bash [jsdelivr.net] +https://cdn.jsdelivr.net/npm/artplayer/dist/artplayer.js +``` + +```bash [unpkg.com] +https://unpkg.com/artplayer/dist/artplayer.js +``` + +::: + +## Usage + +::: code-group + +```html [index.html] + + + ArtPlayer Demo + + + + +
+ + + + +``` + +::: + +::: warning Note + +The player's dimensions depend on the dimensions of its `container`. Therefore, your `container` must have defined dimensions. + +::: + +::: tip See more usage examples at the following link + +[/example](https://github.com/zhw2590582/ArtPlayer/tree/master/example) + +::: + +## `Vue.js` + +::: code-group + +```vue [Artplayer.vue] + + + +``` + +```vue [app.vue] + + + +``` + +::: + +::: warning Artplayer is not reactive: + +Directly modifying the `option` in `Vue.js` will not update the player. + +::: + +## `React.js` + +::: code-group + +```jsx [Artplayer.jsx] import Artplayer from 'artplayer' import { useEffect, useRef } from 'react' @@ -3602,9 +4318,9 @@ export default function Player({ option, getInstance, ...rest }) { return
} +``` -app.jsx: - +```jsx [app.jsx] import Artplayer from './Artplayer.jsx' function App() { @@ -3626,31 +4342,43 @@ function App() { } export default App +``` -Important note: Artplayer is not reactive. Directly modifying the `option` prop in React.js will not update the player. +::: -TypeScript +::: warning Artplayer is not reactive: -TypeScript definitions are automatically imported when you import Artplayer. Here are examples for different frameworks. +Directly modifying the `option` in `React.js` will not update the player. -Vue.js: +::: +## TypeScript + +The `artplayer.d.ts` file is automatically imported when you import `Artplayer`. + +### Vue.js + +```vue{3} +``` -React.js: +### React.js +```jsx{2} import Artplayer from 'artplayer'; const art = useRef(null); art.current = new Artplayer(); +``` -You can also import and use the Option type for better type safety. +### Option -Option: +You can also use the type for the options. +```ts{3} import Artplayer, { type Option } from 'artplayer'; const option: Option = { @@ -3661,31 +4389,41 @@ const option: Option = { option.volume = 0.5; const art = new Artplayer(option); +``` -For the full TypeScript definitions, refer to the repository: packages/artplayer/types +::: tip Full TypeScript Definitions -JavaScript +[packages/artplayer/types](https://github.com/zhw2590582/ArtPlayer/tree/master/packages/artplayer/types) -If your JavaScript files lose TypeScript type hints, you can manually import the types using JSDoc comments. +::: -For a variable: +## JavaScript +Sometimes your `js` files may lose `TypeScript` type hints. In such cases, you can manually import the types. + +Variable: + +```js{1-3} /** * @type {import("artplayer")} */ let art = null; +``` -For a function parameter: +Parameter: +```js{1-3} /** * @param {import("artplayer")} art */ function getInstance(art) { // } +``` -For a Vue.js component property: +Property: +```js{4-6} export default { data() { return { @@ -3696,9 +4434,11 @@ export default { } } } +``` -For the Option type: +Option: +```js{1-3} /** * @type {import("artplayer/types/option").Option} */ @@ -3711,31 +4451,52 @@ const option = { option.volume = 0.5; const art8 = new Artplayer(option); +``` -Legacy Browsers +## Legacy Browsers -The standard production build, artplayer.js, supports the latest version of Chrome. For compatibility with older browsers, use the legacy build. +The production build `artplayer.js` only supports the latest major version of `Chrome`: `last 1 Chrome version`. -Import the legacy version: +For legacy browsers, you can use the `artplayer.legacy.js` file, which is compatible down to: `IE 11`. +```js import Artplayer from 'artplayer/legacy' +``` -You can also use it via a CDN: +::: code-group -From jsdelivr.net: +```bash [jsdelivr.net] https://cdn.jsdelivr.net/npm/artplayer/dist/artplayer.legacy.js +``` -From unpkg.com: +```bash [unpkg.com] https://unpkg.com/artplayer/dist/artplayer.legacy.js +``` -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 +::: tip If you need to support even older browsers, modify the following configuration and build it yourself: -Starting from version 5.2.6, ArtPlayer and its plugins provide ESM versions with the .mjs extension. +Build configuration: [scripts/build.js](https://github.com/zhw2590582/ArtPlayer/blob/master/scripts/build.js#L29) -Example using an import map in HTML: +Reference documentation: [browserslist](https://github.com/browserslist/browserslist#full-list) +::: + +## ECMAScript Module + +::: tip ESM Demo: + +[https://artplayer.org/esm.html](https://artplayer.org/esm.html) + +::: + +Starting from version `5.2.6`, `artplayer` and all plugins also provide an `ESM` version in `mjs` format, such as: + +- `artplayer/dist/artplayer.mjs` +- `artplayer-plugin-danmuku/dist/artplayer-plugin-danmuku.mjs` + +```html @@ -3772,13 +4533,13 @@ Example using an import map in HTML: +``` -Custom userAgent +## Custom userAgent -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. +Currently, the detection of whether a device is mobile is not always accurate. Sometimes you may want to adjust the player's UI by changing the `userAgent`. Therefore, starting from version `5.2.4`, a global variable `globalThis.CUSTOM_USER_AGENT` has been added. +```html ArtPlayer Demo @@ -3802,29 +4563,51 @@ Set the global variable `globalThis.CUSTOM_USER_AGENT` before importing the Artp +``` -Important: You must set the custom userAgent before loading the Artplayer library for it to take effect. +::: warning Note -Language Settings +You need to modify it before importing the `Artplayer` dependency for it to take effect. -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 +===== packages/artplayer-vitepress/docs/en/start/i18n.md ===== -The default languages, 'en' and 'zh-cn', are built-in. +# Language Settings +::: danger + +Due to the increasing number of bundled multilingual resources, starting from version `5.1.0`, the core `artplayer.js` code will no longer bundle any languages other than `Simplified Chinese` and `English`. You will need to manually import any other languages you require. + +::: + +:::warning + +When a language cannot be matched, English will be displayed by default. For i18n syntax reference, see: [artplayer/types/i18n.d.ts](https://github.com/zhw2590582/ArtPlayer/blob/master/packages/artplayer/types/i18n.d.ts) + +::: + +## Default Languages + +The default languages are: `en`, `zh-cn`. No manual import is required. + +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', lang: 'zh-cn', // or 'en' }); +``` -Importing Languages +## Importing Languages -Language files are available in the dist/i18n/ directory. You can import them as modules or via script tags. +Language files before bundling are located at: `artplayer/src/i18n/*.js`. Contributions for new languages are welcome. -Module import example: +Bundled language files are located at: `artplayer/dist/i18n/*.js` +::: code-group + +```js [import] import id from 'artplayer/i18n/id'; import zhTw from 'artplayer/i18n/zh-tw'; @@ -3837,9 +4620,9 @@ var art = new Artplayer({ }, lang: 'zh-tw', }); +``` -Script tag example: - +```js [script] @@ -3852,11 +4635,13 @@ var art = new Artplayer({ }, lang: 'zh-tw', }); +``` -Adding a New Language +::: -You can define a custom language directly in the options. +## Adding a New Language +```js{4-9} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -3867,83 +4652,95 @@ var art = new Artplayer({ }, }, }); +``` -Modifying Languages - -You can override the strings of any language, including the default ones. +## Modifying a Language +```js import zhTw from 'artplayer/i18n/zh-tw'; var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', i18n: { - // Change the default 'zh-cn' language + // Change the default language 'zh-cn': { Play: 'Your Play' }, - // Change the imported 'zh-tw' language + // Change the imported language 'zh-tw': { ...zhTw, Play: 'Your Play' }, }, }); +``` -Basic Options +===== packages/artplayer-vitepress/docs/en/start/option.md ===== -container +# Basic Options -- Type: String, Element -- Default: #artplayer +## `container` -The DOM container where the player is mounted. +- Type: `String, Element` +- Default: `#artplayer` -To initialize an ArtPlayer instance, you must provide a container element. This can be a CSS selector string or a direct DOM element reference. +The `DOM` container where the player is mounted. -```js +
▶ Run Code
+ +```js{2} var art = new Artplayer({ - container: '.artplayer-app', + container: '.artplayer-app', // container: document.querySelector('.artplayer-app'), url: '/assets/sample/video.mp4', }); ``` -You may need to define the size of the container element. You can set explicit width and height. +You may need to set the size of the container element, for example: -```css +```css{2-3} .artplayer-app { width: 400px; height: 300px; } ``` -Alternatively, you can use the CSS aspect-ratio property. +Or use `aspect-ratio`: -```css +```css{2} .artplayer-app { aspect-ratio: 16/9; } ``` -Note: Among all configuration options, only the `container` is required. +:::warning Note -URL -Type: String -Default: '' +Among all options, only `container` is required. -This is the video source URL. +::: -```js +## `url` + +- Type: `String` +- Default: `''` + +The video source URL. + +
▶ Run Code
+ +```js{3} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', }); ``` -If the video URL is not known at initialization time, you can set it asynchronously later. +Sometimes the `url` is not known immediately. In such cases, you can set the `url` asynchronously. -```js +
▶ Run Code
+ +```js{6} var art = new Artplayer({ container: '.artplayer-app', }); @@ -3953,15 +4750,24 @@ setTimeout(() => { }, 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. +:::warning Note -ID -Type: String -Default: '' +By default, three video file formats are supported: `.mp4`, `.ogg`, `.webm`. -A unique identifier for the player, currently used for the playback resumption feature (`autoplayback`). +To play other formats like `.m3u8` or `.flv`, please refer to the `Third-party Libraries` section on the left. -```js +::: + +## `id` + +- Type: `String` +- Default: `''` + +The unique identifier for the player. Currently used only for playback memory `autoplayback`. + +
▶ Run Code
+ +```js{2} var art = new Artplayer({ id: 'your-url-id', container: '.artplayer-app', @@ -3969,13 +4775,16 @@ var art = new Artplayer({ }); ``` -ONREADY -Type: Function -Default: undefined +## `onReady` -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. +- Type: `Function` +- Default: `undefined` -```js +The constructor accepts a function as the second parameter. This function is triggered when the player is successfully initialized and the video is ready to play, similar to the `ready` event. + +
▶ Run Code
+ +```js{7-9} var art = new Artplayer( { container: '.artplayer-app', @@ -3988,9 +4797,9 @@ var art = new Artplayer( ); ``` -This is equivalent to using the event listener method: +Equivalent to: -```js +```js{7-9} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4002,15 +4811,22 @@ art.on('ready', () => { }); ``` -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. +:::warning Note -POSTER -Type: String -Default: '' +Inside the callback function, `this` refers to the player instance. However, if an arrow function is used for the callback, `this` will not point to the player instance. -The poster image URL, displayed when the player is initialized but before video playback begins. +::: -```js +## `poster` + +- Type: `String` +- Default: `''` + +The video poster image, which only appears when the player is initialized and not yet playing. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4018,13 +4834,16 @@ var art = new Artplayer({ }); ``` -THEME -Type: String -Default: '#f00' +## `theme` -The theme color for the player, used for elements like the progress bar and highlights. +- Type: `String` +- Default: `#f00` -```js +The player's theme color, currently used for the `progress bar` and `highlighted elements`. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4032,13 +4851,16 @@ var art = new Artplayer({ }); ``` -VOLUME -Type: Number -Default: 0.7 +## `volume` -The default volume level for the player. +- Type: `Number` +- Default: `0.7` -```js +The player's default volume. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4046,15 +4868,22 @@ var art = new Artplayer({ }); ``` -Note: The player caches the last volume setting. On the next initialization (e.g., page refresh), it will use this cached value. +:::warning Note -ISLIVE -Type: Boolean -Default: false +The player caches the last volume setting. Upon the next initialization (e.g., page refresh), the player will read this cached value. -Enables live streaming mode, which hides the progress bar and playback time. +::: -```js +## `isLive` + +- Type: `Boolean` +- Default: `false` + +Enable live streaming mode. This will hide the progress bar and playback time. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4062,13 +4891,16 @@ var art = new Artplayer({ }); ``` -MUTED -Type: Boolean -Default: false +## `muted` -Determines if the player starts in a muted state. +- Type: `Boolean` +- Default: `false` -```js +Whether to start muted by default. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4076,13 +4908,16 @@ var art = new Artplayer({ }); ``` -AUTOPLAY -Type: Boolean -Default: false +## `autoplay` -Determines if the video should start playing automatically. +- Type: `Boolean` +- Default: `false` -```js +Whether to autoplay. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4091,29 +4926,40 @@ var art = new Artplayer({ }); ``` -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. +:::warning Note -AUTOSIZE -Type: Boolean -Default: false +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](https://developers.google.com/web/updates/2017/09/autoplay-policy-changes). -Automatically adjusts the player size to fill the container and hide black bars, similar to the CSS property `object-fit: cover;`. +::: -```js +## `autoSize` + +- Type: `Boolean` +- Default: `false` + +By default, the player's dimensions fill the entire `container`, often resulting in black bars. This option automatically adjusts the player size to hide black bars, similar to `css`'s `object-fit: cover;`. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', autoSize: true, }); + ``` -AUTOMINI -Type: Boolean -Default: false +## `autoMini` -Automatically switches to mini-player mode when the player scrolls out of the browser viewport. +- Type: `Boolean` +- Default: `false` -```js +Automatically enters `Mini Player` mode when the player scrolls out of the browser viewport. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4121,13 +4967,16 @@ var art = new Artplayer({ }); ``` -LOOP -Type: Boolean -Default: false +## `loop` -Enables looping of the video. +- Type: `Boolean` +- Default: `false` -```js +Whether to loop playback. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4135,13 +4984,16 @@ var art = new Artplayer({ }); ``` -FLIP -Type: Boolean -Default: false +## `flip` -Enables the video flip functionality, which appears in the Settings Panel and Context Menu. +- Type: `Boolean` +- Default: `false` -```js +Whether to display the video flip function. Currently only appears in the `Settings Panel` and `Context Menu`. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4150,13 +5002,16 @@ var art = new Artplayer({ }); ``` -PLAYBACKRATE -Type: Boolean -Default: false +## `playbackRate` -Enables the video playback rate functionality, which appears in the Settings Panel and Context Menu. +- Type: `Boolean` +- Default: `false` -```js +Whether to display the video playback speed function. It will appear in the `Settings Panel` and `Context Menu`. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4165,13 +5020,16 @@ var art = new Artplayer({ }); ``` -ASPECTRATIO -Type: Boolean -Default: false +## `aspectRatio` -Enables the video aspect ratio functionality, which appears in the Settings Panel and Context Menu. +- Type: `Boolean` +- Default: `false` -```js +Whether to display the video aspect ratio function. It will appear in the `Settings Panel` and `Context Menu`. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4180,13 +5038,16 @@ var art = new Artplayer({ }); ``` -SCREENSHOT -Type: Boolean -Default: false +## `screenshot` -Adds a video screenshot button to the bottom control bar. +- Type: `Boolean` +- Default: `false` -```js +Whether to display the `Screenshot` function in the bottom control bar. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4194,15 +5055,22 @@ var art = new Artplayer({ }); ``` -Note: Due to browser security policies, screenshot capture may fail if the video is served from a different origin (cross-origin) than the website. +:::warning Note -SETTING -Type: Boolean -Default: false +Due to browser security mechanisms, screenshotting may fail if the video source URL is cross-origin with the website. -Adds a toggle button for the Settings Panel to the bottom control bar. +::: -```js +## `setting` + +- Type: `Boolean` +- Default: `false` + +Whether to display the toggle button for the `Settings Panel` in the bottom control bar. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4210,13 +5078,16 @@ var art = new Artplayer({ }); ``` -HOTKEY -Type: Boolean -Default: true +## `hotkey` -Enables keyboard hotkeys for player control. +- Type: `Boolean` +- Default: `true` -```js +Whether to use hotkeys. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4224,93 +5095,115 @@ var art = new Artplayer({ }); ``` -Hotkeys +| Hotkey | Description | +| ------- | -------------------- | +| `↑` | Increase volume | +| `↓` | Decrease volume | +| `←` | Seek forward | +| `→` | Seek backward | +| `space` | Toggle play/pause | -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. +:::warning Note -Hotkey: Up arrow -Description: Increase volume +These hotkeys only take effect after the player gains focus (e.g., after clicking on the player). -Hotkey: Down arrow -Description: Decrease volume +::: -Hotkey: Left arrow -Description: Seek forward +## `pip` -Hotkey: Right arrow -Description: Seek backward +- Type: `Boolean` +- Default: `false` -Hotkey: Space -Description: Toggle play/pause +Whether to display the `Picture-in-Picture` toggle button in the bottom control bar. -Configuration Options +
▶ Run Code
-pip -Type: Boolean -Default: false -This setting determines whether to display the Picture-in-Picture toggle button in the bottom control bar. - -Example: +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', pip: true, }); +``` -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. +## `mutex` -Example: +- Type: `Boolean` +- Default: `true` + +If multiple players exist on the page simultaneously, whether only one player is allowed to play at a time. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', mutex: true, }); +``` -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. +## `backdrop` -Example: +- Type: `Boolean` +- Default: `true` + +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 look. However, this may cause performance or compatibility issues on some low-performance devices or older browsers. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', backdrop: false, // Disable frosted glass effect }); +``` -fullscreen -Type: Boolean -Default: false -This setting determines whether to display the Window Fullscreen button in the bottom control bar. +## `fullscreen` -Example: +- Type: `Boolean` +- Default: `false` + +Whether to display the player `Window Fullscreen` button in the bottom control bar. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', fullscreen: true, }); +``` -fullscreenWeb -Type: Boolean -Default: false -This setting determines whether to display the Webpage Fullscreen button in the bottom control bar. +## `fullscreenWeb` -Example: +- Type: `Boolean` +- Default: `false` + +Whether to display the player `Web Fullscreen` button in the bottom control bar. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', fullscreenWeb: true, }); +``` -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. +## `subtitleOffset` -Example: +- Type: `Boolean` +- Default: `false` + +Subtitle time offset, ranging from `[-5s, 5s]`. Appears in the `Settings Panel`. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4321,24 +5214,37 @@ var art = new Artplayer({ setting: true, }); -miniProgressBar -Type: Boolean -Default: false -When enabled, a mini progress bar will appear when the player loses focus but is still playing. +``` -Example: +## `miniProgressBar` + +- Type: `Boolean` +- Default: `false` + +A mini progress bar that only appears when the player loses focus and is playing. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', miniProgressBar: true, }); +``` -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. +## `useSSR` -Example: +- Type: `Boolean` +- Default: `false` + +Whether to use SSR (Server-Side Rendering) mount mode. Useful if you want to pre-render the player's required HTML before the player is mounted. + +You can access the player's required HTML via `Artplayer.html`. + +
▶ Run Code
+ +```js{7} var $container = document.querySelector('.artplayer-app'); $container.innerHTML = Artplayer.html; @@ -4347,25 +5253,35 @@ var art = new Artplayer({ url: '/assets/sample/video.mp4', useSSR: true, }); +``` -playsInline -Type: Boolean -Default: true -This controls whether to use playsInline mode for video playback on mobile devices. +## `playsInline` -Example: +- Type: `Boolean` +- Default: `true` + +Whether to use `playsInline` mode on mobile devices. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', playsInline: true, }); +``` -layers -Type: Array -Default: [] -This array is used to initialize custom layers on the player. +## `layers` -Example: +- Type: `Array` +- Default: `[]` + +Initialize custom layers. + +
▶ Run Code
+ +```js{5-23} var img = '/assets/sample/layer.png'; var art = new Artplayer({ container: '.artplayer-app', @@ -4390,15 +5306,24 @@ var art = new Artplayer({ }, ], }); +``` -For detailed Component Configuration, please refer to: /component/layers.html +:::warning For `Component Configuration`, please refer to: -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. +[/component/layers.html](/component/layers.html) -Example: +::: + +## `settings` + +- Type: `Array` +- Default: `[]` + +Initialize custom settings panels. + +
▶ Run Code
+ +```js{5-34} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4434,15 +5359,24 @@ var art = new Artplayer({ }, ], }); +``` -For detailed Settings Panel configuration, please refer to: /component/setting.html +:::warning For `Settings Panel`, please refer to: -contextmenu -Type: Array -Default: [] -This array is used to initialize custom items in the player's right-click context menu. +[/component/setting.html](/component/setting.html) -Example: +::: + +## `contextmenu` + +- Type: `Array` +- Default: `[]` + +Initialize custom context menus. + +
▶ Run Code
+ +```js{4-12} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4456,15 +5390,24 @@ var art = new Artplayer({ }, ], }); +``` -For detailed Component Configuration, please refer to: /component/contextmenu.html +:::warning For `Component Configuration`, please refer to: -controls -Type: Array -Default: [] -This array is used to initialize custom controls in the bottom control bar. +[/component/contextmenu.html](/component/contextmenu.html) -Example: +::: + +## `controls` + +- Type: `Array` +- Default: `[]` + +Initialize custom bottom control bar. + +
▶ Run Code
+ +```js{4-16} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4483,17 +5426,30 @@ var art = new Artplayer({ ], }); -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. +:::warning For `Component Configuration`, please refer to the following address: -Example: +[/component/controls.html](/component/controls.html) + +::: + +## `quality` + +- Type: `Array` +- Default: `[]` + +Whether to display the `Quality Selection` list in the bottom control bar. + +| Property | Type | Description | +| --------- | --------- | ---------------- | +| `default` | `Boolean` | Default quality | +| `html` | `String` | Quality name | +| `url` | `String` | Quality URL | + +
▶ Run Code
+ +```js{4-14} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4509,26 +5465,23 @@ var art = new Artplayer({ }, ], }); +``` -highlight -Type: Array -Default: [] -This array is used to define highlight markers that will be displayed on the player's progress bar. +## `highlight` -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. +- Type: `Array` +- Default: `[]` -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. +Display `Highlight Information` on the progress bar. -Property: time -Type: Number -Description: Highlight time (in seconds) +| Property | Type | Description | +| -------- | -------- | ------------------------------- | +| `time` | `Number` | Highlight time (in seconds) | +| `text` | `String` | Highlight text | -Property: text -Type: String -Description: Highlight text - -Example configuration with multiple highlights: +
▶ Run Code
+```js{4-25} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4555,17 +5508,18 @@ var art = new Artplayer({ }, ], }); +``` +## `plugins` -Plugins +- Type: `Array` +- Default: `[]` -Type: Array -Default: [] +Initialize custom `plugins`. -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 defining and using a custom plugin: +
▶ Run Code
+```js{15} function myPlugin(art) { console.info(art); return { @@ -4582,41 +5536,27 @@ var art = new Artplayer({ url: '/assets/sample/video.mp4', plugins: [myPlugin], }); +``` +## `thumbnails` -Thumbnails +- Type: `Object` +- Default: `{}` -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 | Type | Description | +| -------- | -------- | -------------------------- | +| `url` | `String` | Thumbnail image URL | +| `number` | `Number` | Number of thumbnails | +| `column` | `Number` | Number of thumbnail columns| +| `width` | `Number` | Thumbnail width | +| `height` | `Number` | Thumbnail height | +| `scale` | `Number` | Thumbnail scale | -Property: url -Type: String -Description: Thumbnail image URL - -Property: number -Type: Number -Description: Number of thumbnails - -Property: column -Type: Number -Description: Number of thumbnail columns - -Property: width -Type: Number -Description: Thumbnail width - -Property: height -Type: Number -Description: Thumbnail height - -Property: scale -Type: Number -Description: Thumbnail scale - -Basic configuration example: +
▶ Run Code
+```js{4-8} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4626,47 +5566,34 @@ var art = new Artplayer({ column: 10, }, }); +``` -Note: You can generate thumbnails online using artplayer-tool-thumbnail. +:::warning Generate Thumbnails Online +[artplayer-tool-thumbnail](https://artplayer.org/?libs=./uncompiled/artplayer-tool-thumbnail/index.js&example=thumbnail) -Subtitle +::: -Type: Object -Default: {} +## `subtitle` -Set the video subtitle. Supported subtitle formats are vtt, srt, and ass. +- Type: `Object` +- Default: `{}` -Property: name -Type: String -Description: Subtitle name +Set video subtitles. Supported subtitle formats: `vtt`, `srt`, `ass`. -Property: url -Type: String -Description: Subtitle URL +| Property | Type | Description | +| ----------- | ---------- | ------------------------------------------------ | +| `name` | `String` | Subtitle name | +| `url` | `String` | Subtitle URL | +| `type` | `String` | Subtitle type, options: `vtt`, `srt`, `ass` | +| `style` | `Object` | Subtitle style | +| `encoding` | `String` | Subtitle encoding, default `utf-8` | +| `escape` | `Boolean` | Whether to escape `html` tags, default `true` | +| `onVttLoad` | `Function` | Function for modifying `vtt` text | -Property: type -Type: String -Description: Subtitle type, options: vtt, srt, ass - -Property: style -Type: Object -Description: Subtitle style - -Property: encoding -Type: String -Description: Subtitle encoding, default: utf-8 - -Property: escape -Type: Boolean -Description: Whether to escape html tags, default: true - -Property: onVttLoad -Type: Function -Description: Function for modifying vtt text - -Example with an SRT subtitle and custom styling: +
▶ Run Code
+```js{4-12} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4681,17 +5608,18 @@ var art = new Artplayer({ }, }, }); +``` +## `moreVideoAttr` -More Video Attributes +- Type: `Object` +- Default: `{'controls': false, 'preload': 'metadata'}` (In Safari, it will automatically adjust to `preload: 'auto'` for better loading experience.) -Type: Object -Default: {'controls': false, 'preload': 'metadata'} (In Safari, it automatically adjusts to preload: 'auto' for better loading experience). +More video attributes. These attributes will be written directly into the video element. -More video attributes. These attributes will be directly written into the video element. - -Example adding inline playback attributes for mobile: +
▶ Run Code
+```js{4-7} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4701,16 +5629,18 @@ var art = new Artplayer({ }, }); +``` -Icons +## `icons` -Type: Object -Default: {} +- Type: `Object` +- Default: `{}` -Used to replace default icons, supports both Html strings and HTMLElement. +Used to replace default icons. Supports `Html` strings and `HTMLElement`. -Example replacing the loading and state icons: +
▶ Run Code
+```js{4-7} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4719,75 +5649,101 @@ var art = new Artplayer({ state: '', }, }); +``` -Note: For all icon definitions, refer to artplayer/types/icons.d.ts. +:::warning All Icon Definitions +[artplayer/types/icons.d.ts](https://github.com/zhw2590582/ArtPlayer/blob/master/packages/artplayer/types/icons.d.ts) -Type +::: -Type: String -Default: '' +## `type` -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. +- Type: `String` +- Default: `''` -Example specifying an HLS stream: +Used to specify the video format. It needs to be used together 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 may not have the correct suffix, so it needs to be explicitly specified. +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.m3u8', type: 'm3u8', }); +``` -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. +:::warning Suffix Recognition +The player can only parse suffixes like this: `/assets/sample/video.m3u8` -Custom Type +But cannot parse suffixes like this: `/assets/sample/video?type=m3u8` -Type: Object -Default: {} +Therefore, if you use `customType`, it's best to also specify the `type`. -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 setting up a custom handler for HLS streams: +## `customType` +- Type: `Object` +- Default: `{}` + +Matches based on the video's `type` and delegates video decoding to third-party programs for processing. The processing function can receive three parameters: + +- `video`: The video `DOM` element +- `url`: The video URL +- `art`: The current instance + +
▶ Run Code
+ +```js{4-8} 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()` -Type: String -Default: navigator.language.toLowerCase() +The default display language. Currently supported: `en`, `zh-cn`. -The default display language. Currently supported: en, zh-cn. - -Example setting the player to English: +
▶ Run Code
+```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', lang: 'en', }); +``` -Note: For more language settings, see /start/i18n.html. +:::warning More Language Settings +[/start/i18n.html](/start/i18n.html) -Internationalization (i18n) +::: -Type: Object -Default: {} +## `i18n` -Custom i18n configuration. This configuration will be deeply merged with the built-in i18n. +- Type: `Object` +- Default: `{}` -Example adding a new language: +Custom `i18n` configuration. This configuration will be deeply merged with the built-in `i18n`. +Add your language: + +
▶ Run Code
+ +```js{4-9} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4798,9 +5754,13 @@ var art = new Artplayer({ }, }, }); +``` -Example modifying an existing language: +Modify an existing language: +
▶ Run Code
+ +```js{4-11} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', @@ -4813,534 +5773,635 @@ var art = new Artplayer({ }, }, }); +``` -Note: For more language settings, see /start/i18n.html. +:::warning More Language Settings +[/start/i18n.html](/start/i18n.html) -Lock +::: -Type: Boolean -Default: false +## `lock` -Whether to display a lock button on mobile devices to hide the bottom control bar. +- Type: `Boolean` +- Default: `false` -Example enabling the lock feature: +Whether to display a `lock button` on mobile devices to hide the bottom `control bar`. +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', lock: true, }); +``` +## `gesture` -Gesture - -Type: Boolean -Default: true +- Type: `Boolean` +- Default: `true` Whether to enable gesture events on the video element on mobile devices. -Example disabling gestures: +
▶ Run Code
+```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', gesture: false, }); +``` +## `fastForward` -Fast Forward - -Type: Boolean -Default: false +- Type: `Boolean` +- Default: `false` Whether to add a long-press video fast-forward feature on mobile devices. -Example enabling fast-forward: +
▶ Run Code
+```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', fastForward: true, }); +``` -Here is the documentation reorganized into a clean, plain text format. +## `autoPlayback` -Initialization Example -This is a basic example of creating an ArtPlayer instance. +- Type: `Boolean` +- Default: `false` -var art = new Artplayer({ - container: '.artplayer-app', - url: '/assets/sample/video.mp4', - fastForward: true, -}); +Whether to use the automatic `playback feature`. -autoPlayback -Type: Boolean -Default: false -Determines whether to use the automatic playback feature, which resumes video playback from the last watched position. +
▶ Run Code
+```js{4-5} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', id: 'your-url-id', autoPlayback: true, }); +``` -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. +:::warning Note -autoOrientation -Type: Boolean -Default: false -When enabled on mobile web, this will automatically rotate the player during fullscreen mode based on the video's dimensions and the screen size. +Because the player uses the `url` as the `key` to cache playback progress by default. +However, if the `url` for the same video is different, then you need to use `id` to identify the unique `key` for the video. + +::: + +## `autoOrientation` + +- Type: `Boolean` +- Default: `false` + +Whether to rotate the player in fullscreen mode on mobile web, based on the video dimensions and viewport dimensions. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', autoOrientation: true, }); +``` -airplay -Type: Boolean -Default: false -Controls the visibility of the AirPlay button. Note that this feature is only supported in certain browsers. +## `airplay` +- Type: `Boolean` +- Default: `false` + +Whether to display the `airplay` button. Currently, only some browsers support this feature. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', airplay: true, }); +``` -cssVar -Type: Object -Default: {} -This object allows you to override the player's built-in CSS variables for custom styling. +## `cssVar` +- Type: `Object` +- Default: `{}` + +Used to modify the built-in CSS variables. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', cssVar: { - // Define custom CSS variables here + // }, }); +``` -For a full list of available CSS variables, please refer to the official type definition file: artplayer/types/cssVar.d.ts +:::warning Reference for `cssVar` Syntax -proxy -Type: function -Default: undefined -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. +[artplayer/types/cssVar.d.ts](https://github.com/zhw2590582/ArtPlayer/blob/master/packages/artplayer/types/cssVar.d.ts) +::: + +## `proxy` + +- Type: `function` +- Default: `undefined` + +The function can return a third-party `HTMLCanvasElement` or `HTMLVideoElement`. For example, it can proxy an existing `video` DOM element. + +
▶ Run Code
+ +```js{4} var art = new Artplayer({ container: '.artplayer-app', url: '/assets/sample/video.mp4', proxy: () => document.createElement('video') }); - - +``` ===== Type Definitions Overview ===== -artplayer-plugin-ads.d.ts +===== docs/assets/ts/artplayer-plugin-ads.d.ts ===== -This plugin adds advertising capabilities to ArtPlayer, supporting video, image, and HTML ad formats. - -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 +// Generated from the package public declaration by yarn build:ts. Do not edit. +/* eslint-disable ts/no-redeclare -- Callable and public type namespace intentionally merge. */ +declare namespace artplayerPluginAds { + interface Translations { + close: string + countdown: string + detail: string + canBeClosed: string + } + /** Implemented options. Video takes precedence over HTML. */ + interface Option { + html?: string + video?: string + url?: string + /** Seconds before the close button becomes available. @default 5 */ + playDuration?: number + /** Total advertisement duration in seconds. @default 10 */ + totalDuration?: number + /** Initial ad-video mute state. @default false */ + muted?: boolean + /** All four fields replace the default translation object together. */ + i18n?: Translations + } + /** Historical published declaration. String durations still fail runtime validation. */ + interface LegacyOption extends Omit { + /** @deprecated Incorrect in the old declaration; use a numeric duration. */ + totalDuration?: string + } + /** Historical unpublished workspace declaration; these fields are not runtime aliases. */ + interface WorkspaceOption extends Option { + /** @deprecated Ignored by the runtime. Use html or video instead. */ + source: string + /** @deprecated Ignored by the runtime. Images are supplied through html. */ + type: 'video' | 'image' | 'html' + } + /** Input acceptance for both historical declaration families. */ + interface CompatOption extends Omit { + /** @deprecated The string branch exists for old types only and is rejected at runtime. */ + totalDuration?: number | string + /** @deprecated Ignored by the runtime. Use html or video instead. */ + source?: string + /** @deprecated Ignored by the runtime. Images are supplied through html. */ + type?: 'video' | 'image' | 'html' + } + interface Result { + name: 'artplayerPluginAds' + /** Complete once; before initialization this cancels the pending preroll. */ + skip: () => void + /** Pause only the countdown, leaving ad video playback unchanged. */ + pause: () => void + /** Resume only the countdown without adding extra timers. */ + play: () => void + } + interface Callable { + (option?: Option): (art: Artplayer) => Result + /** @deprecated Compatibility with erroneous old string-duration declarations only. */ + (option: LegacyOption): (art: Artplayer) => Result + (option: WorkspaceOption): (art: Artplayer) => Result + (option?: CompatOption): (art: Artplayer) => Result + /** Required final signature keeps Parameters extraction free of top-level undefined. */ + (option: CompatOption): (art: Artplayer) => Result + } + interface Factory extends Callable { + /** Same function; supports historical require(package).default calls. */ + readonly default: Callable + } + interface RuntimeCallable { + (option?: Option): (art: Artplayer) => Result + (option: Option): (art: Artplayer) => Result + } + /** Accurate typing for the identical implementation at /runtime. */ + interface RuntimeFactory extends RuntimeCallable { + readonly default: RuntimeCallable + } } - -interface Ads { - name: 'artplayerPluginAds' - - /** - * 跳过广告 - * Skip ad - */ - skip: () => void - - /** - * 暂停广告 - * Pause ad - */ - pause: () => void - - /** - * 播放广告 - * Play ad - */ - play: () => void -} - -// 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 - +declare const artplayerPluginAds: artplayerPluginAds.Factory export = artplayerPluginAds export as namespace artplayerPluginAds; -artplayer-plugin-ambilight.d.ts -This plugin creates an ambient light effect around the video player based on the video content. +===== docs/assets/ts/artplayer-plugin-ambilight.d.ts ===== -interface Option { - blur?: string - opacity?: number - frequency?: number - zIndex?: number - duration?: number +// Generated from the package public declaration by yarn build:ts. Do not edit. +/* eslint-disable ts/no-redeclare -- Callable and public type namespace intentionally merge. */ +declare namespace artplayerPluginAmbilightDefinitions { + export interface Option { + /** CSS blur radius. @default '50px' */ + blur?: string + /** Grid cell opacity. @default 0.5 */ + opacity?: number + /** Maximum sampling frequency in frames per second. @default 10 */ + frequency?: number + /** Historical input retained for compatibility; runtime uses a fixed z-index of 9. */ + zIndex?: number + /** Background color transition duration in seconds. @default 0.3 */ + duration?: number + } + export interface Result { + name: 'artplayerPluginAmbilight' + /** Start sampling; does nothing after the player is destroyed. */ + start: () => void + /** Stop sampling while retaining the last colors. */ + stop: () => void + } + /** Published 1.1.0 factory shape; the options argument remains required. */ + export type Callable = (option: Option) => (art: Artplayer) => Result + export type Factory = Callable + /** Accurate optional invocation and CommonJS self alias, exposed by /runtime. */ + export interface RuntimeFactory { + (option?: Option): (art: Artplayer) => Result + readonly default: RuntimeFactory + } + export const artplayerPluginAmbilight: (option: Option) => (art: Artplayer) => Result } - -interface Result { - name: 'artplayerPluginAmbilight' - start: () => void - stop: () => void +declare const artplayerPluginAmbilight: typeof artplayerPluginAmbilightDefinitions.artplayerPluginAmbilight +declare namespace artplayerPluginAmbilight { + export type Option = artplayerPluginAmbilightDefinitions.Option + export type Result = artplayerPluginAmbilightDefinitions.Result + export type Callable = artplayerPluginAmbilightDefinitions.Callable + export type Factory = artplayerPluginAmbilightDefinitions.Factory + export type RuntimeFactory = artplayerPluginAmbilightDefinitions.RuntimeFactory } - -declare const artplayerPluginAmbilight: (option: Option) => (art: Artplayer) => Result - -export default artplayerPluginAmbilight - export = artplayerPluginAmbilight export as namespace artplayerPluginAmbilight; -artplayer-plugin-asr.d.ts -This plugin provides Automatic Speech Recognition (ASR) functionality, capturing audio chunks for subtitle generation. +===== docs/assets/ts/artplayer-plugin-asr.d.ts ===== -interface AudioChunk { - pcm: ArrayBuffer - wav: ArrayBuffer +// Generated from the package public declaration by yarn build:ts. Do not edit. +/* eslint-disable ts/no-redeclare -- Callable and public type namespace intentionally merge. */ +declare namespace artplayerPluginAsrDefinitions { + export interface AudioChunk { + pcm: ArrayBuffer + wav: ArrayBuffer + } + export interface AsrPluginOption { + length?: number + interval?: number + sampleRate?: number + autoHideTimeout?: number + onAudioChunk?: (chunk: AudioChunk) => void | Promise + } + export interface AsrPluginInstance { + name: 'artplayerPluginAsr' + stop: () => void + hide: () => void + append: (subtitle: string) => void + } + /** Historical factory shape, including void stop and callback results. */ + export type Factory = (option?: AsrPluginOption) => (art: Artplayer) => AsrPluginInstance + /** Accurate asynchronous view available through the /runtime entry. */ + export interface RuntimeOption extends Omit { + /** Capture the media stream without taking ownership of its playback route. */ + audioInput?: { + type: 'capture' + } + onAudioChunk?: (chunk: AudioChunk) => string | void | null | Promise + } + export interface RuntimeResult extends Omit { + stop: () => Promise + } + export interface RuntimeFactory { + (option?: RuntimeOption): (art: Artplayer) => RuntimeResult + readonly default: RuntimeFactory + } + export function artplayerPluginAsr(option?: AsrPluginOption): (art: Artplayer) => AsrPluginInstance } - -interface AsrPluginOption { - length?: number - interval?: number - sampleRate?: number - autoHideTimeout?: number - onAudioChunk?: (chunk: AudioChunk) => void | Promise +declare const artplayerPluginAsr: typeof artplayerPluginAsrDefinitions.artplayerPluginAsr +declare namespace artplayerPluginAsr { + export type AudioChunk = artplayerPluginAsrDefinitions.AudioChunk + export type AsrPluginOption = artplayerPluginAsrDefinitions.AsrPluginOption + export type AsrPluginInstance = artplayerPluginAsrDefinitions.AsrPluginInstance + export type Factory = artplayerPluginAsrDefinitions.Factory + export type RuntimeOption = artplayerPluginAsrDefinitions.RuntimeOption + export type RuntimeResult = artplayerPluginAsrDefinitions.RuntimeResult + export type RuntimeFactory = artplayerPluginAsrDefinitions.RuntimeFactory } - -interface AsrPluginInstance { - name: 'artplayerPluginAsr' - stop: () => void - hide: () => void - append: (subtitle: string) => void -} - -declare function artplayerPluginAsr(option?: AsrPluginOption): (art: Artplayer) => AsrPluginInstance - -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. +===== docs/assets/ts/artplayer-plugin-audio-track.d.ts ===== -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 +// Generated from the package public declaration by yarn build:ts. Do not edit. +/* eslint-disable ts/no-redeclare -- Callable and public type namespace intentionally merge. */ +declare namespace artplayerPluginAudioTrackDefinitions { + export 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 + } + export type UpdateOption = Partial