Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Audio troubles in HTML builds
Started by sporkfin Sep 05 2019 08:33 AM

- - - - -
15 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 825 posts
  • Corona SDK

Large sound files (like background music) don't play when the HTML build loads, however, smaller files like sound effects will play.

 

I have found that if I put a touch listener on an object (button) and use that to start the music, it works. I have wait a few seconds before pressing the button because, I presume, the audio is still loading. If I press the button before the sound is loaded, nothing happens.  

 

My original thought was that if I used

audio.loadSound

instead of

audio.loadStream

it would increase the load time but allow the soundtrack to play.  I didn't make a difference.  Neither one worked.

 

My second thought was to use a delay to trigger the sound but this didn't work with delays triggered by timers or transition-based delays.

 

I'm hoping one of you will have my third thought or maybe you first or second thought solved this already.  I'm open to ideas - thanks!



[TOPIC: post.html]
#2

ponywolf

[GLOBAL: userInfoPane.html]
ponywolf
  • Contributor

  • 274 posts
  • Corona SDK

I'm playing a 5.4MB MP3 file on this game with the latest daily build... Can you hear that music?

 

https://ponywolf.itch.io/roguejack

 

Here's what I'm using to play both sound and music...

 

https://github.com/ponywolf/ponyblitz/blob/master/com/ponywolf/ponysound.lua

 

Hope that helps!



[TOPIC: post.html]
#3

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 825 posts
  • Corona SDK

Thanks @ponywolf

 

Cool game as per usual!  Your algorithm likes me - I got three black jacks in row!

 

I just discovered that the audio for my apps plays fine with Firefox but not with Chrome or Safari.  Interestingly, I get the same results with roguejack.

 

I'm testing on

MacOS Mojave (10.14.5)

Corona 2019.3519

 

FireFox - music plays when game loads

 

Chrome - I have to toggle the sound on and off (presumably, after the sound loads) to get the music to start.  Once the music plays, when I reload the page it plays automatically.

 

Safari -  I have to toggle the sound to get it to work - no automatic reload fix.

FYI, I get this alert several times but I can click through to play - "Error: Failed to mount IDBFS

 SecurityError: IDBFactory.open() called in an invalid security context")
 
The fact that the error seems to be browser dependent suggests that there could be a solution.
Are you able to get roguejack sound to play on all browsers?


[TOPIC: post.html]
#4

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 825 posts
  • Corona SDK

OK, I've found another possible clue. 

 

In Firefox, the music plays no matter what - even if click to another program, the music keeps playing so it is system wide.  Also, the app continues to run.   In Chrome and Safari, if I click away from the web page with the HTML build, both the sound and the app itself pause.

 

Do we have any browser geniuses to weigh in here?



[TOPIC: post.html]
#5

ponywolf

[GLOBAL: userInfoPane.html]
ponywolf
  • Contributor

  • 274 posts
  • Corona SDK

Maybe my connection is better... I get music starting on first load. Wouldn't be a big deal to wait a second or two to start it... This is what that would look like with my lib...

snd:loadMusic("snd/The_Bards_Tale.mp3")
timer.performWithDelay(1000, function ()
  snd:playMusic()
end)

The Safari error is a known issue on itch.io... it's because the game is running in an iFrame, Safari gets upset about that.

 

Off topic, but the arrow keys still scroll the webpage on itch.io as well, which is kind of a pain :(



[TOPIC: post.html]
#6

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 825 posts
  • Corona SDK

I  have 1Gb/s Fios at the router but my wifi is more like 100 Mb/s.  I'll try the super fast connection and see what happens.

 

HTML builds rock - or at least they will when I work out a few of these kinks. 

 

How did you get around the arrow keys scrolling on itch.io?



[TOPIC: post.html]
#7

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,697 posts
  • Enterprise

100mb/s should be considered a super fast connection. There was a time not only a couple of years ago where a 20/1.5mbs connection was considered quite fast.


  • Michael Flad likes this

[TOPIC: post.html]
#8

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 825 posts
  • Corona SDK

OK, maybe I won't focus on the connection speed.   

 

Speaking of speed, for years I craved a T1 connection and now I'm pretty sure my phone's data speed makes that look infantile.  With the 1,000 Mb/s connection I downloaded a 45GB game for the PS4 in about 4 minutes - crazy!


  • Michael Flad likes this

[TOPIC: post.html]
#9

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,697 posts
  • Enterprise

Hard to believe that way back when, there was 300bps (baud) dial up. I would not want to give up my gigabit fiber at all today.

 

Rob


  • Michael Flad likes this

[TOPIC: post.html]
#10

gamebit.labs

[GLOBAL: userInfoPane.html]
gamebit.labs
  • Contributor

  • 224 posts
  • Corona SDK

@sporkfin, did you find a solution to the audio playback issue? i'm facing it too.

 

Ben



[TOPIC: post.html]
#11

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 563 posts
  • Corona SDK

Chrome has made various changes to their tolerance of audio on a web page recently. In a nutshell, people don't like autoplaying audio and chrome is trying to respect that.

You basically need to bind the playback to a user driven event now. I.e. rather than having it play on page load, you can use the click event of a button to invoke it.

Presumably if you have something like a "new game" button in Corona and trigger playback when that's hit, the build process will mean that this translates to a JavaScript event in the browser which Chrome will recognise as a user invoke and playback should then work fine. Untested but that's my theory at least.

[TOPIC: post.html]
#12

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 825 posts
  • Corona SDK

@gamebit - I had some luck dropping bits of my sound module onto main.lua.   It was enough to give me hope before putting the audio troubles on the back burner.

 

@richard11 - I had trouble getting a button to trigger the sound when I first had this problem but your solution makes sense.  I'll give it a try next time I'm tinkering with HTML builds.



[TOPIC: post.html]
#13

gamebit.labs

[GLOBAL: userInfoPane.html]
gamebit.labs
  • Contributor

  • 224 posts
  • Corona SDK

thanks, will try...



[TOPIC: post.html]
#14

gamebit.labs

[GLOBAL: userInfoPane.html]
gamebit.labs
  • Contributor

  • 224 posts
  • Corona SDK

My learning experience of handling audio playback for HTML5 builds:

 

1. there is no issue playing back an audio file which is a few MBs in size.

2. because browsers automatically stop audio when your app is out of focus and resume automatically when it's in focus, you don't have to manage your audio via system event.type.

 

Ben.



[TOPIC: post.html]
#15

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 825 posts
  • Corona SDK

Can you tell how many MBs it has to be before issues arise?



[TOPIC: post.html]
#16

gamebit.labs

[GLOBAL: userInfoPane.html]
gamebit.labs
  • Contributor

  • 224 posts
  • Corona SDK

My background music files are around 4MBs each, no issues. Didn't think to check if there's an issue playing bigger files.

 

Ben.




[topic_controls]
[/topic_controls]