Title: | 'Shiny' Extension of 'video.js' |
---|---|
Description: | Video interactivity within 'shiny' applications using 'video.js'. Enables the status of the video to be sent from the UI to the server, and allows events such as playing and pausing the video to be triggered from the server. |
Authors: | Ashley Baldry [aut, cre], Steve Heffernan [aut] (Creator of video.js) |
Maintainer: | Ashley Baldry <[email protected]> |
License: | Apache License (>= 2) |
Version: | 0.1.1 |
Built: | 2025-01-27 03:40:15 UTC |
Source: | https://github.com/ashbaldry/video |
Enabling languages (other than English) to appear as tooltips and other buttons in video.js widgets.
addVideoLanguages(video, languages) availableLanguages()
addVideoLanguages(video, languages) availableLanguages()
video |
A |
languages |
A character vector of languages to support in the video.
See |
If any languages are missing, you can add a separate script in the head of the application that will apply the language to all videos. See https://videojs.com/guides/languages/ for more details
An updated video
with extra language support
video <- video("https://vjs.zencdn.net/v/oceans.mp4") video <- addVideoLanguages(video, c("es", "fr", "de")) if (interactive()) { library(shiny) ui <- fluidPage(lang = "fr", video) server <- function(input, output) {} shinyApp(ui, server) }
video <- video("https://vjs.zencdn.net/v/oceans.mp4") video <- addVideoLanguages(video, c("es", "fr", "de")) if (interactive()) { library(shiny) ui <- fluidPage(lang = "fr", video) server <- function(input, output) {} shinyApp(ui, server) }
If no type is provided when generating a video.js video, then the format needs to be guessed. Included in the package is a dataset of the default type of each video. This will give the default type of each file provided.
guessVideoFormat(files)
guessVideoFormat(files)
files |
A vector of URL paths (relative or absolute) to videos |
A vector the same length as files
of the video types.
guessVideoFormat("video.mp4")
guessVideoFormat("video.mp4")
video.js contains the ability to include tracks with the video, including subtitles,
captions and descriptions. includeTextTracks
will make sure that they are
included on load, and find the defaults to embed with the video.
includeTextTracks( video, files, language = "en", label = "English", kind = "subtitles", default = FALSE )
includeTextTracks( video, files, language = "en", label = "English", kind = "subtitles", default = FALSE )
video |
A |
files |
A vector of WebVTT files that contain "cues" of when text should appear, hide and what text to display |
language |
The valid BCP 47 code for the language of the text track, e.g. "en" for English or "es" for Spanish. |
label |
Short descriptive text for the track that will used in the user interface. For example, in a menu for selecting a captions language. |
kind |
An optional vector to match the type of text tracks in
|
default |
The boolean |
All vectors must either be the same length as files
or of length 1. In the latter,
they will be applied to all files
supplied.
An updated video
with text tracks included
vid <- video("https://vjs.zencdn.net/v/oceans.mp4") includeTextTracks(vid, "url/to/subtitles.vtt")
vid <- video("https://vjs.zencdn.net/v/oceans.mp4") includeTextTracks(vid, "url/to/subtitles.vtt")
{video}
Example ApplicationsRun {video}
Example Applications
runVideoExample(example = "basic", display.mode = "showcase", ...) availableVideoExamples()
runVideoExample(example = "basic", display.mode = "showcase", ...) availableVideoExamples()
example |
Name of the example to load. Current examples include:
|
display.mode |
The mode in which to display the application. By default set to |
... |
Optional arguments to send to |
This function does not return a value; interrupt R to stop the application (usually by pressing Ctrl+C or Esc).
availableVideoExamples() if (interactive()) { library(shiny) library(video) runVideoExample("server") }
availableVideoExamples() if (interactive()) { library(shiny) library(video) runVideoExample("server") }
A video player that can be embedded in HTML pages.
video( files, format = NULL, options = list(), seek_ping_rate = 1000, width = NULL, height = NULL, elementId = NULL )
video( files, format = NULL, options = list(), seek_ping_rate = 1000, width = NULL, height = NULL, elementId = NULL )
files |
A vector of file paths or URLs pointing |
format |
An optional list of formats of |
options |
A named list of options to apply to the video. List of available options available in Details |
seek_ping_rate |
Number of milliseconds between each update of 'input${id}_seek' while playing. Default is set to 1000. If set to 0, then 'input${id}_seek' will not exist. |
width , height
|
Must be a valid CSS unit (like |
elementId |
HTML id tag to be given to the video player element |
Here are some more common options to implement:
Whether or not the video will autoplay on load. NOTE: There is not a guarantee autoplay will work in the browser.
FALSE
Default: Video won't autoplay
TRUE
Video will use browser's autoplay
"muted"
Will mute the video and then manually call play()
on loadstart()
. Likely to work on browsers
"play"
Will call play()
on loadstart()
, similar to browser autoplay
Determines whether or not the player has controls that the user can interact with. By default
video
will include controls even if not specified in the options.
A URL to an image that displays before the video begins playing. This is often a frame of the video or a custom title screen.
For a full list of available options check out https://videojs.com/guides/options/
A shiny.tag containing all of the required options for a videojs
JS object to be initialised in a shiny application.
On the server side there will be up to four additional objects available as inputs:
{id}_playing
A logical value as to whether or not the video
is playing audio
{id}_seek
(If seek_ping_rate > 0
) the current time of the track loaded
{id}_duration
The duration of the track loaded
if (interactive()) { library(shiny) ui <- fluidPage( title = "howler.js Player", video("https://vjs.zencdn.net/v/oceans.mp4") ) server <- function(input, output) { } runShiny(ui, server) }
if (interactive()) { library(shiny) ui <- fluidPage( title = "howler.js Player", video("https://vjs.zencdn.net/v/oceans.mp4") ) server <- function(input, output) { } runShiny(ui, server) }
Change the state of the video player from the server.
playVideo
, pauseVideo
and stopVideo
will all be applied to the current video.
changeVideo
will update the track to the URL or file specified.
updatePlaybackRate
will change how fast the video is playing.
playVideo(id, session = getDefaultReactiveDomain()) pauseVideo(id, session = getDefaultReactiveDomain()) stopVideo(id, session = getDefaultReactiveDomain()) seekVideo(id, seek, session = getDefaultReactiveDomain()) changeVideo(id, files, format = NULL, session = getDefaultReactiveDomain()) updatePlaybackRate(id, playrate = 1, session = getDefaultReactiveDomain())
playVideo(id, session = getDefaultReactiveDomain()) pauseVideo(id, session = getDefaultReactiveDomain()) stopVideo(id, session = getDefaultReactiveDomain()) seekVideo(id, seek, session = getDefaultReactiveDomain()) changeVideo(id, files, format = NULL, session = getDefaultReactiveDomain()) updatePlaybackRate(id, playrate = 1, session = getDefaultReactiveDomain())
id |
ID of the |
session |
Shiny session |
seek |
Time (in seconds) to set the position of the track |
files |
A vector of file paths or URLs pointing |
format |
An optional list of formats of |
playrate |
Speed of playback of the video. Default is set to 1 (normal speed) |
Updates the the state of the specified video
in the shiny application.
if (interactive()) { library(shiny) ui <- fluidPage( title = "howler.js Player", video( "https://vjs.zencdn.net/v/oceans.mp4", elementId = "video" ), actionButton("pause", "Pause Video") ) server <- function(input, output) { observeEvent(input$pause, pauseVideo("video")) } runShiny(ui, server) }
if (interactive()) { library(shiny) ui <- fluidPage( title = "howler.js Player", video( "https://vjs.zencdn.net/v/oceans.mp4", elementId = "video" ), actionButton("pause", "Pause Video") ) server <- function(input, output) { observeEvent(input$pause, pauseVideo("video")) } runShiny(ui, server) }
Output and render functions for using video within Shiny applications and interactive Rmd documents.
videoOutput(outputId, width = "100%", height = "400px") renderVideo(expr, env = parent.frame(), quoted = FALSE)
videoOutput(outputId, width = "100%", height = "400px") renderVideo(expr, env = parent.frame(), quoted = FALSE)
outputId |
output variable to read from |
width , height
|
Must be a valid CSS unit (like |
expr |
An expression that generates a video |
env |
The environment in which to evaluate |
quoted |
Is |
An output or render function that enables the use of the widget within Shiny applications.