1

I have a Google Sheet with URLs of my audio Files from my own Google Drive Folder. I realised a Script from labnol.org (thanks to @Amit Agarwal) to Open a Mini Player in an iframe.

Is it possible to autoplay the file, if the mini Player is opend?

The Apps script is from Here: 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');
};
Rubén
  • 34,714
  • 9
  • 70
  • 166

1 Answers1

1

Use autoplay attribute of audio element:

/**
 * 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)
     ,"")
)()
TheMaster
  • 45,448
  • 6
  • 62
  • 85