inkle / inky

An editor for ink: inkle's narrative scripting language
http://www.inklestudios.com/ink
2.42k stars 296 forks source link

Using JavaScript for Audio Fades with #Tags #504

Closed Inkynoob739 closed 5 months ago

Inkynoob739 commented 8 months ago

Hello! I know the basics about inky but I am not a genius when it comes to JavaScript. I used some different forums and stuff a while back to get a working play and pause sound system inside the inky html. I was wondering if there was anyway to make the audio fade out when a certain tag is called within the Ink story, like using .setVolume() or something of the likeness. This was the code I was using:

else if( splitTag && splitTag.property == "FADE" ) { this.audioLoop.setVolume = 0.5; // set volume to 50% }

Every time the tag was called though, nothing happened. I read through some forums, and was wondering if I had to use something like jQuery or something else to help run the HTML. Again, I know very little about JavaScript so any help would be great. Perhaps I needed to use something else, I don't know. Please help!

Below is the code I used for starting and stopping audio tracks:

else if( splitTag && splitTag.property == "AUDIOLOOP" ) { if('audioLoop' in this) { this.audioLoop.pause(); this.audioLoop.removeAttribute('src'); this.audioLoop.load(); } this.audioLoop = new Audio(splitTag.val); this.audioLoop.play(); this.audioLoop.loop = true; }

FrameMuse commented 5 months ago

This won't work this.audioLoop.setVolume = 0.5;, there is no such a thing as setVolume, you should do this.audioLoop.volume = 0.5. https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/volume

@Inkynoob739 Please, close the issue if it's solved.

Inkynoob739 commented 5 months ago

Thanks for responding to this. I had opened a discussion in inkle/ink and found an answer there: [https://github.com/inkle/ink/discussions/897]

Again, thanks for responding, and sorry for not closing the issue.