Mossy Posted January 14, 2025 Posted January 14, 2025 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")'); Ding.mp3 Quote
Sherzod Posted January 14, 2025 Posted January 14, 2025 11 minutes ago, Mossy said: Ding.mp3 Hello, Where is the file located? Quote
Mossy Posted January 14, 2025 Author Posted January 14, 2025 I have tried the file in the same directory as the exe as well. Quote
irigsoft Posted January 14, 2025 Posted January 14, 2025 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")'); Ding.mp3 100.6 kB · 8 downloads 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();'); Quote
Mossy Posted January 14, 2025 Author Posted January 14, 2025 Hi Irigsoft Sorry I tried the above code but no sound! Don't know what I am doing wrong? Quote
irigsoft Posted January 14, 2025 Posted January 14, 2025 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''); Quote
irigsoft Posted January 14, 2025 Posted January 14, 2025 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 Quote
Mossy Posted January 14, 2025 Author Posted January 14, 2025 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();'); Quote
irigsoft Posted January 15, 2025 Posted January 15, 2025 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? Quote
Mossy Posted January 15, 2025 Author Posted January 15, 2025 The path is correct and I am using mp3 file. Quote
irigsoft Posted January 15, 2025 Posted January 15, 2025 12 minutes ago, Mossy said: The path is correct and I am using mp3 file. on your code you use ", not ''. did you try ? Quote
irigsoft Posted January 15, 2025 Posted January 15, 2025 2 hours ago, irigsoft said: what error do you get from the Google Console Quote
Mossy Posted January 22, 2025 Author Posted January 22, 2025 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(); Quote
Sherzod Posted January 22, 2025 Posted January 22, 2025 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? Quote
Mossy Posted January 22, 2025 Author Posted January 22, 2025 yes 100% I have map functions on the same file and they work OK but not the sound. Quote
irigsoft Posted January 22, 2025 Posted January 22, 2025 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 ? Quote
Sherzod Posted January 22, 2025 Posted January 22, 2025 10 minutes ago, Mossy said: I have map functions on the same file and they work OK but not the sound. What type of deployment? Quote
Sherzod Posted January 23, 2025 Posted January 23, 2025 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 ? Quote
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.