Document PictureInPicture API

349 Views

January 31, 25

スライド概要

Classi エンジニアLT会の資料です

profile-image

岡山県在住。小売店、飲食業を経て2000年よりウェブ制作に従事し、2023年6月からClassiに所属。 業務外の活動として、セミナーイベント・勉強会への登壇、書籍の執筆・寄稿など執筆活動、技術系ドキュメントの翻訳などを行う。 ウェブクリエイターズニュース管理人。okayama-js主宰。Okayama WordPress Meetup オーガナイザー。

シェア

またはPlayer版

埋め込む »CMSなどでJSが使えない場合

関連スライド

各ページのテキスト
1.

Document Picture-in-Picture API Classi エンジニアLT会 前川昌幸 2025.01.31

2.

Picture-In-Picture

3.

Picture-In-Picture

4.

Picture-In-Picture

5.

2種類のPicture-In-Picture API • Picture-In-Picture API • https://developer.mozilla.org/en-US/docs/Web/API/Picture-inPicture_API • 浮動動画ウィンドウ • Document Picture-In-Picture API • https://developer.mozilla.org/en-US/docs/Web/API/ Document_Picture-in-Picture_API • Google Meetで利用されているのはこちら

6.

2種類のPicture-In-Picture API • Picture-In-Picture API • Firefox以外は利用できる • Document Picture-In-Picture API • デスクトップのChromium系のみ

7.

2種類のPicture-In-Picture API • Picture-In-Picture API • Firefox以外は利用できる • Document Picture-In-Picture API • デスクトップのChromium系のみ

8.

Document Picture-In-Picture API • HTMLを入れるなど、window.openで開くポップアップ的な利用ができる • 軽く動作デモ • https://gist.github.com/maepon/ 85e6dbc9a86adc2e10183ab8c2786bf4

9.

Document Picture-In-Picture API

10.
[beta]
async function openPip(){
// Picture-In-Pictureを開く
pipWindow = await window.documentPictureInPicture.requestWindow({
width: 300,
height: 200,
});
// Picture-In-PictureにHTMLを挿入
pipWindow.document.body.append(box1);
// 閉じる動作(HTMLを元に戻す)
pipWindow.addEventListener('pagehide', (event) => {
const pinBox = event.target.querySelector('#box-1');
wrapBox.append(pinBox);
});
}

11.
[beta]
window.addEventListener('blur',windowBlur)
window.addEventListener('focus',windowFocus)
function windowBlur() {
if (!pipWindow || pipWindow.closed){
openPip();
}
}
function windowFocus() {
if (pipWindow || !pipWindow.closed){
closePip();
}
}

Chromeではクリックなどの明示的動作
がない場合は開かないので、左記のコードは
許可をする必要がある。
(Edgeは必要無く開く)

12.
[beta]
自分で開けないとき
// Picture-In-Pictureを開く
pipWindow = await window.documentPictureInPicture.requestWindow({
width: 300,
height: 200,
});

という感じで受けられない場合

13.
[beta]
自分で開けないとき
window.documentPictureInPicture.addEventListener('enter', event => {
const pipTarget = event.target;
// ウィンドウへの操作は event.target.window
pipTarget.window.close();
// bodyへの追加などは event.window.document.body
pipTarget.window.document.body.append(foo);
})

14.

イベントの起動もOK

15.

これを調べている理由は……

16.

ここのチャットをなんとかしたくて!

17.

格闘中

18.

ありがとうございました!