george Posted November 26, 2015 Share Posted November 26, 2015 Hi guys,I need your help. This small page is producing a code in Firefox, Firefox ESR, Chrome on OSX each with its latest release.But it's not working as expected in Safari 9. Here is the very very reduced example:http://www.2vc.org/audio-bug/ Surprisingly it is working on jsfiddle which doesn't make it any more logicalhttp://jsfiddle.net/pg072s2r/ I don't get any sound output in safari 9 (still under yosemite) on the first page load. But if I reload it works as expected for any successive reload. There are no external files involved. So what the heck is happening here? This currently happens in my larger project with large files I am decoding and also in this small example. Can someone confirm this? I'm looking into this for some days now and I just don't get it? What do I miss? It feels like a bug that can't be a real bug but rather is some stupid error on my site. Thanks for looking into this. Btw this is the code- easy isn't it?var AudioContext = window.AudioContext || window.webkitAudioContext;var ac = new AudioContext();var oscillator = ac.createOscillator();oscillator.frequency.value = 200;oscillator.connect(ac.destination);oscillator.start();Thanks for taking your time.Regards George Quote Link to comment Share on other sites More sharing options...
alex_h Posted November 26, 2015 Share Posted November 26, 2015 Weird! I wonder if its something to do with not being 'ready' on window load. Did you try moving the code to start from a button press rather than on page load? Or even just activating it after a timeout or something like that. Quote Link to comment Share on other sites More sharing options...
george Posted November 26, 2015 Author Share Posted November 26, 2015 Hi Alex,so this happen also for you? And yeah I tried many, many different combinations on the way done from my large project down to this example. Sometimes it worked on click, on timeout but I just wanted to get back to a very basic example to get it confirmed. I mean it simply must work on a desktop browser. I will wait for other responses and continue to search an existing bug ticket for webkit for this. Btw I also tried applying chris wilsons monkey patch- as it might fix some known issues. But still the same.https://github.com/cwilso/AudioContext-MonkeyPatch RegardsGeorge Quote Link to comment Share on other sites More sharing options...
alex_h Posted November 26, 2015 Share Posted November 26, 2015 I don't have a mac so I couldn't try it actually, just interested and thought I'd throw an idea in there. Quote Link to comment Share on other sites More sharing options...
george Posted November 26, 2015 Author Share Posted November 26, 2015 I updated my testcase and prepared three workarounds. All of them deal with the state of the involved audio context.It's suspened at the beginning and we can resume it without user interaction or even with mousemove until it's fixed. I hope this can fix my project as it's a little bit more complex Her the update:http://www.2vc.org/audio-bug/ Quote Link to comment Share on other sites More sharing options...
george Posted November 26, 2015 Author Share Posted November 26, 2015 This is my workaround which works superb at the moment. I use a timeout and trigger a resume on the audio context- which is suspended for whatever reason.function fixSuspendedState(ac){ if(ac.state == 'suspended'){ log.warn('AudioContext FIX: suspended. Try to wake it.') if(ac.resume){ ac.resume(); } return ac.state == 'running'; }else{ log.warn('AudioContext FIX: not suspended, nothing to do.') return true; }}function fix(ac){ if(ac.state == 'running') return;//nothing to do setTimeout(function(){ var fixed = fixSuspendedState(ac); log.warn('AudioContext FIX: Applied, state is', fixed); }, 2000)}var ac = new AudioContext(); //wherever you are doing thisfix(ac);//fix it Dolbbb 1 Quote Link to comment Share on other sites More sharing options...
Dolbbb Posted August 9, 2016 Share Posted August 9, 2016 Thanks! I have the same problem and your code fixed it! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.