##// END OF EJS Templates
Backport PR #13147: Reword the YouTubeVideo autoplay WN
Backport PR #13147: Reword the YouTubeVideo autoplay WN

File last commit:

r26788:c8bc91db
r26788:c8bc91db
Show More
enable-to-add-extra-attrs-to-iframe.rst
39 lines | 1.2 KiB | text/x-rst | RstLexer
/ docs / source / whatsnew / pr / enable-to-add-extra-attrs-to-iframe.rst
Blazej Michalik
Backport PR #13147: Reword the YouTubeVideo autoplay WN
r26788 ``YouTubeVideo`` autoplay and the ability to add extra attributes to ``IFrame``
===============================================================================
Blazej Michalik
Backport PR #13133: enable autoplay in embed youtube player
r26782
Blazej Michalik
Backport PR #13147: Reword the YouTubeVideo autoplay WN
r26788 You can add any extra attributes to the ``<iframe>`` tag using the new
``extras`` argument in the ``IFrame`` class. For example::
Blazej Michalik
Backport PR #13133: enable autoplay in embed youtube player
r26782
In [1]: from IPython.display import IFrame
Blazej Michalik
Backport PR #13147: Reword the YouTubeVideo autoplay WN
r26788 In [2]: IFrame(src="src", width=300, height=300, extras=['loading="eager"'])
Blazej Michalik
Backport PR #13133: enable autoplay in embed youtube player
r26782
Blazej Michalik
Backport PR #13147: Reword the YouTubeVideo autoplay WN
r26788 The above cells will result in the following HTML code being displayed in a
notebook::
Blazej Michalik
Backport PR #13133: enable autoplay in embed youtube player
r26782
Blazej Michalik
Backport PR #13147: Reword the YouTubeVideo autoplay WN
r26788 <iframe
width="300"
height="300"
src="src"
frameborder="0"
allowfullscreen
loading="eager"
></iframe>
Related to the above, the ``YouTubeVideo`` class now takes an
``allow_autoplay`` flag, which sets up the iframe of the embedded YouTube video
such that it allows autoplay.
.. note::
Whether this works depends on whether the autoplay policy of the browser
rendering the HTML allows it. It might not work in every circumstance, and
could get blocked by browser extensions.
Try it out!
Blazej Michalik
Backport PR #13133: enable autoplay in embed youtube player
r26782 ::
In [1]: from IPython.display import YouTubeVideo
Blazej Michalik
Backport PR #13147: Reword the YouTubeVideo autoplay WN
r26788 In [2]: YouTubeVideo("dQw4w9WgXcQ", allow_autoplay=True)
Blazej Michalik
Backport PR #13133: enable autoplay in embed youtube player
r26782
Blazej Michalik
Backport PR #13147: Reword the YouTubeVideo autoplay WN
r26788 🙃