本文介绍了如何作为触发功能的一部分播放声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我试图用Google工作表创建一种闹钟。任何人都可以想到一种方法,我可以在触发器上播放声音吗? 直到2014年12月发布IFRAME沙箱为止以及随后的几个月的错误修复;)通过Google Apps脚本的Caja消毒的HTML无法支持HTML5音频标签。 查看问题2196 。 以下是一个将音乐播放器嵌入文档边栏的简单示例。 $ b Code.gs var SIDEBAR_TITLE ='侧边栏音乐盒'; / ** *添加一个包含项目的自定义菜单以显示侧边栏和对话框。 * * @param {Object} e一个简单的onOpen触发器的事件参数。 * / 函数onOpen(e){ DocumentApp.getUi() .createAddonMenu() .addItem('Show sidebar','showSidebar') .addToUi(); } / ** *安装加载项时运行;调用onOpen()以确保菜单创建, *任何其他初始化工作立即完成。 * * @param {Object} e一个简单的onInstall触发器的事件参数。 * / onInstall(e){ onOpen(e); } / ** *打开一个侧边栏。侧栏结构在Sidebar.html *项目文件中进行了介绍。 * / 函数showSidebar(){ var ui = HtmlService.createTemplateFromFile('Sidebar') .evaluate() .setSandboxMode(HtmlService.SandboxMode.IFRAME ) .setTitle(SIDEBAR_TITLE); DocumentApp.getUi()。showSidebar(ui); } Sidebar.html <! - 使用模板化HTML打印scriptlet导入常用样式表 - > <?!= HtmlService.createHtmlOutputFromFile('Stylesheet')。getContent(); ?> < div class =sidebar branding-below> < p> 为您的享受带来一点音乐! < / p> < audio id =playercontrols> < source src =http://ukulelehunt.com/wp-content/uploads/2008/11/alohadechocobo.mp3type =audio / mpeg> 您的浏览器不支持音频元素。 < / audio> < div id =sidebar-status>< / div> < / div> < div class =sidebar bottom> < span class =grey branding-text>文档附加音效演示< / span> < / div> b Stylesheet.html <! - 此CSS包适用于Google样式;它应该始终包含在内。 - > < link rel =stylesheethref =https://ssl.gstatic.com/docs/script/css/add-ons.css> < style> #player { width:95%; } < / style> 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? 解决方案 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. Code.gsvar 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<!-- 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>Stylesheet.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> 这篇关于如何作为触发功能的一部分播放声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-22 22:11