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

后端 未结 1 874
暖寄归人
暖寄归人 2021-01-14 08:34

I am trying to build a type of alarm clock with a Google sheet. Can anyone think of a way I can play a sound on a trigger?

1条回答
  •  粉色の甜心
    2021-01-14 08:55

    Until the release of IFRAME sandboxes in December 2014 (and the subsequent months of bug fixes ;) it was not possible to support HTML5 audio tags through Google Apps Script's Caja-sanitized HTML. See issue 2196.

    Here's a simple example that embeds a music player into a document sidebar.

    screenshot

    Code.gs

    var SIDEBAR_TITLE = 'Sidebar Musicbox';
    
    /**
     * Adds a custom menu with items to show the sidebar and dialog.
     *
     * @param {Object} e The event parameter for a simple onOpen trigger.
     */
    function onOpen(e) {
      DocumentApp.getUi()
          .createAddonMenu()
          .addItem('Show sidebar', 'showSidebar')
          .addToUi();
    }
    
    /**
     * Runs when the add-on is installed; calls onOpen() to ensure menu creation and
     * any other initializion work is done immediately.
     *
     * @param {Object} e The event parameter for a simple onInstall trigger.
     */
    function onInstall(e) {
      onOpen(e);
    }
    
    /**
     * Opens a sidebar. The sidebar structure is described in the Sidebar.html
     * project file.
     */
    function showSidebar() {
      var ui = HtmlService.createTemplateFromFile('Sidebar')
          .evaluate()
          .setSandboxMode(HtmlService.SandboxMode.IFRAME)
          .setTitle(SIDEBAR_TITLE);
      DocumentApp.getUi().showSidebar(ui);
    }
    

    Sidebar.html

    
    
    
    
    
    
    

    Stylesheet.html

    
    
    
    
    

    0 讨论(0)
提交回复
热议问题