Software Archive
Read-only legacy content
17061 Discussions

Audio Not Playing in the App but playing in the Emulator

Joseph_R_2
Beginner
615 Views

Hi,

I am facing the issue of the audio not being played from the installed App in the Mobile.

I am able to play the audio in the XDK Emulator but not in the Mobile.

The Error in the App Mobile App is code : 1 message : undefined

Here is the code

  <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
        <script type="text/javascript" charset="utf-8">
        document.addEventListener("deviceready", onDeviceReady, false);
        var my_media = null;

        function playAudio(src) {

            my_media = new Media(src, onSuccess, onError);
            my_media.play();  
        } 
        function onSuccess() {
            console.log("playAudio():Audio Success");
        }
        function onError(error) {
            alert('code: '    + error.code    + '\n' +
                  'message: ' + error.message + '\n');
        } 

        </script>
      </head>


      <body>
          <h3>Luger</h3>
     <button onclick="playAudio('www/Shot.ogg');"> <img src="Luger.jpg" width="500" height="200"> </button

I used both Wav and Ogg, both are playing fine in the Emulator not in the Installed App

Please Help if possible, Thanks in Advance

0 Kudos
4 Replies
Amrita_C_Intel
Employee
615 Views

Hello,

Which plugin are you using?

Emulator is just a simulator. There are some limitations just check out this link: https://software.intel.com/en-us/xdk/docs/dev-emulator

Try to build with crosswalk and use either build or debug tab to see the actual behavior of the app.

0 Kudos
Amrita_C_Intel
Employee
615 Views

First of all you can take look of one of our sample to understand how it works.

Here is the link: https://github.com/gomobile/sample-audio-player

.wav and .ogg files are the only ones compatible with the emulator. However, you can use .mp3 files without issues except that you should test on a built app or app preview. 

0 Kudos
Joseph_R_2
Beginner
615 Views

Hi Amrita,

Thanks for your Example, but I think I figured out the problem here.

The issue is happening if the Sound File is present Locally in the www folder, If I give a Sound File URL to be played instead, it is getting played flawlessly in the App .

In your given example, the Cordova API Function has an URL for its playback, so its getting played both in the Emulator and the App.

I think the issue is with the Asset Compression in Android and the MP3 did not get compressed correctly.

I am adding the changed code

  <body>
          <h3>Luger</h3>
     <button onclick="playAudio('http://www.wolfensteingoodies.com/archives/olddoom/sounds/dspistol.wav');"> <img src="Luger.jpg" width="500" height="200"> 

Thanks for your time again.

0 Kudos
Amrita_C_Intel
Employee
615 Views

Great! I am glad it is working

0 Kudos
Reply