I'm trying to change the volume on my audio tag in my Shiny app. Some sites that I've looked into show that you can directly use the "volume" argument within the audio tag to set it but I have not been able to reproduce it.
This site https://www.w3schools.com/jsref/prop_audio_volume.asp and https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_audio_volume that I found uses Javascript to update the volume but I cannot figure out how to call a function created in Javascript in Shiny. Any help is much appreciated.
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
tags$audio(id = "myAudio", controls = NA, autoplay = NA, tags$source(src="aud.mpeg")),
br(),
actionButton("mybutton", "Submit"),
tags$script('
var x = document.getElementById("myAudio").onclick
function setHalfVolume() {
x.volume = 0.2;
};
')
)
server <- function(input, output) {
observeEvent(input$mybutton, {
setHalfVolume()
})
}
shinyApp(ui = ui, server = server)