简体   繁体   English

如何修改video标签的内部媒体控件下载事件?

[英]How to modify the internal media controls download event of video tag?

The video tag has a download button, is it possible to modify the download event. video标签有下载按钮,是否可以修改下载事件。

For example modify the download file name.例如修改下载文件名。

I've tried to modify the download attribute of video tag, but not works for when blob video src as described in the question How to set the download file extension for blob data我已尝试修改视频标签的download属性,但不适用于问题如何设置 blob 数据的下载文件扩展名中所述的 blob video src

在此处输入图像描述

Note, to inspect the Download button of video tag,注意,要检查视频标签的下载按钮,

Settings|Preferences -> Elements -> Show user agent shadow DOM Settings|Preferences -> Elements -> Show user agent shadow DOM

在此处输入图像描述

The download control is not actually part of the HTML5 spec, rather it is implemented by the user agent, ie the browser.下载控制实际上不是 HTML5 规范的一部分,而是由用户代理(即浏览器)实现的。

Browsers may implement controls differently but most will allow file download via right click - you can see this in your example above where right clicking give the option to 'Save video as...'.浏览器可能会以不同方式实现控件,但大多数浏览器都允许通过右键单击下载文件 - 您可以在上面的示例中看到这一点,右键单击可以选择“将视频另存为...”。

However, I think you mean a download button built into the standard video controls - ie the same place the 'Play', 'fast Forward' etc buttons are.但是,我认为您的意思是标准视频控件中内置的下载按钮 - 即“播放”、“快进”等按钮所在的相同位置。

The HTML5 specification does not say that a download control must be supported - the wording the spec uses is ( https://html.spec.whatwg.org/multipage/media.html#the-video-element ): HTML5 规范并未说明必须支持下载控件 - 规范使用的措辞是 ( https://html.spec.whatwg.org/multipage/media.html#the-video-element ):

This user interface should include features to begin playback, pause playback, seek to an arbitrary position in the content (if the content supports arbitrary seeking), change the volume, change the display of closed captions or embedded sign-language tracks, select different audio tracks or turn on audio descriptions, and show the media content in manners more suitable to the user (eg fullscreen video or in an independent resizable window).此用户界面应包括以下功能:开始播放、暂停播放、在内容中搜索任意 position(如果内容支持任意搜索)、更改音量、更改隐藏式字幕或嵌入式手语轨道的显示、select 不同的音频跟踪或打开音频描述,并以更适合用户的方式显示媒体内容(例如全屏视频或在独立的可调整大小的窗口中)。 Other controls may also be made available.也可以提供其他控件。

Chrome, for example provides the download button you show above as part of the standard controls but Safari does not:例如,Chrome 提供了您在上面显示的下载按钮作为标准控件的一部分,但 Safari 没有:

在此处输入图像描述

Assuming you want your solution to work across browsers also, the best approach is likely to either add custom controls yourself to your video element on your page or to use a third party player that can provide download functionality working as you would like it.假设您希望您的解决方案也可以跨浏览器工作,最好的方法可能是自己将自定义控件添加到页面上的视频元素,或者使用可以提供您希望的下载功能的第三方播放器。

Mozilla provide a good guide (at the time of writing) to create a style custom video controls to which you could add your own download button: Mozilla 提供了一个很好的指南(在撰写本文时)来创建样式自定义视频控件,您可以在其中添加自己的下载按钮:

You could also take a simpler approach and just add your own download button with the video element on your page but that is not as elegant.您也可以采用更简单的方法,只需在页面上添加带有视频元素的下载按钮,但这并不优雅。

If you prefer to use a 3rd party players then plugins exist for players like video.js to add download buttons - eg https://github.com/7Ds7/videojs-vjsdownload#readme如果您更喜欢使用第三方播放器,则可以使用 video.js 等播放器的插件来添加下载按钮 - 例如https://github.com/7Ds7/videojs-vjsdownload#readme

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM