Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / Get sound working in html5??

Author
Message
ICERGB
22
Years of Service
User Offline
Joined: 8th Nov 2002
Location: Canada
Posted: 12th May 2024 17:34

Tried several versions of this code to get sound working in html
can't seem to get it to work



https://boyar.net/testsound6/testsound24c.html


Attachments

Login to view attachments
blink0k
Moderator
11
Years of Service
Recently Online
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 13th May 2024 00:22 Edited at: 13th May 2024 00:25
Does this work for windows?
I think there are ogg specific commands to handle ogg sounds
ICERGB
22
Years of Service
User Offline
Joined: 8th Nov 2002
Location: Canada
Posted: 13th May 2024 07:29
Yes, most of the different ways I've tried including this memblock version works for windows
I added the code in hopes someone would modify it to a working method for html
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 13th May 2024 09:13 Edited at: 13th May 2024 09:37
i see you were expermenting with vsync which you should leave off in HTML as it will mess with the HTML player's internal timer.

meanwhile:

the only difference that i experience with this code in HTML is that when i move to another tab, i stop hearing the looping ogg while, with VSync, 0, it continues to be audible even when i leave the tab. try it out HERE for yourself?

otherwise, you'll find worse experiences when using vsync,1 in HTML as alluded to HERE.

meanwhile, note that the project is set for the user to manually launch via Run Project. now, i'm no web guru but as i understand it, some browsers/settings wont execute some stuff without the user explicitly allowing it via similar user "click"/allow notions.

your HTML plays no sound for me so i dont know if it's my browser(Edge)/settings or something to do with your domain (that mattering rings a bell) but i know that my project (and all of my games on itch which most-all use .ogg) play ogg sounds and music fine for me (and i've never had someone tell me that mine didnt work for them).

perhaps Phaelax or some other web-savy guru can explain better while i only know what works or does not from personal trial and error or someone like them explaining it to me (which i tend to forget the "why" and just "do" or "do not" to make it work ).

btw, there's absolutely no need for the memblock stuff. i will say that some ogg settings may/will have issues under HTML (and maybe all AppGameKit?). my tried and true settings are 1411 kbps @ 44,100 kHz. AKA, Audacity's ogg quality 8 setting on export.

hope this helps.

ps, i just re-read your code and saw

still, hopefully something in the above helps.
James H
17
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 13th May 2024 14:11
I have no real input here, but I am curious to know what renderer gets used? I ask as i found vsync -1 turns off vsync for vulkan because vsync 0 only works for ogl. Obviously thats a straight forward test, but I am curious as to which renderer if any(of the aforementioned ones) gets used?
Win 10 Home 64, Intel(R) Core(TM) i5-10300H, 8GB DDR4, NVidia GeForce GTX 1650 4GB GDDR6
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th May 2024 04:08
Sounds works for me. I can also load the page where sound doesn't work. We really should sticky an explanation for this, it comes up often enough.

It's a browser security thing. If you look at your browser's dev console you'll see a message like "An AudioContext was prevented from starting automatically. It must be created or resumed after a user gesture on the page".
Essentially what's happening is AppGameKit cannot access the audio library necessary to play sounds as access is restricted until there has been some kind of user interaction on the page. Unfortunately, once your game has loaded the AppGameKit library makes no more attempts to load the sound library needed. You need to make sure access is allowed BEFORE the canvas loads your game. Quick and dirty method, click somewhere on the page (i believe it has to be outside of the canvas) as soon as the page loads but before the javascript library loads. A better solution, do what itch.io does and add a play button overtop of the game. Prevent the game from loading until the user clicks the button. A gesture from another page might be ok, I forget exactly, but it would have to be from the same server. That's why a hotlink from TGC to your page doesn't work or loading the page directly rather than navigating to it from elsewhere on your website.

You can view my page source in this example to see how I added a play button, but essentially you're just taking the existing javascript and putting it into a function and calling that on button click. (You'll see a lot of CSS but that's only cause I got fancy with my button)
https://zimnox.com/games/asteroids/
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda
Pixel-Perfect Collision

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

blink0k
Moderator
11
Years of Service
Recently Online
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 14th May 2024 05:10
Added this thread to Resource directory
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 14th May 2024 06:38 Edited at: 14th May 2024 07:17
the info really needs to go HERE, not the Resource Directory which already has a link to a collection of HTML issues/info/work-arounds
ICERGB
22
Years of Service
User Offline
Joined: 8th Nov 2002
Location: Canada
Posted: 14th May 2024 13:00 Edited at: 15th May 2024 11:15
I tried vsync because there was mention of it in another thread; and also memblocks because it was mentioned in another thread about "to small" ogg files

I will remove the vsync and memblock commands and see if I can get that javascript play button to work. and let you know! tks for the info!


Wow that javascript is fullmealdeal. I'll try to break it down.
ICERGB
22
Years of Service
User Offline
Joined: 8th Nov 2002
Location: Canada
Posted: 17th May 2024 09:17 Edited at: 19th May 2024 12:57
OK, so i took out the nice javascript effects so as not to step on your toes Phaelax

This can be named index.html, it will pick up the agkplayer file in the folder




and my code cleaned up a bit (to be used with images and sound attached on the first post)


Note: this also sets it to full screen automatically upon start.
Might have to revisit this full screen thing

and thanks VirtualNomad

Yay There be sound here!
https://boyar.net/sound8/



Edit : Is there an easy way to fix the AGKplayer loading Error: TypeError: document.getElementById(...) is Null


Edit: this may work to cut out the error, not sure if it cuts out the other errors:
Javascript change:

Login to post a reply

Server time is: 2024-11-17 22:32:17
Your offset time is: 2024-11-17 22:32:17