import{_ as a,c as l,o as p,a as s,b as n}from"./app.c78ba5b1.js";const Ws=JSON.parse('{"title":"Instance Property","description":"","frontmatter":{},"headers":[{"level":2,"title":"play","slug":"play","link":"#play","children":[]},{"level":2,"title":"pause","slug":"pause","link":"#pause","children":[]},{"level":2,"title":"toggle","slug":"toggle","link":"#toggle","children":[]},{"level":2,"title":"destroy","slug":"destroy","link":"#destroy","children":[]},{"level":2,"title":"seek","slug":"seek","link":"#seek","children":[]},{"level":2,"title":"forward","slug":"forward","link":"#forward","children":[]},{"level":2,"title":"backward","slug":"backward","link":"#backward","children":[]},{"level":2,"title":"volume","slug":"volume","link":"#volume","children":[]},{"level":2,"title":"url","slug":"url","link":"#url","children":[]},{"level":2,"title":"switchUrl","slug":"switchurl","link":"#switchurl","children":[]},{"level":2,"title":"switchQuality","slug":"switchquality","link":"#switchquality","children":[]},{"level":2,"title":"muted","slug":"muted","link":"#muted","children":[]},{"level":2,"title":"currentTime","slug":"currenttime","link":"#currenttime","children":[]},{"level":2,"title":"duration","slug":"duration","link":"#duration","children":[]},{"level":2,"title":"screenshot","slug":"screenshot","link":"#screenshot","children":[]},{"level":2,"title":"getDataURL","slug":"getdataurl","link":"#getdataurl","children":[]},{"level":2,"title":"getBlobUrl","slug":"getbloburl","link":"#getbloburl","children":[]},{"level":2,"title":"fullscreen","slug":"fullscreen","link":"#fullscreen","children":[]},{"level":2,"title":"fullscreenWeb","slug":"fullscreenweb","link":"#fullscreenweb","children":[]},{"level":2,"title":"pip","slug":"pip","link":"#pip","children":[]},{"level":2,"title":"poster","slug":"poster","link":"#poster","children":[]},{"level":2,"title":"mini","slug":"mini","link":"#mini","children":[]},{"level":2,"title":"playing","slug":"playing","link":"#playing","children":[]},{"level":2,"title":"autoSize","slug":"autosize","link":"#autosize","children":[]},{"level":2,"title":"rect","slug":"rect","link":"#rect","children":[]},{"level":2,"title":"flip","slug":"flip","link":"#flip","children":[]},{"level":2,"title":"playbackRate","slug":"playbackrate","link":"#playbackrate","children":[]},{"level":2,"title":"aspectRatio","slug":"aspectratio","link":"#aspectratio","children":[]},{"level":2,"title":"loop","slug":"loop","link":"#loop","children":[]},{"level":2,"title":"autoHeight","slug":"autoheight","link":"#autoheight","children":[]},{"level":2,"title":"attr","slug":"attr","link":"#attr","children":[]},{"level":2,"title":"title","slug":"title","link":"#title","children":[]},{"level":2,"title":"type","slug":"type","link":"#type","children":[]},{"level":2,"title":"theme","slug":"theme","link":"#theme","children":[]},{"level":2,"title":"airplay","slug":"airplay","link":"#airplay","children":[]},{"level":2,"title":"loaded","slug":"loaded","link":"#loaded","children":[]},{"level":2,"title":"played","slug":"played","link":"#played","children":[]},{"level":2,"title":"proxy","slug":"proxy","link":"#proxy","children":[]},{"level":2,"title":"query","slug":"query","link":"#query","children":[]},{"level":2,"title":"video","slug":"video","link":"#video","children":[]}],"relativePath":"en/advanced/property.md","lastUpdated":1674271220000}'),e={name:"en/advanced/property.md"},o=s('
The Instance Property here refers to the Primary Property attached to the Instance, which is more commonly used
play #FunctionPlay video
',5),r=n("div",{className:"run-code"},"▶ Run Code",-1),c=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
muted: true,
});
art.on('ready', () => {
art.play();
});
pause #FunctionPause video
`,4),t=n("div",{className:"run-code"},"▶ Run Code",-1),D=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
muted: true,
});
art.on('ready', () => {
art.play();
setTimeout(() => {
art.pause();
}, 3000);
});
toggle #FunctionToggle video playback and pause
`,4),y=n("div",{className:"run-code"},"▶ Run Code",-1),F=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
muted: true,
});
art.on('ready', () => {
art.toggle();
setTimeout(() => {
art.toggle();
}, 3000);
});
destroy #FunctionBooleanTo destroy the player, accept a parameter indicating whether to remove the player's html after destruction. The default value is true
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', () => {
art.destroy();
});
seek #SetterNumberVideo time jump in seconds
`,4),C=n("div",{className:"run-code"},"▶ Run Code",-1),d=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', () => {
art.seek = 5;
});
forward #SetterNumberVideo time fast forward in seconds
`,4),u=n("div",{className:"run-code"},"▶ Run Code",-1),b=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', () => {
art.forward = 5;
});
backward #SetterNumberVideo time rewind in seconds
`,4),h=n("div",{className:"run-code"},"▶ Run Code",-1),m=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', () => {
art.seek = 5;
setTimeout(() => {
art.backward = 2;
}, 3000);
});
volume #Setter/GetterNumberSet and get video volume, range: [0, 1]
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', () => {
console.info(art.volume);
art.volume = 0.5;
console.info(art.volume);
});
url #Setter/GetterStringSet and get video url
`,4),v=n("div",{className:"run-code"},"▶ Run Code",-1),T=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', () => {
art.url = '/assets/sample/video.mp4?t=0';
});
switchUrl #FunctionStringSetting the video url is similar to that of url, but some optimization operations will be performed
The function supports two parameters, the first is the new video url, and the second is the optional new video name
`,5),E=n("div",{className:"run-code"},"▶ Run Code",-1),f=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', () => {
art.seek = 10;
setTimeout(() => {
art.switchUrl('/assets/sample/video.mp4?t=0', 'New Video Name');
}, 3000);
});
switchQuality #FunctionStringSet the video quality address, similar to switchUrl, but with the previous playback progress
The function supports two parameters, the first is the new video url, and the second is the optional new video name
`,5),S=n("div",{className:"run-code"},"▶ Run Code",-1),w=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', () => {
art.seek = 10;
setTimeout(() => {
art.switchQuality('/assets/sample/video.mp4?t=0', 'New Video Name');
}, 3000);
});
muted #Setter/GetterBooleanSet and get whether the video is muted
`,4),k=n("div",{className:"run-code"},"▶ Run Code",-1),P=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', () => {
console.info(art.muted);
art.muted = true;
console.info(art.muted);
});
currentTime #Setter/GetterNumberSet and get the current time of the video. Setting the time is similar to seek, but it will not trigger additional events
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', () => {
console.info(art.currentTime);
art.currentTime = 5;
console.info(art.currentTime);
});
duration #GetterGet video duration
`,4),I=n("div",{className:"run-code"},"▶ Run Code",-1),V=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', () => {
console.info(art.duration);
});
Tip
Some videos have no duration, such as live videos or videos that have not been decoded. The duration obtained at this time will be 0
screenshot #FunctionDownload a screenshot of the current video frame
`,5),j=n("div",{className:"run-code"},"▶ Run Code",-1),x=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', () => {
art.screenshot();
});
getDataURL #FunctionGet the base64 address of the screenshot of the current video frame, and return a Promise
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', async () => {
const url = await art.getDataURL();
console.info(url)
});
getBlobUrl #FunctionGet the blob address of the screenshot of the current video frame, and return a Promise
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', async () => {
const url = await art.getBlobUrl();
console.info(url);
});
fullscreen #Setter/GetterBooleanSet and get full screen of player window
`,4),U=n("div",{className:"run-code"},"▶ Run Code",-1),W=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
controls: [
{
position: 'right',
html: 'Fullscreen Switch',
click: function () {
art.fullscreen = !art.fullscreen;
},
},
],
});
Tip
Due to the browser security mechanism, the page must have interaction before triggering the full screen of the window (for example, the user has clicked on the page)
fullscreenWeb #Setter/GetterBooleanSet and get full screen of player web page
`,5),L=n("div",{className:"run-code"},"▶ Run Code",-1),O=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
fullscreenWeb: true,
});
art.on('ready', () => {
art.fullscreenWeb = true;
setTimeout(() => {
art.fullscreenWeb = false;
}, 3000);
});
pip #Setter/GetterBooleanSet and get the picture-in-picture mode of the player
`,4),H=n("div",{className:"run-code"},"▶ Run Code",-1),$=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
controls: [
{
position: 'right',
html: 'PIP',
click: function () {
art.pip = !art.pip;
},
},
],
});
Tip
Due to the browser security mechanism, before triggering picture-in-picture, the page must have interaction (for example, the user has clicked on the page)
poster #Setter/GetterStringSet and obtain video posters. You can only see the poster effect before the video is played
`,5),M=n("div",{className:"run-code"},"▶ Run Code",-1),Q=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
poster: '/assets/sample/poster.jpg',
});
art.on('ready', () => {
console.info(art.poster);
art.poster = '/assets/sample/poster.jpg?t=0';
console.info(art.poster);
});
mini #Setter/GetterBooleanSet and get player mini mode
`,4),J=n("div",{className:"run-code"},"▶ Run Code",-1),Y=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', () => {
art.mini = true;
});
playing #GetterBooleanGet whether the video is playing
`,4),K=n("div",{className:"run-code"},"▶ Run Code",-1),X=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
muted: true,
});
art.on('ready', () => {
console.info(art.playing);
});
autoSize #Setter/GetterBooleanSet whether the video is adaptive size. After setting it to true, it will only be executed once
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', () => {
console.info(art.autoSize);
art.autoSize = true;
console.info(art.autoSize);
});
rect #GetterGet the size and coordinate information of the player
`,4),ns=n("div",{className:"run-code"},"▶ Run Code",-1),as=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', () => {
console.info(JSON.stringify(art.rect));
});
Tip
Dimension and coordinate information are obtained through getBoundingClientRect
flip #Setter/GetterStringSet and get player rollover, support normal, horizontal, vertical
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', () => {
console.info(art.flip);
art.flip = 'horizontal';
console.info(art.flip);
});
playbackRate #Setter/GetterNumberSet and get player playback speed
`,4),es=n("div",{className:"run-code"},"▶ Run Code",-1),os=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', () => {
console.info(art.playbackRate);
art.playbackRate = 2;
console.info(art.playbackRate);
});
aspectRatio #Setter/GetterStringSet and obtain the player aspect ratio
`,4),rs=n("div",{className:"run-code"},"▶ Run Code",-1),cs=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', () => {
console.info(art.aspectRatio);
art.aspectRatio = '16:9';
console.info(art.aspectRatio);
});
loop #Setter/GetterArraySet and obtain interval sequential playback in seconds
`,4),ts=n("div",{className:"run-code"},"▶ Run Code",-1),Ds=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', () => {
console.info(art.loop);
art.loop = [5, 10];
console.info(art.loop);
});
Tip
To delete interval looping, just set loop to []
art.loop and art.option.loop aer two different things, please don't mix them up
autoHeight #Setter/GetterBooleanWhen the container has only width, this attribute can automatically calculate and set the height of the video. After it is set to true, it will only be executed once
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', () => {
art.autoHeight = true;
});
art.on('resize', () => {
art.autoHeight = true;
});
提示
This attribute is useful when your container has only width but does not know the specific height. It can automatically calculate the height of the video, but you need to determine the time to set this attribute
attr #FunctionStringGet and set the attributes of the video element dynamically
`,5),is=n("div",{className:"run-code"},"▶ Run Code",-1),As=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', () => {
console.info(art.attr('playsInline'));
art.attr('playsInline', true);
console.info(art.attr('playsInline'));
});
title #Setter/GetterStringGet and set player titles dynamically
`,4),Cs=n("div",{className:"run-code"},"▶ Run Code",-1),ds=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', () => {
console.info(art.title);
art.title = 'New Title';
console.info(art.title);
});
type #Setter/GetterStringGet and set video types dynamically
`,4),us=n("div",{className:"run-code"},"▶ Run Code",-1),bs=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', () => {
console.info(art.type);
art.type = 'm3u8';
console.info(art.type);
});
theme #Setter/GetterStringGet and set player theme color dynamically
`,4),hs=n("div",{className:"run-code"},"▶ Run Code",-1),ms=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('ready', () => {
console.info(art.theme);
art.theme = '#000';
console.info(art.theme);
});
airplay #FunctionEnable airplay
`,4),_s=n("div",{className:"run-code"},"▶ Run Code",-1),gs=s(`var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
controls: [
{
position: 'right',
html: 'AirPlay',
click: function () {
art.airplay();
},
},
],
});
loaded #GetterThe proportion of video cache, with the range of [0, 1], is often used in conjunction with the video:timeupdate event
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('video:timeupdate', () => {
console.info(art.loaded);
});
played #GetterThe proportion of video playback, with the range of [0, 1], is often used in conjunction with the video:timeupdate event
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
art.on('video:timeupdate', () => {
console.info(art.played);
});
proxy #FunctionThe proxy function of DOM event essentially proxies addEventListener and removeEventListener. When proxy is used to process the event, the player will also automatically destroy the event when it is destroyed
var container = document.querySelector('.artplayer-app');
var art = new Artplayer({
container: container,
url: '/assets/sample/video.mp4',
});
art.proxy(container, 'click', event => {
console.info(event);
});
Tip
If you need some DOM events only exist in the life cycle of the player, we strongly recommend using this function to avoid memory leakage
query #FunctionThe query function of DOM is similar to document.querySelector, but the queried object is limited to the current player, which can avoid errors of the same class name
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
console.info(art.query('.art-video'));
video #ElementReturn the video element of the player
var art = new Artplayer({
container: '.artplayer-app',
url: '/assets/sample/video.mp4',
});
console.info(art.video);