4

我正在使用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

4

5 回答 5

5

您可以使用 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 });
于 2018-12-08T12:55:28.647 回答
3

添加带有“下载”标签的链接

<a href="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-576p.mp4" download> download </a>
于 2018-12-05T17:41:00.310 回答
1

您是否尝试过作者的解决方案https ://github.com/sampotts/plyr/issues/193#issuecomment-432629429

您可以通过添加下载在控制选项中打开它。它会自动指向当前源并在新窗口中打开。您还可以在 urls 选项中指定自定义 url,特别是设置 urls.download 属性 - 例如

const player = new Plyr('#player', {
  urls: {
    download: 'https://example.com/path/to/download',
  },
});

通过设置配置,您也可以在更改源时即时设置自定义 URL:

player.config.urls.download = 'https://example.com/path/to/download';
于 2018-12-08T04:30:23.647 回答
1

在这里没有看到太多活动,所以我将添加我如何解决这个问题。确保 plyr.js 文件已链接,然后使用此脚本。只需删除您不想要的元素。即重新启动按钮已被删除(我把它变成了评论)。

<script>

    document.addEventListener('DOMContentLoaded', () => {

        const 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
        ];

        const player = Plyr.setup('.js-player', { controls});
 });
</script>
于 2020-07-16T19:29:37.530 回答
0

下载 Plyr.js 脚本,用 VisualStudio Code 或 Brackets 修改它打开 plyr.js 脚本后,查找以下代码以删除注释的选项。

在下载选项中删除评论。

// Default controls
    controls: ['play-large', // 'restart',
    // 'rewind',
    'play', // 'fast-forward',
    'progress', 'current-time', //'duration',
    'mute', 'volume', 'captions', 'settings', //'pip',
    'airplay', //'download',
    'fullscreen'],
    settings: ['captions', 'quality', 'speed'],

它应该如下所示

// Default controls
    controls: ['play-large', // 'restart',
    // 'rewind',
    'play', // 'fast-forward',
    'progress', 'current-time', //'duration',
    'mute', 'volume', 'captions', 'settings', //'pip',
    'airplay', 'download',
    'fullscreen'],
    settings: ['captions', 'quality', 'speed'],

就是这样,保存更改,瞧

于 2020-10-07T15:00:07.013 回答