import{_ as n,c as l,o as p,V as s,z as a}from"./chunks/framework.5c8808ab.js";const Ls=JSON.parse('{"title":"Instance Properties","description":"","frontmatter":{},"headers":[],"relativePath":"en/advanced/property.md","filePath":"en/advanced/property.md","lastUpdated":1700976201000}'),o={name:"en/advanced/property.md"},e=s('

Instance Properties ​

Here, instance properties refer to the primary properties mounted on the instance, which are quite commonly used.

play ​

Play video

',5),r=a("div",{className:"run-code"},"▶ Run Code",-1),t=s(`
js
var art = new Artplayer({
    container: '.artplayer-app',
    url: '/assets/sample/video.mp4',
    muted: true,
});

art.on('ready', () => {
    art.play();
});

pause ​

Pause video

`,4),c=a("div",{className:"run-code"},"▶ Run Code",-1),D=s(`
js
var art = new Artplayer({
    container: '.artplayer-app',
    url: '/assets/sample/video.mp4',
    muted: true,
});

art.on('ready', () => {
    art.play();

    setTimeout(() => {
        art.pause();
    }, 3000);
});

toggle ​

Toggle the play and pause state of the video

`,4),y=a("div",{className:"run-code"},"▶ Run Code",-1),F=s(`
js
var art = new Artplayer({
    container: '.artplayer-app',
    url: '/assets/sample/video.mp4',
    muted: true,
});

art.on('ready', () => {
    art.toggle();

    setTimeout(() => {
        art.toggle();
    }, 3000);
});

destroy ​

Destroy the player. Accepts a parameter indicating whether to remove the player's html after destruction, which defaults to true

`,4),i=a("div",{className:"run-code"},"▶ Run Code",-1),A=s(`
js
var art = new Artplayer({
    container: '.artplayer-app',
    url: '/assets/sample/video.mp4',
});

art.on('ready', () => {
    art.destroy();
});

seek ​

Jump to a specific time in the video, in seconds.

`,4),C=a("div",{className:"run-code"},"▶ Run Code",-1),d=s(`
js
var art = new Artplayer({
    container: '.artplayer-app',
    url: '/assets/sample/video.mp4',
});

art.on('ready', () => {
    art.seek = 5;
});

forward ​

Fast forward the video time, in seconds.

`,4),u=a("div",{className:"run-code"},"▶ Run Code",-1),b=s(`
js
var art = new Artplayer({
    container: '.artplayer-app',
    url: '/assets/sample/video.mp4',
});

art.on('ready', () => {
    art.forward = 5;
});

backward ​

Video rewind time in seconds

`,4),m=a("div",{className:"run-code"},"▶ Run Code",-1),h=s(`
js
var art = new Artplayer({
    container: '.artplayer-app',
    url: '/assets/sample/video.mp4',
});

art.on('ready', () => {
    art.seek = 5;

    setTimeout(() => {
        art.backward = 2;
    }, 3000);
});

volume ​

Sets and gets the video volume, which ranges from [0, 1]

`,4),_=a("div",{className:"run-code"},"▶ Run Code",-1),g=s(`
js
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 ​

Set and retrieve the video address

`,4),v=a("div",{className:"run-code"},"▶ Run Code",-1),T=s(`
js
var art = new Artplayer({
    container: '.artplayer-app',
    url: '/assets/sample/video.mp4',
});

art.on('ready', () => {
    art.url = '/assets/sample/video.mp4?t=0';
});

switch ​

Set the video address, which is similar to art.url, but performs some optimization operations

`,4),E=a("div",{className:"run-code"},"▶ Run Code",-1),S=s(`
js
var art = new Artplayer({
    container: '.artplayer-app',
    url: '/assets/sample/video.mp4',
});

art.on('ready', () => {
    art.seek = 10;
    setTimeout(() => {
        art.switch = '/assets/sample/video.mp4?t=0';
    }, 3000);
});

switchUrl ​

Set the video address, similar to setting art.url, but some optimization operations will be executed.

`,4),P=a("div",{className:"run-code"},"▶ Run Code",-1),w=s(`
js
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');
    }, 3000);
});

Warning

art.switch and art.switchUrl have the same functionality. However, the art.switchUrl method will return a Promise. When it resolves, it indicates that the new address can be played; when it rejects, it indicates there was an error loading the new address.

switchQuality ​

Set video quality address, similar to art.switchUrl, but it will carry over the previous playback progress.

`,5),f=a("div",{className:"run-code"},"▶ Run Code",-1),k=s(`
js
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');
    }, 3000);
});

muted ​

Set and get whether the video is muted.

`,4),q=a("div",{className:"run-code"},"▶ Run Code",-1),R=s(`
js
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 ​

Set and get the current time of the video. Setting the time is similar to seek, but it does not trigger additional events.

`,4),N=a("div",{className:"run-code"},"▶ Run Code",-1),V=s(`
js
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 ​

Get the video duration

`,4),I=a("div",{className:"run-code"},"▶ Run Code",-1),j=s(`
js
var art = new Artplayer({
    container: '.artplayer-app',
    url: '/assets/sample/video.mp4',
});

art.on('ready', () => {
    console.info(art.duration);
});

Note

Some videos do not have a duration, such as videos that are being live streamed or videos that have not been fully decoded, in which case the obtained duration will be 0

screenshot ​

Download a screenshot of the current video frame

`,5),x=a("div",{className:"run-code"},"▶ Run Code",-1),G=s(`
js
var art = new Artplayer({
    container: '.artplayer-app',
    url: '/assets/sample/video.mp4',
});

art.on('ready', () => {
    art.screenshot();
});

getDataURL ​

Gets the base64 address of the screenshot of the current video frame, which returns a Promise.

`,4),z=a("div",{className:"run-code"},"▶ Run Code",-1),B=s(`
js
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 ​

Gets the blob address of the screenshot of the current video frame, which returns a Promise.

`,4),U=a("div",{className:"run-code"},"▶ Run Code",-1),W=s(`
js
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 ​

Set and get the player window fullscreen

`,4),H=a("div",{className:"run-code"},"▶ Run Code",-1),L=s(`
js
var art = new Artplayer({
    container: '.artplayer-app',
    url: '/assets/sample/video.mp4',
    controls: [
        {
            position: 'right',
            html: 'Fullscreen Switch',
            click: function () {
                art.fullscreen = !art.fullscreen;
            },
        },
    ],
});

Note

Due to browser security mechanisms, before triggering the window to fullscreen, the page must have had an interaction (e.g. user clicked on the page).

fullscreenWeb ​

Set and get the player web page full screen

`,5),O=a("div",{className:"run-code"},"▶ Run Code",-1),$=s(`
js
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 ​

Set and get the player picture-in-picture mode

`,4),J=a("div",{className:"run-code"},"▶ Run Code",-1),M=s(`
js
var art = new Artplayer({
    container: '.artplayer-app',
    url: '/assets/sample/video.mp4',
    controls: [
        {
            position: 'right',
            html: 'PIP',
            click: function () {
                art.pip = !art.pip;
            },
        },
    ],
});

Warning

Due to browser security mechanisms, user interaction (e.g., a user click on the page) must occur before triggering picture-in-picture.

poster ​

Set and get the video poster, the poster effect is visible only before the video starts playing.

`,5),Q=a("div",{className:"run-code"},"▶ Run Code",-1),K=s(`
js
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 ​

Set and get the player's mini mode

`,4),X=a("div",{className:"run-code"},"▶ Run Code",-1),Y=s(`
js
var art = new Artplayer({
    container: '.artplayer-app',
    url: '/assets/sample/video.mp4',
});

art.on('ready', () => {
    art.mini = true;
});

playing ​

Get whether the video is currently playing

`,4),Z=a("div",{className:"run-code"},"▶ Run Code",-1),ss=s(`
js
var art = new Artplayer({
    container: '.artplayer-app',
    url: '/assets/sample/video.mp4',
    muted: true,
});

art.on('ready', () => {
    console.info(art.playing);
});

autoSize ​

Sets whether the video should auto adjust its size

`,4),as=a("div",{className:"run-code"},"▶ Run Code",-1),ns=s(`
js
var art = new Artplayer({
    container: '.artplayer-app',
    url: '/assets/sample/video.mp4',
});

art.on('ready', () => {
    art.autoSize();
});

rect ​

Gets the size and position information of the player

`,4),ls=a("div",{className:"run-code"},"▶ Run Code",-1),ps=s(`
js
var art = new Artplayer({
    container: '.artplayer-app',
    url: '/assets/sample/video.mp4',
});

art.on('ready', () => {
    console.info(JSON.stringify(art.rect));
});

Warning

The size and coordinates are obtained via getBoundingClientRect

flip ​

Set and get the player flip, supports normal, horizontal, vertical

`,5),os=a("div",{className:"run-code"},"▶ Run Code",-1),es=s(`
js
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 ​

`,3),rs=a("div",{className:"run-code"},"▶ Run Code",-1),ts=s(`
js
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 ​

Set and get the aspect ratio of the player

`,4),cs=a("div",{className:"run-code"},"▶ Run Code",-1),Ds=s(`
js
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);
});

autoHeight ​

When the container has only width, this attribute can automatically calculate and set the height of the video

`,4),ys=a("div",{className:"run-code"},"▶ Run Code",-1),Fs=s(`
js
var art = new Artplayer({
    container: '.artplayer-app',
    url: '/assets/sample/video.mp4',
});

art.on('ready', () => {
    art.autoHeight();
});

