Embedding multimedia files in R Markdown HTML documents

Update: I have improved the functions in this post and turned them into an R package. The source code and installation instructions are available here. I am currently writing a comprehensive educational resource of all things music called The Musican’s Compendium using bookdown, an R package that can generate print-ready books and ebooks from R Markdown documents.