Skip to content

Instantly share code, notes, and snippets.

@freaktechnik
Created July 20, 2020 22:18
Show Gist options
  • Save freaktechnik/84a186e1f701aaea0f68e2b3617a4d5c to your computer and use it in GitHub Desktop.
Save freaktechnik/84a186e1f701aaea0f68e2b3617a4d5c to your computer and use it in GitHub Desktop.
document.addEventListener('DOMContentLoaded', () => {
document.getElementById('play').addEventListener('click', async () => {
const player = new Audio();
document.body.append(player);
player.src = browser.runtime.getURL('pop.flac');
document.getElementById('output').value = 'playing';
try {
await player.play();
document.getElementById('output').value = 'played!';
} catch(error) {
document.getElementById('output').value = error;
}
});
document.getElementById('playRemote').addEventListener('click', async () => {
const player = new Audio();
document.body.append(player);
player.src = 'https://lab.humanoids.be/pop.flac';
document.getElementById('output').value = 'playing';
try {
await player.play();
document.getElementById('output').value = 'played!';
} catch(error) {
document.getElementById('output').value = error;
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment