mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 19:06:15 -08:00
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
// npm i artplayer-plugin-iframe
|
|
// import ArtplayerPluginIframe from 'artplayer-plugin-iframe';
|
|
|
|
const $iframe = document.createElement('iframe');
|
|
$iframe.allowFullscreen = true;
|
|
$iframe.width = '100%';
|
|
$iframe.height = '100%';
|
|
|
|
const $container = document.querySelector('.artplayer-app');
|
|
$container.innerHTML = '';
|
|
$container.appendChild($iframe);
|
|
|
|
const iframe = new ArtplayerPluginIframe({
|
|
iframe: $iframe,
|
|
url: '/iframe.html',
|
|
});
|
|
|
|
iframe.message(({ type, data }) => {
|
|
switch (type) {
|
|
case 'fullscreenWeb':
|
|
if (data) {
|
|
$iframe.classList.add('fullscreenWeb');
|
|
} else {
|
|
$iframe.classList.remove('fullscreenWeb');
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
});
|
|
|
|
iframe.commit(() => {
|
|
var art = new Artplayer({
|
|
container: '.artplayer-app',
|
|
url: '/assets/sample/video.mp4',
|
|
fullscreen: true,
|
|
fullscreenWeb: true,
|
|
});
|
|
|
|
art.on('fullscreenWeb', (state) => {
|
|
ArtplayerPluginIframe.postMessage({
|
|
type: 'fullscreenWeb',
|
|
data: state,
|
|
});
|
|
});
|
|
});
|