skip to Main Content

After several days of research, I am appealing to your help because I found similar problems to mine but no solution (at least I managed to understand them).

Via a programmed google script, I want to autoplay a youtube video/audio or a video on google drive in an iframe from google sheet every hour.
For more context, it is about launching a count that is displayed in a Google Sheet cell then when the count reaches 0, I want an audio to automatically trigger to signal the end of the count.

You know that it is not possible to display an iframe outside the user context via SpreadsheetApp.getUi() when the script is autonomous.

Would you have a simple solution for me?

Thanks in advance for your help.

The solution can be used to display an HTML page, but I’m new to this part, and I don’t know how to do it.

2

Answers


  1. Chosen as BEST ANSWER

    Thanks a lot, I'm starting, sorry. I created Code.gs and Index.html files in GAS but I don't know what to do with them.


  2. Did you try to write an HTML file in your Google Apps Script project that contains the iframe for your video or audio?
    and also try to use GAS to serve this HTML as a web page.

    something like this

    function doGet() {
      return HtmlService.createHtmlOutputFromFile('Index'); //file
    }
    
    function getCountdownValue() {
      var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
      return sheet.getRange('A1').getValue();  // I've added this cell as f.e
    }
    

    and for the HTML like this (this is only an example of how I think it can work)

    <!DOCTYPE html>
    <html>
      <head>
        <script>
          setInterval(checkCountdown, 60000); // it can be any 
    
          function checkCountdown() {
           google.script.run.withSuccessHandler(function(countdownValue) {
              if (countdownValue === 0) {
                document.getElementById('videoFrame').style.display = 'block';
              }
            }).getCountdownValue();
          }
        </script>
      </head>
      <body>
        <iframe 
             id="videoFrame" 
             src="https://www.youtube.com/embed/VIDEO_ID?autoplay=1" 
             frameborder="0" 
             allow="autoplay; encrypted-media" 
             allowfullscreen 
             style="display:none;">
       </iframe>
      </body>
    </html>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search