1
votes

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

1

1 Answers

1
votes

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();"/>