vembedr icon indicating copy to clipboard operation
vembedr copied to clipboard

embed_youtube(width = 'auto', height = 'auto')

Open englianhu opened this issue 2 years ago • 0 comments

I think our default should be to embed using defaults:

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

For the <iframe/> itself, we need the width and height, but we can calculate this if we have two of the three values - if we have all three, we ignore ratio.

This begs an internal function:

get_width_height <- function(width, height, ratio) {

  # validate ratio

  if (is.null(width) && is.null(height)) {
    stop() # no can do
  }

  if (is.null(width)) {
    width <- round(height * ratio)
  }

  if (is.null(height)) {
    height <- round(width / ratio)
  }

  list(width = width, height = height)
}

Source : https://github.com/ijlyttle/vembedr/issues/33#issue-419261628

>args(embed_youtube)
function (id, width = NULL, height = 300, ratio = c("16by9", 
    "4by3"), frameborder = 0, allowfullscreen = TRUE, query = NULL) 
NULL
<environment: R_GlobalEnv>
>
>lib('vembedr'); vlist <- c('C1hrbXlreY4', 'O8qPQNz8Q8Y', '3pnXMEusQCY', 'E9_eAm2tTns', 'budv9DSiuko')
> 
> embed_youtube(vlist[1], height='auto')
Error in height * ratio : 二进列运算符中有非数值参数
> 
> embed_youtube(vlist[1], width='auto')
错误: width is not a number (a length one numeric vector).
> 
> embed_youtube(vlist[1], width='auto', height='auto')
错误: width is not a number (a length one numeric vector).

Raised Issue for Enhancement

  1. How to make the embed video auto-resize when the browser screen width/height resize.

  2. With regards rmarkdown, let say embed multiple videos by html as below, there can be ordered in one line...

<iframe width="560" height="315" src="https://www.youtube.com/embed/O8qPQNz8Q8Y" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> <iframe width="560" height="315" src="https://www.youtube.com/embed/O8qPQNz8Q8Y" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

but use vembedr on rmarkdown...

Screenshot_4

englianhu avatar Mar 21 '22 05:03 englianhu