Embed video

library("vembedr")

Using this package, you can embed videos into RMarkdown documents and Shiny apps for videos from:

The links above are associated with the embedding API for each of the services; these are the APIs wrapped by the embed() functions in this package. You can also embed the video using only the URL of the page your video is on, with embed_url().

To set the start time, or to change the formatting, check out the use_*() functions in vignette("modify").

Embded using URL

Although a URL can be long and awkward, it will get the job done. If the URL is from one of the supported services, it should just work:

embed_url("https://www.youtube.com/watch?v=BD_n6ju9iRA")

If you would like to generate more-concise code using the URL, you can use the suggest_embed() function:

suggest_embed("https://www.youtube.com/watch?v=BD_n6ju9iRA")
#> embed_youtube("BD_n6ju9iRA")

Embed by service

YouTube

You can get your video’s identifier by inspecting its URL at YouTube - you can use the short version, as well:

suggest_embed("https://youtu.be/JeaBNAXfHfQ")
#> embed_youtube("JeaBNAXfHfQ")

The identifier is the last part of the URL. To embed this video:

embed_youtube("JeaBNAXfHfQ")

Vimeo

For Vimeo, the identifier is also included in the standard URL:

suggest_embed("https://vimeo.com/238200347")
#> embed_vimeo("238200347")

The Vimeo identifier is the path of the URL:

embed_vimeo("238200347")

Box

To share a video on Box, the video file itself will have to be shared. From the Box web-interface, you can do this by clicking the Share button at the top-right corner of your file’s web-page. Then create a Share Link:

Then, you need to capture some information about the embed-link itself, either the URL or the id. Please note that you need to work with the “ugly” URL, not a custom URL:

suggest_embed("https://app.box.com/s/d75g9cr27s2jnx62b86idpgffzzxfdt2")
#> embed_box("d75g9cr27s2jnx62b86idpgffzzxfdt2")

You can do the same thing using the embed_box() function and the id. The Box identifier is the last part of the path, in this case d75g9cr27s2jnx62b86idpgffzzxfdt2.

embed_box("d75g9cr27s2jnx62b86idpgffzzxfdt2")

If you are using a corporate instance of Box, and use the embed_box() function, you will also have to specify the custom_domain. For example, if your URL starts with "https://acme.app.box.com", then your custom_domain is "acme".

Microsoft Stream

Microsoft Stream is a service offered for use by (large) organizations so that they may share videos internally to their organization. As such, this functionality may have limited appeal.

suggest_embed(
  "https://web.microsoftstream.com/video/ae21b0ac-4a2b-41f4-b3fc-f1720dd20f48"
)
#> embed_msstream("ae21b0ac-4a2b-41f4-b3fc-f1720dd20f48")

The identifier is the last part of the path of the URL, in this case ae21b0ac-4a2b-41f4-b3fc-f1720dd20f48.

embed_msstream("ae21b0ac-4a2b-41f4-b3fc-f1720dd20f48") %>%
  use_rounded() %>%
  use_start_time(10)

Because this video is internal to an organization, it will likely not play for you.

Sample videos

In case you need sample videos with which to experiment, this package has you covered:

rickroll_vimeo()

Also (mercifully, not displayed as it seems no-longer embeddable):

rickroll_youtube()