首页 > 解决方案 > 如何使用 Plyr JS 在视频播放器中添加下载按钮?

问题描述

我正在使用Plyr JS 并希望download为每个video.

这是我试图download option提供的内容:

尽管我提供了: controlsList="nodownload"

<video controls crossorigin playsinline controlsList="nodownload" poster="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.jpg" id="player">
     <source src="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-576p.mp4" type="video/mp4" size="576">
</video>

问题:如何使下载选项仅使用Plyr.io插件显示?

这是我的演示: https ://codepen.io/msolimans/pen/xQEjmX

标签: javascripthtmlhtml5-videoplyr.js

解决方案


您可以使用 Plyr JS 自定义所有 Plyr 控件。这是来自官方来源的完整描述。

控件

这是为 Plyr 控件呈现的标记。您可以使用默认控件或根据您的需要提供自定义版本的标记。您可以将以下内容传递给控制选项:

  • Array选项(这会根据您的选择构建默认控件)
  • Element与控件
  • String包含所需的 HTML
  • false(或空字符串或数组)禁用所有控件
  • Function将被执行并应返回上述之一

演示:CodePen.io 上带有自定义控件(包括下载按钮)的Plyr 播放器

在 StackOverflow 片段中,下载按钮不起作用,因为它位于沙箱中。请参阅 CodePen.io 上的演示(上面的链接)。

Array带有选项的示例:

var controls =
[
    'play-large', // The large play button in the center
    'restart', // Restart playback
    'rewind', // Rewind by the seek time (default 10 seconds)
    'play', // Play/pause playback
    'fast-forward', // Fast forward by the seek time (default 10 seconds)
    'progress', // The progress bar and scrubber for playback and buffering
    'current-time', // The current time of playback
    'duration', // The full duration of the media
    'mute', // Toggle mute
    'volume', // Volume control
    'captions', // Toggle captions
    'settings', // Settings menu
    'pip', // Picture-in-picture (currently Safari only)
    'airplay', // Airplay (currently Safari only)
    'download', // Show a download button with a link to either the current source or a custom URL you specify in your options
    'fullscreen' // Toggle fullscreen
];

var player = new Plyr('#player', { controls });

推荐阅读