art.on('resize', () => {
    art.autoHeight();
});

Warning

When your container has only width but you do not know the exact height, this property is very useful as it can automatically calculate the video's height, but you need to make sure when to set this property.

attr ​

Dynamically get and set the attributes of the video element

`,5),is=a("div",{className:"run-code"},"▶ Run Code",-1),As=s(`
js
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'));
});

type ​

Dynamically get and set the video type

`,4),Cs=a("div",{className:"run-code"},"▶ Run Code",-1),ds=s(`
js
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 ​

Dynamically get and set the player's theme color

`,4),us=a("div",{className:"run-code"},"▶ Run Code",-1),bs=s(`
js
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 ​

Activate airplay

`,4),ms=a("div",{className:"run-code"},"▶ Run Code",-1),hs=s(`
js
var art = new Artplayer({
    container: '.artplayer-app',
    url: '/assets/sample/video.mp4',
    controls: [
        {
            position: 'right',
            html: 'AirPlay',
            click: function () {
                art.airplay();
            },
        },
    ],
});

loaded ​

The proportion of the video that is cached, ranging from [0, 1], commonly used with the video:timeupdate event.

`,4),_s=a("div",{className:"run-code"},"▶ Run Code",-1),gs=s(`
js
var art = new Artplayer({
    container: '.artplayer-app',
    url: '/assets/sample/video.mp4',
});

art.on('video:timeupdate', () => {
    console.info(art.loaded);
});

played ​

The proportion of the video that has been played, ranging from [0, 1], commonly used with the video:timeupdate event.

`,4),vs=a("div",{className:"run-code"},"▶ Run Code",-1),Ts=s(`
js
var art = new Artplayer({
    container: '.artplayer-app',
    url: '/assets/sample/video.mp4',
});

art.on('video:timeupdate', () => {
    console.info(art.played);
});

proxy ​

A proxy function for DOM events, which essentially proxies addEventListener and removeEventListener. When using proxy to handle events, the event will automatically be destroyed when the player is destroyed.

`,4),Es=a("div",{className:"run-code"},"▶ Run Code",-1),Ss=s(`
js
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 to exist only during the lifespan of the player, it is highly recommended to use this function to avoid causing memory leaks.

query ​

DOM query function, similar to document.querySelector, but the object being queried is limited within the current player, which can prevent errors due to having the same class name.

`,5),Ps=a("div",{className:"run-code"},"▶ Run Code",-1),ws=s(`
js
var art = new Artplayer({
	container: '.artplayer-app',
	url: '/assets/sample/video.mp4',
});

console.info(art.query('.art-video'));

video ​

A shortcut to return the video element of the player.

`,4),fs=a("div",{className:"run-code"},"▶ Run Code",-1),ks=s(`
js
var art = new Artplayer({
	container: '.artplayer-app',
	url: '/assets/sample/video.mp4',
});

console.info(art.video);

cssVar ​

Dynamically getting or setting css variables

`,4),qs=a("div",{className:"run-code"},"▶ Run Code",-1),Rs=s(`
js
var art = new Artplayer({
	container: '.artplayer-app',
	url: '/assets/sample/video.mp4',
});

art.on('ready', () => {
    console.log(art.cssVar('--art-theme'));
    art.cssVar('--art-theme', 'green');
    console.log(art.cssVar('--art-theme'));
});

quality ​

Dynamically setting the list of qualities

`,4),Ns=a("div",{className:"run-code"},"▶ Run Code",-1),Vs=s(`
js
var art = new Artplayer({
	container: '.artplayer-app',
	url: '/assets/sample/video.mp4',
	quality: [
		{
			default: true,
			html: 'SD 480P',
			url: '/assets/sample/video.mp4',
		},
		{
			html: 'HD 720P',
			url: '/assets/sample/video.mp4',
		},
	],
});

art.on('ready', () => {
	setTimeout(() => {
		art.quality = [
			{
				default: true,
				html: '1080P',
				url: '/assets/sample/video.mp4',
			},
			{
				html: '4K',
				url: '/assets/sample/video.mp4',
			},
		];
	}, 3000);
})
`,1),Is=[e,r,t,c,D,y,F,i,A,C,d,u,b,m,h,_,g,v,T,E,S,P,w,f,k,q,R,N,V,I,j,x,G,z,B,U,W,H,L,O,$,J,M,Q,K,X,Y,Z,ss,as,ns,ls,ps,os,es,rs,ts,cs,Ds,ys,Fs,is,As,Cs,ds,us,bs,ms,hs,_s,gs,vs,Ts,Es,Ss,Ps,ws,fs,ks,qs,Rs,Ns,Vs];function js(xs,Gs,zs,Bs,Us,Ws){return p(),l("div",null,Is)}const Os=n(o,[["render",js]]);export{Ls as __pageData,Os as default};