How to stop the playing of a sound in R Shiny

When playing a sound I would like to have the possibility to stop this with another button. Or when pressing the play button again, the playing of the sound should stop, and then played from the beginning.

I struggled implementing this in R Shiny using shinyjs but did not succeed. This is my code:

library(shiny)
library(shinyjs)

ui <- fluidPage(
  useShinyjs(),

  shiny::actionButton('sound'  ,'Play sound'),
  shiny::actionButton('stopper','Stop sound')
)

server <- function(input, output) {
  observeEvent(input$sound, 
  {
    shinyjs::runjs("snd.pause();")
    shinyjs::runjs("var snd = new Audio('https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3'); snd.play();")
  })

  observeEvent(input$stopper, 
  {
    shinyjs::runjs("snd.pause();")
  })
}

shinyApp(ui = ui, server = server)

The code is inspired by the code at: https://community.rstudio.com/t/how-to-stop-audio-with-shinyjs/122650.

So the idea is that after pressing the ‘Play sound’ button the play can be stopped prematurely with the ‘Stop sound’ button, or when prematurely pressing the ‘Play sound’ button the playing should stop and subsequently start from the beginning.

Is this somehow possible?