Playing audio via tags in browser embedded mode (via Javascript)
- Dominant language
- C#
- Stars
- 4.9k
- Forks
- 540
- PR merge metrics
- No merged PRs in 30d
Description
Hello, I'm experimenting with what can be done for a browser text-game with ink and so far the one thing I'm missing is ability to add some audio.
I tried a quick hack with modifying main.js but it only got the game to freeze.
Here's the basic function (copy-pasted from W3C so I'm pretty sure it should be OK)
```
function sound(src) {
this.sound = document.createElement("audio");
this.sound.src = src;
this.sound.setAttribute("preload", "auto");
this.sound.setAttribute("controls", "none");
this.sound.style.display = "none";
document.body.appendChild(this.sound);
this.play = function(){
this.sound.play();
}
this.stop = function(){
this.sound.pause();
}
}
```
And here the tag's usage (put it right next to IMAGE and CLASS tags of course)
```
if (splitTag && splitTag.property == "SOUND" ) {
var sound = new sound(splitTag.val);
sound.play();
}
```
I am pretty sure that it hangs on `new sound()`, I 'debugged' this with adding sound path as a paragraph and it doesn't get beyond that point.
Is there a better way to do it? Or any tips on how to get this JS hack to work? Btw, it could be very nice default addition to main.js I believe!
PS I'm pretty new to this tech, sorry if I'm missing something obvious.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.