mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 19:06:15 -08:00
107 lines
3.1 KiB
HTML
107 lines
3.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Artplayer Iframe Inject</title>
|
|
<style>
|
|
html,
|
|
body {
|
|
width: 100%;
|
|
height: 100%;
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
|
|
.container {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
width: 100%;
|
|
height: 100%;
|
|
padding: 50px;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
.fullscreenWeb {
|
|
position: fixed;
|
|
z-index: 9999;
|
|
width: 100%;
|
|
height: 100%;
|
|
left: 0;
|
|
top: 0;
|
|
right: 0;
|
|
bottom: 0;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="container">
|
|
<iframe id="iframe" frameborder="0" width="100%" height="100%" allowfullscreen="true"></iframe>
|
|
</div>
|
|
<script src="./iframe.helper.js"></script>
|
|
<script>
|
|
(async function () {
|
|
const $iframe = document.getElementById('iframe');
|
|
|
|
// Init iframe helper
|
|
const helper = new IframeHelper({
|
|
iframe: $iframe,
|
|
url: './inner.html',
|
|
});
|
|
|
|
// Listen messages from the iframe
|
|
helper.message(({ type, data }) => {
|
|
switch (type) {
|
|
case 'fullscreenWeb':
|
|
if (data) {
|
|
$iframe.classList.add('fullscreenWeb');
|
|
} else {
|
|
$iframe.classList.remove('fullscreenWeb');
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
});
|
|
|
|
// Instantiate the player and mount the instance in the window
|
|
await helper.commit(() => {
|
|
window.art = new Artplayer({
|
|
container: '.artplayer-app',
|
|
url: '../assets/sample/video.mp4',
|
|
fullscreen: true,
|
|
fullscreenWeb: true,
|
|
});
|
|
|
|
// Send message to parent window
|
|
window.art.on('fullscreenWeb', state => {
|
|
IframeHelper.postMessage({ type: 'fullscreenWeb', data: state })
|
|
});
|
|
});
|
|
|
|
// The value of the player can be returned through the resolve method
|
|
const currentTime = await helper.commit((resolve) => {
|
|
window.art.on('ready', () => {
|
|
window.art.seek = 5;
|
|
resolve(window.art.currentTime);
|
|
});
|
|
});
|
|
|
|
console.log(currentTime);
|
|
|
|
// The value of the player can be returned through the return
|
|
const currentTime2 = await helper.commit(() => {
|
|
return window.art.currentTime;
|
|
});
|
|
|
|
console.log(currentTime2);
|
|
})();
|
|
|
|
</script>
|
|
</body>
|
|
|
|
</html> |