问题描述
我正在使用Carrierwave上传视频文件,并且video_tag
的autoplay
和loop
都设置为true
.最初上传视频后,该视频会自动播放,但刷新页面后只会显示视频的第一帧.
I'm using Carrierwave to upload video files and have both autoplay
and loop
set to true
for my video_tag
. The video plays automatically after uploading it initially but only shows the first frame of the video after I've refreshed the page.
video_tag的来源:
Source for video_tag:
video_tag post.video_url.to_s, autoplay: true, loop: true, class: :standard_post_video
我也在使用Nginx和Unicorn.谢谢!
I'm also using Nginx and Unicorn. Thanks!
推荐答案
只需添加
在video_tag中
in video_tag
video_tag post.video_url.to_s, autoplay: true, loop: true, muted: 'muted', class: :standard_post_video
请参阅文档: https://developers.google. com/web/updates/2017/09/autoplay-policy-changes
Chrome的自动播放政策很简单:
Chrome's autoplay policies are simple:
- 始终允许静音的自动播放.
-
在以下情况下允许自动播放声音
- Muted autoplay is always allowed.
Autoplay with sound is allowed if:
- 用户已与域进行了交互(单击,点击等).
- 在台式机上,已经超过了用户的媒体参与度索引"阈值,这表示
- 用户以前曾播放带声音的视频.
-
在移动设备上,用户已[将网站添加到主屏幕].
- User has interacted with the domain (click, tap, etc.).
- On desktop, the user's Media Engagement Index threshold has been crossed, meaning
- the user has previously play video with sound.
On mobile, the user has [added the site to their home screen].
顶级帧可以将自动播放权限委派给其iframe,以允许自动播放声音.
Top frames can delegate autoplay permission to their iframes to allow autoplay with sound.
这篇关于Rails错误:自动播放有时仅对video_tag有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!