Play sound on iPhone and iPad browser

0
0

We are experimenting problems with Audio component when playing sound on iPhone and iPad browser (iOs 14.xxx). We tried different format (mp3, wav, m4a) but no sound in iPhone/iPad browser. Everything run properly in all browsers on Windows. Please advice ?

Regards,

Stefano

  • You must to post comments
0
0

As long as the Window or Page is created in Program.Main you’ll be able to access it using App.MainPage or App.Window1

 

If your audio and button are on the same level, you can use this so you don’t have to worry if it’s on a page or window:

this.getParent().audio1.play();

 

I would recommend using the debugger; keyword and placing it in your JavaScript code so you can play around with the console in Chrome Dev tools.

 

Some helpful links:

JavaScript Object Model in Wisej:

https://docs.wisej.com/docs/concepts/javascript-object-model

Debugger keyword:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger

 

HTH,

Levie

  • Stefano Gruni
    Thanks Levie for your suggestion. The sound play correctly on iPhone pressing button1 as in your example. My problem now is to play sound without user interaction. I tried this.button1.Call(“execute”) the sound run on Windows but not on iOs. Please advice. S.G.
  • You must to post comments
0
0

Hi Stefano,

Playing audio on iOS Safari requires user interaction from the client. You can’t use Wisej to initially play the audio because it’s part of a callback (the play gets blocked, see the console errors). Wisej uses polling or a WebSocket connection to receive changes from the server (and to process commands like the server-side audio.play() call). This comes in the form of a callback through the AJAX request or the WebSocket’s message processing.

You can however play audio through a callback after the client has interacted with the audio element or triggered play() through a client-side event.

So if your application requires users to login or click a button at all, you can add to the client-side JS “execute” event something like:

App.Window1.audio1.play();
App.Window1.audio1.pause();

 

This satisfies the requirement of interacting with the element and dom (though no audio will be played here).

You can then go on later in your application and call audio1.Play() in your C# or VB code normally and it should play without an issue.

 

Please let me know if you have any issues with this!

 

Best,

Levie

  • Stefano Gruni
    Thanks again for your prompt response. I have a login page but the autoplayed sound is in other page with no interaction, could it run ?
  • Levie (ITG)
    It doesn’t have to be the login page. It can be any page, just make sure you attach the client-side event to a button and that it gets clicked before you try playing the audio. You can also access any Wisej client-side widget in JavaScript by calling widget(“WIDGET_ID”). You can get WIDGET_ID on the server from any Wisej control by checking the Control.Handle property. btw, if you want a custom solution (or training) for this we’re more than happy to work with you one-on-one with a consulting package. HTH, Levie
  • Stefano Gruni
    Thanks Levie, I understood that we need at least of a user click. Is it correct ?
  • Levie (ITG)
    Yes that’s correct, you can find Safari’s policies here too: https://webkit.org/blog/7734/auto-play-policy-changes-for-macos/ HTH, Levie
  • You must to post comments
0
0

Hi Levi,

thanks for the sample. Does it run in Window or just in a Page?

s.g.

  • Stefano Gruni
    could you send me some sample code using a Window not a Page?
  • You must to post comments
0
0

Hi Stefano,

Here’s the sample. Let me know if you have any issues with it!

Best,

Levie

  • Stefano Gruni
    could you send me some sample code using a Window not a Page?
  • You must to post comments
0
0

Hi Levi,

could you provide some code sample ?

Regards,

Stefano

  • You must to post comments
0
0

Additionally,

You could accomplish auto-playing the audio through a custom WKWebView wrapper like the one provided as part of the Wisej Mobile package. It overrides a lot of the default Safari functionality to give developers more control over their application.

If you’re interested, you can contact sales AT wisej DOT com.

 

HTH,

Levie

  • You must to post comments
0
0

Hi Stefano,

You can’t call Audio.Play() from the server on iOS. Safari doesn’t allow async calls to play the audio (https://developer.apple.com/forums/thread/94522). You can see it throws an error in the console (see attached image).

You can get around it by adding a ClientEvent for the “execute” event to a button with something like this:

App.MainPage.Audio1.play();

 

It should work fine as long as you trigger audio.play() from the client and not through a callback.

If you need more help with this, please let me know and provide some more details on how you’re using it!

 

Best,

Levie

Attachment
  • You must to post comments
Showing 7 results
Your Answer

Please first to submit.