1

The post below outlines how to set up the sidebar which can play a sound on Google Sheets

How can I play a sound as part of a triggered function

It works, sidebar opens up with the sheet and makes the sound when I press the play button.

However I haven't been able to trigger a play action from a function on a script.

I need a trigger function like this one -

function playme() {
('#player.play')
}

Update (Solved) -

There's no need to use IFRAME sandbox for my requirement, complicates the matters unnecessarily.

The post below provides an elegant solution (without the use of IFRAME), where the sidebar script runs a simple poll for the selected range and triggers a sound if there's change compared to previous poll values.

Google Script: Play Sound when a specific cell change the Value

Burak
  • 23
  • 1
  • 6

1 Answers1

1

You need to get the player object using document.getElementById, then you can call the functions to control the player.

<script>
  function play() {
    var player = document.getElementById("player");

    player.play();
  }
</script>

To get the function to run you need to call the play() function. An easy way to do this would be to add a button to the html part of the code:

<input type="button" value="Play" onclick="play();"/>   
Aidan
  • 1,550
  • 1
  • 13
  • 20
  • thanks, I've added document.getElementById part but still unable to trigger a play action. Something is wrong - updated the post with the entire code. – Burak May 16 '18 at 15:58
  • Added part, a button popped up on the sidebar, but it doesn't do anything when I click. I think "player.play();" in "function play()" doesn't work. – Burak May 16 '18 at 17:00
  • Works for me so you need to debug: Is the event is being triggered? Does document.getElementById() return null? Is there an error in the console when player.play() is called? If you right-click on the sidebar and choose "inspect element" you will be brought to the developer tools - there is a lot going on there, start with the console window and see if there are any obvious error messages. – Aidan May 17 '18 at 10:21
  • How do you trigger the play from the app script not a button that the user has to click – aNewb Nov 26 '20 at 00:57