Title: Embed Video in HTML
Version: 0.1.5
Description: A set of functions for generating HTML to embed hosted video in your R Markdown documents or Shiny applications.
Depends: R (≥ 3.3.0)
License: MIT + file LICENSE
Encoding: UTF-8
Imports: htmltools, httr, stringr, magrittr, glue, assertthat, utils, lifecycle
RoxygenNote: 7.1.2
URL: https://github.com/ijlyttle/vembedr
BugReports: https://github.com/ijlyttle/vembedr/issues
Suggests: testthat, knitr, rmarkdown, covr, here, fs, conflicted, usethis
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2021-12-11 16:43:37 UTC; ijlyttle
Author: Ian Lyttle ORCID iD [aut, cre], Schneider Electric [cph]
Maintainer: Ian Lyttle <ian.lyttle@se.com>
Repository: CRAN
Date/Publication: 2021-12-11 19:30:02 UTC

vembedr: Package for embedding video

Description

The vembedr package lets you embed video into your HTML pages for these services:

Details

It provides two categories of functions:

You can use the pipe (⁠|>⁠ or ⁠%>%⁠) to chain embed function-calls with use function-calls.


Pipe functions

Description

Like dplyr, vembedr also uses the pipe function, ⁠\%>\%⁠ to turn function composition into a series of imperative statements.

Arguments

lhs, rhs

An embed object and a function to apply to it

Examples

# Instead of
use_start_time(rickroll_youtube(), "1m35s")
# you can write
rickroll_youtube() %>% use_start_time("1m35s")

Embed video from service

Description

These functions are used to embed video into your rmarkdown html-documents, or into your shiny apps. There are functions to embed from YouTube, Vimeo, Microsoft Channel 9 (who host the UseR! 2016 videos), and Box.

Usage

embed_box(
  id,
  custom_domain = getOption("vembedr.box_custom_domain"),
  width = NULL,
  height = 300,
  ratio = c("16by9", "4by3"),
  frameborder = 0,
  allowfullscreen = TRUE
)

embed_msstream(
  id,
  width = NULL,
  height = 300,
  ratio = c("16by9", "4by3"),
  query = NULL
)

embed_vimeo(
  id,
  width = NULL,
  height = 300,
  ratio = c("16by9", "4by3"),
  frameborder = 0,
  allowfullscreen = TRUE,
  query = NULL,
  fragment = NULL
)

embed_youtube(
  id,
  width = NULL,
  height = 300,
  ratio = c("16by9", "4by3"),
  frameborder = 0,
  allowfullscreen = TRUE,
  query = NULL
)

Arguments

id

character, identifier provided by the service

custom_domain

character, (used by Box) name of Box-instance to use. It can be useful to use getOption("vembedr.box_custom_domain") if you are using a corporate instance of Box. If NULL, it will use the standard Box instance.

width

numeric, width of iframe (px)

height

numeric, height of iframe (px)

ratio

character, indicates aspect ratio for the ⁠<iframe/>⁠

frameborder

numeric, size of frame border (px)

allowfullscreen

logical, indicates if to allow fullscreen

query

list, items to include in url-query string

fragment

character, string to include as url-fragment

Details

These services allow you to customize a lot of things by specifying an optional query string. The specification for the query string will differ according to the service being used:

YouTube

https://developers.google.com/youtube/player_parameters

Vimeo

https://developer.vimeo.com/player/embedding

Box

https://developer.box.com/guides/embed/box-embed/#programmatically

Microsoft Stream

https://docs.microsoft.com/en-us/stream/portal-embed-video

Value

Object with S3 class vembedr_embed.

See Also

use_start_time()

Examples

embed_youtube("dQw4w9WgXcQ")
embed_vimeo("45196609")
embed_box("m5do45hvzw32iv2aors3urf5pgkxxazx")
embed_msstream("ae21b0ac-4a2b-41f4-b3fc-f1720dd20f48")


Embed video based on URL

Description

You can use this function to embed video using only the URL and you do not need any customization beyond the start-time. It works for all the services supported by the embed() family of functions.

Usage

embed_url(url)

Arguments

url

character, URL of web-page for video

Details

This function calls suggest_embed() then parses and evaluates the code.

Value

Object with S3 class vembedr_embed.

See Also

suggest_embed()

Examples

embed_url("https://youtu.be/1-vcErOPofQ?t=28s")

Embed video from Microsoft Channel 9

Description

[Deprecated]

These functions are deprecated: links to Microsoft Channel 9 no longer work.

Usage

embed_user2016(
  id,
  width = NULL,
  height = 300,
  ratio = c("16by9", "4by3"),
  frameborder = 0,
  allowfullscreen = TRUE
)

embed_user2017(
  id,
  width = NULL,
  height = 300,
  ratio = c("16by9", "4by3"),
  frameborder = 0,
  allowfullscreen = TRUE
)

rickroll_channel9(...)

embed_channel9(
  id,
  width = NULL,
  height = 300,
  ratio = c("16by9", "4by3"),
  frameborder = 0,
  allowfullscreen = TRUE
)

Arguments

id

character, identifier provided by the service

width

numeric, width of iframe (px)

height

numeric, height of iframe (px)

ratio

character, indicates aspect ratio for the ⁠<iframe/>⁠

frameborder

numeric, size of frame border (px)

allowfullscreen

logical, indicates if to allow fullscreen

...

arguments (other than id) passed on to embed()

Value

Object with S3 class vembedr_embed.


Determine service based on URL

Description

Determine service based on URL

Usage

get_service(url)

Arguments

url

character, URL of web-page for video

Value

character identifying the video service

Examples

get_service("https://youtu.be/1-vcErOPofQ?t=28s")

