在 Google 表格中使用 Apps 脚本自动播放 mp3 文件

问题描述 投票:0回答:1

我有一个 Google 表格,其中包含我自己的 Google 云端硬盘文件夹中的音频文件的 URL。我从labnol.org感谢@Amit Agarwal)实现了一个脚本,用于在 iframe 中打开迷你播放器。

如果迷你播放器打开,是否可以自动播放文件?

Apps 脚本来自此处:https://www.labnol.org/play-mp3-google-sheets-220504:

const openAudioPlayer = () => {
  const cell = SpreadsheetApp.getActiveSheet().getActiveCell().getValue();
  const html = `<iframe src="${cell}" width="480" height="180" frameborder="0" scrolling="no"></iframe>`;
  const dialog = HtmlService.createHtmlOutput(html).setTitle('Play').setWidth(500).setHeight(200);
  SpreadsheetApp.getUi().showModelessDialog(dialog, 'Play Audio');
};
javascript google-apps-script google-sheets audio autoplay
1个回答
2
投票

使用

autoplay 元素的 
audio
属性
:

/**
 * Plays audio from src specified in active cell
 * @OnlyCurrentDoc
 * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio
 * @link https://stackoverflow.com/a/73228860/
 */
(()=>SpreadsheetApp.getUi().showModelessDialog(
      HtmlService.createHtmlOutput(`<audio src="${
       SpreadsheetApp.getActiveRange().getValue()
      }" autoplay>`).setWidth(1).setHeight(1)
     ,"🔊")
)()
© www.soinside.com 2019 - 2024. All rights reserved.