Jump to content

Recommended Posts

Posted

Hi

 

How to play a wave file from code please? I tried the following but is not working.

  UniSession.AddJS(
    'function playSound(url) {' +
    '  var audio = new Audio(url);' +
    '  audio.play();' +
    '}'
  );
 

UniSession.AddJS('playSound("Ding.mp3")');

 

Posted
40 minutes ago, Mossy said:

Hi

 

How to play a wave file from code please? I tried the following but is not working.

  UniSession.AddJS(
    'function playSound(url) {' +
    '  var audio = new Audio(url);' +
    '  audio.play();' +
    '}'
  );
 

UniSession.AddJS('playSound("Ding.mp3")');

 

 

HI, try 

           PlaySoundFile := '.\Settings\Sounds\MyWav.wav';

            PlaySoundFile := StrUtilsEx.FastStringReplace (PlaySoundFile,'\','/',[rfReplaceAll]);
            UniSession.SendResponse(' var audio1 = document.createElement(''audio'');'
                                + 'audio1.setAttribute(''src'', ''' + PlaySoundFile + ''');'
                                + 'audio1.load();'
                                + 'audio1.play();');

 

Posted
13 minutes ago, Mossy said:

Hi Irigsoft

Sorry I tried the above code but no sound! Don't know what I am doing wrong?

try to set full path to file D:\yourApp\.....

and you must to have audio element (payer)  var audio1 = document.createElement(''audio'');

Posted

If you want to play sound on client side, try with this:

UniSession.AddJs ('new Audio('''/settings/sounds/yoursound.mp3''').play();')

/settings/sounds/yoursound.mp3, must exist on your server directory: AppDir\settings\sounds\yoursound.mp3

Posted

Hi irigsoft

 

many thanks for your help. if I place the AppPath on browser it works however when is called from the app makes no noise. As I understand this JS call is executed on the client not the server! however I don't understand why is not executing?

UniSession.AddJs ('new Audio("'+AppPath+'").play();');

Posted
9 hours ago, Mossy said:

Hi irigsoft

 

many thanks for your help. if I place the AppPath on browser it works however when is called from the app makes no noise. As I understand this JS call is executed on the client not the server! however I don't understand why is not executing?

UniSession.AddJs ('new Audio("'+AppPath+'").play();');

look at the path.

does your path use this slash \ or this /?

The correct URL is "/settings/sounds/yoursound.mp3"

Another possible cause of your problem is the file type. I'm using mp3, but with some other files it is necessary to specify the correct MIME type

When you play a file from your app, what error do you get from the Google Console?

Posted

Hi 

I have placed the following function in an UniHTMLFrame and call the function: UniSession.AddJs('playSound("ding.mp3")');

If the app is running on my laptop the sound is there, however when the app is on server, no sound can be heard.

Is this function not suppose to run on client side, if not how can we make it to run on client side. 

        function playSound(filename) {
            var audio = new Audio(filename);
            audio.play();
 

Posted
27 minutes ago, Mossy said:

If the app is running on my laptop the sound is there, however when the app is on server, no sound can be heard.

Hello,

Did you even host the audio file on the server?

Posted
6 minutes ago, Mossy said:

yes 100%

I have map functions on the same file and they work OK but not the sound.

1. can you share picture of google console error when you try to play sound ?

2. can you share your CORS settings ?

Posted
1 hour ago, Mossy said:

any suggestions?

 

21 hours ago, irigsoft said:

1. can you share picture of google console error when you try to play sound ?

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...