项目作者: harsha20599

项目描述 :
A minimal function to simplify the implementation of PIP mode in chrome
高级语言: JavaScript
项目地址: git://github.com/harsha20599/picture-in-picture.git
创建时间: 2019-04-21T01:43:26Z
项目社区:https://github.com/harsha20599/picture-in-picture

开源协议:

下载


Picture In Picture

A minimal function to simplify the implementation of PIP mode in chrome

Here is the live demo

PIP demo

Usage

  1. pip(object, callback);

The object contains

  1. var object = {
  2. // DONOT pass this url if you already have video in your HTML file
  3. url : 'location or url of the video',
  4. button : pipButton,
  5. //optional
  6. preventDefault : true
  7. };

The button can be referenced using getElementById()

Example

  1. const PipButton = document.getElementById('togglePipButton');
  2. // Creating data object
  3. const data = {
  4. url : 'video.mp4',
  5. button : PipButton
  6. }
  7. // Calling the function to initiate picture-in-picture
  8. pip(data,
  9. // handling callback
  10. (err) => {
  11. if(err) {
  12. // Handle the error
  13. return console.log("Error");
  14. }
  15. // On sucessful creation of Picture-in-picture mode
  16. console.log("Sucessful");
  17. }
  18. );

How to get started

  1. Download app.js into your system

  2. Include the downloaded app.js in your HTML file

    1. <script src="location/app.js"></script>

    In above code, replace location with the location where app.js is stored

  3. Include a video in your HTML file with id as video

  4. Create a button inside body of HTML, to toggle the PIP mode

    1. ...
    2. <body>
    3. <video src="location/video.mp4" id="video" ></script>
    4. <button id="togglePIP">togglePIP</button>
    5. </body>
  5. Write the below script inside the body to initiate PIP for the video

    1. ...
    2. <script>
    3. const pipButton = document.getElementById('togglePIP');
    4. pip({pipButton}, (err)=>{
    5. if(err)
    6. return console.log(err);
    7. console.log('Sucessful');
    8. })
    9. </script>
    10. </body>

    Troubleshoot

    • Raise an issue in this repo if you find any bug
    • contact me directly in telegram