gpt4 book ai didi

google-apps-script - 如何在触发功能中播放声音

转载 作者:行者123 更新时间:2023-12-01 09:56:07 24 4
gpt4 key购买 nike

我正在尝试使用 Google 表格构建一种闹钟。任何人都可以想出一种可以在触发器上播放声音的方法吗?

最佳答案

直到 2014 年 12 月发布 IFRAME 沙盒(以及随后几个月的错误修复;)之前,无法通过 Google Apps Script 的 Caja-sanitized HTML 支持 HTML5 音频标签。 See issue 2196 .

这是一个将音乐播放器嵌入文档侧边栏的简单示例。

screenshot

代码.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);
}

边栏.html

<!-- Use a templated HTML printing scriptlet to import common stylesheet -->
<?!= HtmlService.createHtmlOutputFromFile('Stylesheet').getContent(); ?>

<div class="sidebar branding-below">
<p>
A little music for your enjoyment!
</p>
<audio id="player" controls>
<source src="http://ukulelehunt.com/wp-content/uploads/2008/11/alohadechocobo.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<div id="sidebar-status"></div>
</div>

<div class="sidebar bottom">
<span class="gray branding-text">Docs Add-on Sound Demo</span>
</div>

样式表.html

<!-- This CSS package applies Google styling; it should always be included. -->
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons.css">

<style>
#player {
width: 95%;
}
</style>

关于google-apps-script - 如何在触发功能中播放声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26787307/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com