Create an hours-minutes-seconds string

Description

Create an hours-minutes-seconds string

Usage

hms(x)

Arguments

x

numeric (number of seconds), or character (i.e. "3m15s")

Value

character string (i.e. "0h3m15s")

See Also

secs()


Accessor methods for iframe

Description

Accessor methods for iframe

Usage

get_iframe(embed, ...)

## Default S3 method:
get_iframe(embed, ...)

## S3 method for class 'vembedr_embed'
get_iframe(embed, ...)

set_iframe(embed, ...)

## Default S3 method:
set_iframe(embed, ...)

## S3 method for class 'vembedr_embed'
set_iframe(embed, iframe, ...)

Arguments

embed

vembedr_embed object, created using an embed() function

...

other args as needed

iframe

shiny.tag with name "iframe", object to be set

Value

get_iframe

shiny.tag with name "iframe", created using htmltools::tags⁠$iframe()⁠

set_iframe

embed object


Parse a URL to determine service and id

Description

This is an internal function, supporting suggest_embed()

Usage

parse_video_url(url)

Arguments

url

character, URL to parse

Value

list with members:

service

character, describes which service is used

id

character, identifier for the video at the service

start_time

character, indicates start time

See Also

suggest_embed

Examples

parse_video_url("https://youtu.be/1-vcErOPofQ?t=28s")

Embed popular video

Description

If you want to experiment with the arguments to embed(), such as query, but do not have a particular video in mind, this function may be useful to you.

Usage

rickroll_vimeo(...)

rickroll_youtube(...)

Arguments

...

arguments (other than id) passed on to embed()

Details

Please note that the YouTube video seems no longer embeddable.

Value

Object with S3 class vembedr_embed.

Examples

  rickroll_vimeo()
  rickroll_youtube()


Get number of seconds given a string

Description

This is a helper function to get the number of seconds.

Usage

secs(x)

Arguments

x

character, describes a time duration, i.e. "3m15s"

Details

This could be useful for composing query parameters for YouTube embeds.

Value

numeric, number of seconds

See Also

embed_youtube(), hms()


Suggest embed-code based on URL

Description

This function is meant to work with URLs from any of the supported services.

Usage

suggest_embed(url)

suggest_embed_pure(url)

Arguments

url

character, URL of web-page for video

Details

suggest_embed

Called for the side-effect of printing suggested code the screen. If you have a recent version of usethis, the code will be copied to your clipboard.

suggest_embed_pure

Returns character string that represents the suggested code.

Value

character, returns the suggested code (suggest_embed returns invisibly)

Examples

## Not run: 
  # not run because it may copy to your clipboard
  suggest_embed("https://youtu.be/1-vcErOPofQ?t=28s")
  suggest_embed("https://www.youtube.com/watch?v=1-vcErOPofQ")

## End(Not run)
  cat(suggest_embed_pure("https://youtu.be/1-vcErOPofQ?t=28"))

Align horizontally

Description

Use this function to specify the horizontal alignment of the iframe within the enclosing div.

Usage

use_align(embed, align = c("left", "right", "center", "justified"))

Arguments

embed

vembedr_embed object, created using an embed() function

align

character, indicates type of alignment

Value

Object with S3 class vembedr_embed.


Make size responsive

Description

If your HTML page includes Twitter Bootstrap 3, you can use this function to make the size of the iframe responsive within the enclosing div.

Usage

use_bs_responsive(embed)

Arguments

embed

vembedr_embed object, created using an embed() function

Value

Object with S3 class vembedr_embed.


Make rounded corners

Description

You can use this function to make rounded corners for the enclosing ⁠</div>⁠.

Usage

use_rounded(embed, radius = NULL)

Arguments

embed

vembedr_embed object, created using an embed() function

radius

numeric or character, css property for the border-radius for the ⁠<iframe/>⁠. Numeric values will be interpreted as number of pixels.

Value

Object with S3 class vembedr_embed.


Specify start time

Description

This function provides you a consistent way to specify the start time, regardless of the service. Please note that Box does not provide a means to specify the start time.

Usage

## S3 method for class 'vembedr_embed_box'
use_start_time(embed, ...)

## S3 method for class 'vembedr_embed_channel9'
use_start_time(embed, start_time, is_paused = TRUE, ...)

## S3 method for class 'vembedr_embed_msstream'
use_start_time(embed, start_time, ...)

## S3 method for class 'vembedr_embed_vimeo'
use_start_time(embed, start_time, ...)

## S3 method for class 'vembedr_embed_youtube'
use_start_time(embed, start_time, ...)

use_start_time(embed, ...)

## Default S3 method:
use_start_time(embed, ...)

Arguments

embed

vembedr_embed object, created using an embed() function

...

generic arguments to pass through

start_time

numeric (seconds), or character (e.g. "3m15s")

is_paused

logical, for "Channel 9" specifies if the video should be paused at this time

Details

The start_time argument can take a variety of formats; these inputs all evaluate to the same value:

Please note that for Vimeo, you can specify a start time, but you can not specify that the video be paused at this time. In other words, it is like "autoplay" is set to TRUE, and you cannot unset it.

Value

Object with S3 class vembedr_embed.

Examples

  rickroll_youtube() %>%
    use_start_time("3m32s")


vembedr S3 Classes

Description

Knowledge of these classes is not needed for day-to-day use. Rather, it is a bookkeeping device used to make it clearer to a developer how to add a new service.

Details

We use S3 classes to distinguish an embed object, and to denote which service it uses. Objects of these classes are created by embed_url() and each service's embed function.

vembedr_embed

There is an additional class attached according to the service:

To support parsing, there is an internal S3 class attached to the URL being processed. It is named according to the service: