Last active
May 3, 2020 22:28
-
-
Save takahirohonda/0ab032dcff9b7b0d1c2a4552dc4d403b to your computer and use it in GitHub Desktop.
ring-bell-with-html-audio-example.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { BellImage } from '../assets/Bell-Image'; | |
// This is the base64 encoded sound. The file looks like: | |
// export const BellSound = '//sdfagergr......' | |
import { BellSound } from '../assets/Bell-Sound'; | |
export class Bell { | |
private readonly _host: HTMLElement; | |
constructor(host: HTMLElement) { | |
this._host = host; | |
} | |
render(): void { | |
this._host.insertAdjacentHTML('beforeend', | |
`<div class="ring-bell-wgt-img-container">${BellImage}</div> | |
<audio id="ring-bell-wgt-audio" controls style="display:none"> | |
<source | |
src="data:audio/mpeg;base64,${BellSound}" | |
type="audio/mpeg"> | |
</audio> | |
`); | |
} | |
ringBell(): void { | |
const audioElem = this._host | |
.querySelector('#ring-bell-wgt-audio') as HTMLAudioElement; | |
audioElem.load(); | |
audioElem.play(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment