Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ChromeでもPicture in Picture / Picture in Picture...

ChromeでもPicture in Picture / Picture in Picture on Chrome

フロントエンド 百物語( https://kfug.connpass.com/event/93822/ )でGoogleChromeに追加されたPicture in Picture APIの話をしました。

Masashi Hirano

August 12, 2018
Tweet

More Decks by Masashi Hirano

Other Decks in Programming

Transcript

  1. JavaScript pipButton.hidden = !document.pictureInPictureEnabled; pipButton.addEventListener('click', function() { if (!document.pictureInPictureElement) {

    video.requestPictureInPicture() .catch(error => { alert('failed to request'); }); } else { document.exitPictureInPicture() .catch(error => { alert('failed to exit'); }); } }); http://bit.ly/2MBnEQB
  2. Javascript video.addEventListener(‘enterpictureinpicture', (event) => { if (!confirm('Enable Picture in Picture?'))

    { document.exitPictureInPicture(); } }); video.addEventListener(‘leavepictureinpicture', (event) => { windowSize.textContent = ''; alert('Leave Picture in Picture!'); }); http://bit.ly/2MBnEQB
  3. Javascript video.requestPictureInPicture() .then((pipWindow) => { pipWindow.addEventListener('resize', (e) => { const

    {width, height} = e.target; windowSize.textContent = `w: ${width} h: ${height}`; }); }).catch(error => { alert('failed to enable'); }); http://bit.ly/2MBnEQB
  4. Safari൛ if (video.webkitSupportsPresentationMode && typeof video.webkitSetPresentationMode === "function") { //

    Toggle PiP when the user clicks the button. pipButton.addEventListener(“click",(event) => { const mode = video.webkitPresentationMode; video.webkitSetPresentationMode(mode === "picture-in- picture" ? "inline" : "picture-in-picture"); }); } else { // Chrome༻ίʔυ } http://bit.ly/2MBnEQB
  5. Picture In Picture (PiP) | Web | Google Developers Picture-in-Picture

    Mode Now Working on Desktop Google Chrome 68+ ͓͍ɺChromeͰPicture In PictureͰ͖ΔΑ͏ʹͳͬͨͧ(2018/04/15) The Picture-in-Picture API – Arnelle's Blog Adding Picture in Picture to Your Safari Media Controls | Apple Developer Documentation ࢀߟ