diff --git a/packages/artplayer-document/docs/zh-cn/Events.md b/packages/artplayer-document/docs/zh-cn/Events.md deleted file mode 100644 index 996310bff..000000000 --- a/packages/artplayer-document/docs/zh-cn/Events.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -title: 实例事件 -sidebar_position: 6 -slug: /zh-cn/events ---- diff --git a/packages/artplayer-document/docs/zh-cn/Events.mdx b/packages/artplayer-document/docs/zh-cn/Events.mdx new file mode 100644 index 000000000..b6f171de3 --- /dev/null +++ b/packages/artplayer-document/docs/zh-cn/Events.mdx @@ -0,0 +1,126 @@ +--- +title: 实例事件 +sidebar_position: 6 +slug: /zh-cn/events +--- + +播放器的事件分为两种,一种视频的原生事件,另外一种是自定义的事件 + +原生事件来自 `video` 元素,为了让它和自定义事件区分,原生事件添加了前缀 `video:` + +## 原生事件 + +更多信息请阅读 [Mozilla Video Events](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video#events) + +| 事件名字 | 触发时间 | +| ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `video:canplay` | The browser can play the media, but estimates that not enough data has been loaded to play the media up to its end without having to stop for further buffering of content. | +| `video:canplaythrough` | The browser estimates it can play the media up to its end without stopping for content buffering. | +| `video:complete` | The rendering of an OfflineAudioContext is terminated. | +| `video:durationchange` | The duration attribute has been updated. | +| `video:emptied` | The media has become empty; for example, this event is sent if the media has already been loaded (or partially loaded), and the load() method is called to reload it. | +| `video:ended` | Playback has stopped because the end of the media was reached. | +| `video:loadeddata` | The first frame of the media has finished loading. | +| `video:loadedmetadata` | The metadata has been loaded. | +| `video:pause` | Playback has been paused. | +| `video:play` | Playback has begun. | +| `video:playing` | Playback is ready to start after having been paused or delayed due to lack of data. | +| `video:progress` | Fired periodically as the browser loads a resource. | +| `video:ratechange` | The playback rate has changed. | +| `video:seeked` | A seek operation completed. | +| `video:seeking` | A seek operation began. | +| `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 attribute has been updated. | +| `video:volumechange` | The volume has changed. | +| `video:waiting` | Playback has stopped because of a temporary lack of data | + +## 自定义事件 + +### ready + +当实例初始化完成,并视频可以被播放时触发,只会触发一个,哪怕视频地址变化了 + +
▶ Run Code
+ +```js +var art = new Artplayer({ + container: '.artplayer-app', + url: '/assets/sample/video.mp4', +}); + +art.on('ready', (...args) => { + console.info(args) +}) +``` + +### play + +在视频被播放后触发 + +
▶ Run Code
+ +```js +var art = new Artplayer({ + container: '.artplayer-app', + url: '/assets/sample/video.mp4', +}); + +art.on('play', (...args) => { + console.info(args) +}) +``` + +### pause + +在视频被暂停后触发 + +
▶ Run Code
+ +```js +var art = new Artplayer({ + container: '.artplayer-app', + url: '/assets/sample/video.mp4', +}); + +art.on('pause', (...args) => { + console.info(args) +}) +``` + +| 事件名字 | 触发时间 | +| ------------------ | ------------------------------------ | +| `seek` | When the video seek | +| `volume` | When the video volume change | +| `destroy` | When the player is destroyed | +| `focus` | When the player gets focus | +| `blur` | When the player loses focus | +| `hover` | When the mouse is moved into or out | +| `resize` | When the player resize | +| `mousemove` | When the mouse moves over the player | +| `aspectRatio` | When aspect ratio change | +| `url` | When the video url change | +| `autoSize` | When the player auto size change | +| `flip` | When the player flip change | +| `fullscreen` | When the full screen change | +| `fullscreenWeb` | When the web full screen change | +| `fullscreenRotate` | When the rotate full screen change | +| `pip` | When the picture in picture change | +| `mini` | When the mini player change | +| `playbackRate` | When playback rate change | +| `screenshot` | When a screenshot | +| `switch` | When switching video url | +| `loop` | When the interval loop change | +| `subtitleUpdate` | When the subtitles change | +| `subtitleSwitch` | When switching subtitles | +| `subtitleLoad` | When the subtitles loaded | +| `subtitle` | When displaying subtitles | +| `notice` | When displaying notice | +| `mask` | When displaying mask | +| `loading` | When displaying loading | +| `layer` | When displaying layer | +| `info` | When displaying info | +| `setting` | When displaying setting | +| `contextmenu` | When displaying contextmenu | +| `control` | When displaying control | +| `hotkey` | When the hotkey is triggered |