Prevent iframe playing youtube video

偶尔善良 提交于 2019-12-13 02:12:36

问题


Is there an option in iframe to prevent it from playing video i.e. I have following iframe:

<iframe src="https://www.youtube.com/embed/v2ifWcnQs6M" width="468" height="60" ></iframe>

I want to display just the thumbnail of youtube video with red 'play' button in the center of thumbnail, but disallow user to actually play video. Is there a way to do it ?

Because as I checked Youtube IFrame API there is no solution for getting youtube video id i.e. I have to parse url by myself and then construct the following url:

https://img.youtube.com/vi/video_id/0.jpg

And besides this url returns thumbnail without red 'play' button which I also want. So is there an HTML attribute in iframe or js workaround to do it ?


回答1:


Add a transparent div on top of the YouTube video with CSS. See example.




回答2:


No. No such attribute. If you dont want to allow users play that video, you need to construct block manually. Get the thumbnail and create or cut play button image. Then within CSS write layout rules and show to user this constructed block



来源:https://stackoverflow.com/questions/32601119/prevent-iframe-playing-youtube-video

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!