Giter Site home page Giter Site logo

videojs-vjsdownload's Introduction

videojs-vjsdownload

Adds a button to download the video inside the player

Demo

https://7ds7.github.io/videojs-vjsdownload/demo

or

https://codepen.io/binaryunit/pen/xxedpwp

Usage

Include the plugin files

  • videojs-vjsdownload.js
  • videojs-vjsdownload.css

also available trough npm install videojs-vjsdownload

var player = videojs(document.querySelector('.video-js'), {
  plugins: {
    vjsdownload:{
      beforeElement: 'playbackRateMenuButton',
      textControl: 'Download video',
      name: 'downloadButton',
      downloadURL: 'https://video_url.mp4' //optional if you need a different download url than the source
    }
  }
} , function() {
  console.log('Callback video-js initiated');
  this.on('downloadvideo', function(){
    console.log('downloadvideo triggered');
  });
});

Options

  • beforeElement: name of the player.controlBar component for the button to be attached before (default: fullscreenMenuToggle)
  • textControl: String for the controlText (default: 'Download Video')
  • name: name of the DownloadButton component (default: 'downloadButton')
  • downloadURL: oprional file to download (default: null)

Style

By default the download icon is a clip path, to include a custom icon please refer to videojs-vjsdownload.css file

videojs-vjsdownload's People

Contributors

7ds7 avatar ischluff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

videojs-vjsdownload's Issues

Separate window is opening up to download the video file

I am using .mpd file in the src attribute of the video.js player. I have used your plugin to download the .mp4 video, but when I am clicking on the download button a separate tab is opening. Is it possible to trigger the download while being in the same tab? If yes, where should I make changes in the code?

image

Thanks in advance!!

not working with videojs8 / modern javascript?

videojs-vjsdownload.js:45 Uncaught TypeError: Class constructor s cannot be invoked without 'new'
    at new DownloadButton (videojs-vjsdownload.js:45:80)
    at onPlayerReady (videojs-vjsdownload.js:92:44)
    at b.<anonymous> (videojs-vjsdownload.js:117:5)
    at b.<anonymous> (videojs_8_3_0.min.js:12:24999)
    at Array.forEach (<anonymous>)
    at b.<anonymous> (videojs_8_3_0.min.js:12:24977)
    at videojs_8_3_0.min.js:12:27660

Suggestion: Download "in background"

Suggesting to add something like this to trigger a download instead of opening the video file in a new window.

--- videojs-vjsdownload.js.orig 2024-04-02 08:10:26.852589885 +0000
+++ videojs-vjsdownload.js      2024-04-02 08:12:57.650086987 +0000
@@ -41,7 +41,12 @@

   handleClick(e) {
     let currentDownload = this.player().vjsdownload()?.options.downloadURL || this.player().currentSource().src;
-    window.open(currentDownload, "Download");
+    const a = document.createElement('a');
+    a.href = currentDownload;
+    a.download = true;
+    document.body.append(a);
+    a.click();
+    a.remove();
     this.player().trigger("downloadvideo");
   }
 }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.