Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play tags$audio file until the end in Shiny App R

Tags:

html

r

audio

shiny

I have a shiny app that is kind of like a Piano keyboard. I press a button and it plays a sound. It looks something like this:

if (input$down[1] == 65){
tags$audio(src = "Low_C.wav", type = "audio/wav", autoplay = NA, controls = FALSE)}
else if(input$down[1] == 87){
tags$audio(src = "Low_C_Sharp.wav", type = "audio/wav", autoplay = NA, controls = NA)}

Every time I press 65 (letter a on my keyboard), it plays low c. But when I press 87 (letter w) it stops playing low c and plays low c sharp.

I want to be able to press 65, so that it plays low c until the end of "Low_C.wav" even if I press 87 before then end, then it should play them together.

like image 367
Nikola Ivanovic Avatar asked Oct 21 '25 16:10

Nikola Ivanovic


1 Answers

Okay, so I figured it out and thought I'd share.

Instead of tags$audio, I used

tags$script('new Audio ("Low_C.wav").play()')

and

tags$script('new Audio ("Low_C_Sharp.wav").play()')

It can play multiple sounds at once this way.

like image 172
Nikola Ivanovic Avatar answered Oct 23 '25 06:10

Nikola Ivanovic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!