I've been attempting to adjust the volume of an audio tag within my Shiny app. While some resources suggest using the "volume" argument directly within the audio tag, I haven't had success in implementing this.
After stumbling upon this page https://www.w3schools.com/jsref/prop_audio_volume.asp as well as this interactive example https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_audio_volume, it seems that Javascript is utilized to modify the volume. However, I'm facing challenges in understanding how to incorporate a Javascript function inside a Shiny application. Any assistance on this matter would be greatly 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)