本文介绍了Rails错误:自动播放有时仅对video_tag有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Carrierwave上传视频文件,并且video_tagautoplayloop都设置为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

https://github .com/ethanwilkins/simplr/blob/2c07884d153192566ded30bd020c06237747f401/app/views/posts/_card.html.erb#L87

我也在使用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有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 03:01