Re: ScriptProcessorNode/JavaScriptNode iOS vs Android vs MAC OS ( Safari - Chrome)

I wasn't do it exactly like you suggest but as I was doing it I could play
a pure tone with the oscillatorNode...

Nevertheless, I used the onclick event of my button and after it is touched
the context, and all the other elements, are created. I am also declaring
the space for the variables in the top of the script: var node;

But, I still can not hear anything on iOS... I can not figure out why...



On Thu, Oct 3, 2013 at 5:30 PM, Charlie Roberts <bigbadotis@gmail.com>wrote:

> Maybe you're already doing this, but In iOS the audio context needs to be
> created in response to user input. Wrap your initialization code in a
> function and then do something like this when the page loads:
>
>     if('ontouchstart' in document.documentElement) {
>
> document.getElementsByTagName('body')[0].addEventListener('touchstart',
> init);
>     }else{
>       init();
>     }
>
> If you're also running testing Android you'd probably want to do something
> more sophisticated for the browser sniffing, although the worst that would
> happen is the sound wouldn't start until the user touches the screen. Make
> sure you remove the event listener in your init method under iOS. Hope this
> helps. - Charlie
>
>
> On Thu, Oct 3, 2013 at 7:31 AM, Leonardo Martínez <leolib2004@gmail.com>wrote:
>
>> Hello,
>>
>>
>> I have created an app in HTML 5 that generates white noise on its own
>> using a ScriptProcessorNode (Google Chrome) or a JavaScriptNode (Safari).
>>
>> All is working fine for Google Chrome/Safari on my Mac and also in my
>> Android phone (not to mention that the performance is really bad on my
>> Xperia Acro S) but it is not working in Safari/Chrome on my iPod Touch 5th
>> on iOS 6.1.2.
>>
>>
>>
>> The code is the following for initialization:
>>
>>
>>
>> window.AudioContext = window.AudioContext || window.webkitAudioContext;
>>
>> context = new AudioContext();
>>
>>
>>
>>
>>
>> if(this.context.createScriptProcessor)
>>
>> {
>>
>>     jsProcessor = context.createScriptProcessor(512, 0, 2);
>>
>>     alert("Chrome Desktop/Android");
>>
>> }
>>
>> else if(this.context.createJavaScriptNode)
>>
>> {
>>
>>       jsProcessor= context.createJavaScriptNode(512,1,1);
>>
>>       alert("Safari");
>>
>>      //adding 1 to node input make it works only for Safari on MAC
>>
>> }
>>
>> else
>>
>> {
>>
>>     alert("No way");
>>
>> }
>>
>>
>> jsProcessor.onaudioprocess = generateWN;
>>
>> gainNode = context.createGainNode();
>>
>> jsProcessor.connect(gainNode);
>>
>> gainNode.gain.value = 0.5;
>>
>>
>>
>>
>>
>> I have a button on the screen that when it is touched the gainNode is
>> connected to context.destination or it's disconnected. I can see that
>> onaudioprocess event is not triggered on my iPod (iOS 6.1.2 Safari and
>> Chrome)...
>>
>>
>>
>>
>>
>> What am I doing wrong? Is something different from Safari/Chrome on iOS
>> than for MAC that I am not considering?
>>
>>
>>
>> I need to create sound samples on the fly... If this work I would add a
>> filter node to filter the white noise for generating other sounds as the
>> user wants.
>>
>>
>> Thanks!
>>
>> --
>> Leonardo.
>>
>
>


-- 
Leonardo.

Received on Friday, 4 October 2013 02:43:09 UTC