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 |
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
YouTube
Vimeo
Box
Microsoft Stream
It provides two categories of functions:
-
embed functions, to specify a video to embed: e.g.
embed_youtube()
,embed_url()
-
use functions, to modify the embedding: e.g.
use_start_time()
,use_rounded()
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 |
|
custom_domain |
|
width |
|
height |
|
ratio |
|
frameborder |
|
allowfullscreen |
|
query |
|
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
- Vimeo
- Box
https://developer.box.com/guides/embed/box-embed/#programmatically
- Microsoft Stream
Value
Object with S3 class vembedr_embed
.
See Also
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 |
|
Details
This function calls suggest_embed()
then parses and evaluates the code.
Value
Object with S3 class vembedr_embed
.
See Also
Examples
embed_url("https://youtu.be/1-vcErOPofQ?t=28s")
Embed video from Microsoft Channel 9
Description
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 |
|
width |
|
height |
|
ratio |
|
frameborder |
|
allowfullscreen |
|
... |
arguments (other than |
Value
Object with S3 class vembedr_embed
.
Determine service based on URL
Description
Determine service based on URL
Usage
get_service(url)
Arguments
url |
|
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
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 |
|
... |
other args as needed |
iframe |
|
Value
- get_iframe
shiny.tag
withname
"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 |
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
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 |
|
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 |
|
align |
|
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 |
|
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 |
|
radius |
|
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 |
|
... |
generic arguments to pass through |
start_time |
|
is_paused |
|
Details
The start_time
argument can take a variety of formats; these inputs
all evaluate to the same value:
"0h1m0s"
,"0h01m00s"
,"0h1m"
"1m0s"
,"1m"
"60s"
,60
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
base class for all services
HTML
<div>
contains the embed code
There is an additional class attached according to the service:
-
vembedr_embed_youtube
-
vembedr_embed_youtube_short
-
vembedr_embed_vimeo
-
vembedr_embed_channel9
-
vembedr_embed_box
-
vembedr_embed_msstream
To support parsing, there is an internal S3 class attached to the URL being processed. It is named according to the service:
-
vembedr_url_youtube
-
vembedr_url_youtube_short
-
vembedr_url_vimeo
-
vembedr_url_channel9
-
vembedr_url_box
-
vembedr_url_msstream