Embed sound player in quarto book

I'm converting a website I developed in markdown into a quarto book.

I used to have a sound player, that looked like so:

html_tag_audio <- function(file, type = c("wav")) {
  type <- match.arg(type)
  htmltools::tags$audio(
    controls = "",
    htmltools::tags$source(
      src = file,
      type = glue::glue("audio/{type}", type = type)
    )
  )
}

and then, I would refer to it like so:

html_tag_audio("Sound/mylocalsoundfile.mp3", type = "wav")

image

This doesn't seem to work any longer in quarto. I feel this has something to do with the file/folder structure since I get a notification during rendering saying: /Sound/mylocalsoundfile.mp3 (404: Not Found).

How do I properly include a sound player and link a local file?

It is possible the auto detection is not catching the sound file, and so not move it to _site

Did you try already to manually tell Quarto to consider the mp3 as a resource file ?
Using

project:
  type: website
  resources: 
    - "Sound/mylocalsoundfile.mp3"

I'll check the auto detection code

1 Like

It works now with absolute paths. So it looks like quarto paths are a bit different than regular Rmd. This works:
html_tag_audio("../Sound/mylocalsoundfile.mp3", type = "wav")

It shoudn't be that different. If you are willing too, can you share more about you project structure ?
It seemed to be we are not detecting <audio><source src = > from what I can see in our resource detection, so I wouldn't expect this to work.

Are you sure you fix is working if you deployed the website (meaning only the _site folder ?)

It seems to be by using ../ you are allowing the HTML page to reach outside of _site folder, so if you open your project locally it would find the source Sound directory. But does it work if you run quarto preview or deploy your website ?

I want to confirm if we have an issue here or not.
I have open this issue to track `<source src=>` is not identified for resource detection ยท Issue #5268 ยท quarto-dev/quarto-cli ยท GitHub

Usually with resources used in documents:

  • We are supposed to detect them, at least to our best
  • For those not found, the resources configuration allow to tell quarto which are external resources tรด copy to the _site folder because required by the deployed website

Mmmhh you're correct... This will not work once deployed (and indeed it does not work in preview mode). For some reason, the Sound folder is not being copied inside the _site (in my case it's _book) directory. It's really strange because another multimedia directory (Video) does get copied over (unlike sound, the video is not called via src, but via ![](Video/myvideo.m4v)) My tree structure looks like:

.
โ”œโ”€โ”€ _book
โ”‚   โ”œโ”€โ”€ Figures
โ”‚   โ”œโ”€โ”€ index.html
โ”‚   โ”œโ”€โ”€ search.json
โ”‚   โ”œโ”€โ”€ site_libs
โ”‚   โ”‚   โ”œโ”€โ”€ bootstrap
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ bootstrap-icons.css
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ bootstrap-icons.woff
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ bootstrap.min.css
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ bootstrap.min.js
โ”‚   โ”‚   โ”œโ”€โ”€ clipboard
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ clipboard.min.js
โ”‚   โ”‚   โ”œโ”€โ”€ crosstalk
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ css
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ crosstalk.min.css
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ js
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ crosstalk.js
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ crosstalk.js.map
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ crosstalk.min.js
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ crosstalk.min.js.map
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ scss
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ crosstalk.scss
โ”‚   โ”‚   โ”œโ”€โ”€ datatables-binding
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ datatables.js
โ”‚   โ”‚   โ”œโ”€โ”€ datatables-css
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ datatables-crosstalk.css
โ”‚   โ”‚   โ”œโ”€โ”€ dt-core
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ css
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ jquery.dataTables.extra.css
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ jquery.dataTables.min.css
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ js
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ jquery.dataTables.min.js
โ”‚   โ”‚   โ”œโ”€โ”€ dt-ext-buttons
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ css
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ buttons.dataTables.min.css
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ js
โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ buttons.colVis.min.js
โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ buttons.html5.min.js
โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ buttons.print.min.js
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ dataTables.buttons.min.js
โ”‚   โ”‚   โ”œโ”€โ”€ dt-ext-keytable
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ css
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ keyTable.dataTables.min.css
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ js
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ dataTables.keyTable.min.js
โ”‚   โ”‚   โ”œโ”€โ”€ htmlwidgets
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ htmlwidgets.js
โ”‚   โ”‚   โ”œโ”€โ”€ jquery
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ jquery-3.6.0.js
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ jquery-3.6.0.min.js
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ jquery-3.6.0.min.map
โ”‚   โ”‚   โ”œโ”€โ”€ jszip
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ jszip.min.js
โ”‚   โ”‚   โ”œโ”€โ”€ kePrint
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ kePrint.js
โ”‚   โ”‚   โ”œโ”€โ”€ lightable
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ lightable.css
โ”‚   โ”‚   โ”œโ”€โ”€ pdfmake
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ pdfmake.js
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ vfs_fonts.js
โ”‚   โ”‚   โ”œโ”€โ”€ quarto-html
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ anchor.min.js
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ popper.min.js
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ quarto.js
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ quarto-syntax-highlighting.css
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ tippy.css
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ tippy.umd.min.js
โ”‚   โ”‚   โ”œโ”€โ”€ quarto-nav
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ headroom.min.js
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ quarto-nav.js
โ”‚   โ”‚   โ””โ”€โ”€ quarto-search
โ”‚   โ”‚       โ”œโ”€โ”€ autocomplete.umd.js
โ”‚   โ”‚       โ”œโ”€โ”€ fuse.min.js
โ”‚   โ”‚       โ””โ”€โ”€ quarto-search.js
โ”‚   โ””โ”€โ”€ Video
โ”‚       โ””โ”€โ”€ myvideo.m4v
โ”œโ”€โ”€ Figures
โ”œโ”€โ”€ index.qmd
โ”œโ”€โ”€ _quarto.yml
โ”œโ”€โ”€ Sound
โ”‚   โ””โ”€โ”€ mylocalsoundfile.mp3
โ””โ”€โ”€ Video
    โ””โ”€โ”€ myvideo.m4v


I'm on:
RStudio 2023.05.0-daily+229 "Mountain Hydrangea" Daily (2b33be08175490bb522147451d3ee3e0b7deea12, 2023-04-14) for RHEL 9
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) rstudio/2023.05.0-daily+229 Chrome/110.0.5481.177 Electron/23.1.2 Safari/537.36

I think this work using this syntax because it will be parsed as Markdown and handled for detection, before being outputed to HTML. When you provide HTML code directly in the .qmd (as with htmltools), it is another code where we post process the HTML, and we are missing the tags. See issue.

I modified my YAML to include a manual resource configuration:

project:
  type: book
  resources: 
    - "*.mp3"
    - "*.m4a"

The Sound folder now gets copied over into the _book directory. I can confirm this fixes, but the autoconfiguration somehow misses src specified locations. Many thanks for the help!

Yes this is the issue and we'll fix this - you should follow the issue `<source src=>` is not identified for resource detection ยท Issue #5268 ยท quarto-dev/quarto-cli ยท GitHub for resolution

1 Like

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.