Start a new topic

Audio file not playing from local directory

Audio file not playing from local directory


Hello Tarun,

I do it this way:

 

if (sound === null)

{

    sound = new AR.Sound(audioUrl, {

        onError : function(e) {AR.logger.info("error playing sound: "+e);},

        onFinishedPlaying : function() {AR.logger.info("playSoundFinished...");},

        onLoaded : function() {AR.logger.info("onLoaded: "+sound); sound.play();}

    });

    sound.load();

}

else if (sound != null && sound.state==AR.CONST.STATE.LOADED && sound.state!=AR.CONST.STATE.PLAYING)

{

    sound.play();

}

 

If sound is not there yet, load it and play it when ready.

If sound is already loaded, just play it.

 

 

Also, if you need to destroy your sound object, you can do it like this.

 

if (sound && sound instanceof AR.Sound)

{

    sound.stop();

    sound.destroy();

}

sound = null;

 

 

 

So perhaps on thesecond attempt (the one where you're getting the error on Android), don't create a new sound object, simply check if loaded and play it.

 

If this does not work for any reason, you can try stop and destry it and reload it when you want to play it again.

 

Hope this helps,

Philipp

 

So everyone in this thread has a working solution now? Just want to aks again in case I missed anything.

Best regards

Andreas

This is actually the first time I am commenting on an this .I found this to be very clear, informative and precise. It was an easy read and it definitely helped me to understand how the manifest file works. Great job!

 

 

so if you playing from local source then you have to observe the player, but if you're playing from remote source then you observe the player item? Am i right in thinking that? your answer worked perfectly, thanks. 

Hi Philipp,

Thank you So much it really works for me...!!!!  But In Android version sometimes audio not playing give me the error and State are also change to -1 when I alert the AR.Sound Object.The first time it plays in the second  attempt it gives me an error. 

Please help me out..!!!

 

Thanks & Regards,

Tarun Kumar

 

 

 

Hello Tarun,

I experienced the same problem on iOS. The solution is that you have to call sound.load() to trigger the loading.

                                      var sound = new AR.Sound("assets/mysound.mp3", {

                                                               onError : function(e) {AR.logger.info("error playing sound: "+e);},

                                                               onFinishedPlaying : function() {AR.logger.info("playSoundFinished...");},

                                                               onLoaded : function() {AR.logger.info("onLoaded: "+sound); sound.play();}

                                                               });

                                      sound.load();

This works for me on both iOS and Android.

Hi Andreas,

Still not able to play the audio from local directory!!.

 

My Project structure of my App

--www

          ---AR

                     --wtc file

                    --mysound.mp3

                   --image.png

         --JS

                  --custom.js

     --  index.html

      --AR.html

 

First index.html wilI call. Then I load AR.html file to load AR. 

 

var wwwPath = window.location.pathname;

var basePath = wwwPath.substring(0,wwwPath.length-7);

basePath = basePath+"AR/mysound.mp3";

 

I have use relative path  to  sound1 = new AR.Sound(basePath, {})

 

But still it gives me a error

 

Best Regards,

Tarun

 

 

 

 

So you load the Architect World from the application bundle and also want to load the audio file from the bundle? If so, use relative paths for the audio file (relative to the .html file that you load with the Wikitude SDK).

Best regards

Andreas

Hey Andreas,

Platform: IOS(Phonegap)

Actually from  server-side URL HTTPS audio file is working Great, When I play the audio from the local directory it gives me the error.

Error playing audio: URL file:///var/mobile/Applications/AA719447-BF17-4706-BDAE-F1295A7B0990/myapp.app/www/assets/mysound.mp3 was not in cache 

I have uses relative path but not able to play audio file.

Best regards,

Tarun

 

 

 

 

Hi Tarun,
In case you run the Wikitude SDK on iOS 9, try a https url to your audio file and not http. App Transport Security only allows https urls on iOS 9.

Best regards

Andreas

Is any one who can help me out?

Hi,

I have implemented  the code for audio using   AR.Sound method.It's work great when I use the server URL to play sound when I run same code but change with the local path directory it gives me error.

Following are the code snippet

Example: 

It works great using server URL 

 sound1 = new AR.Sound("http://www.server.com/mysoud.mp3", {

                                   onLoaded : function(){

                                      sound1.play();

                                   },

                                   onError : function(){

                                   },

                                   });

 Error:-  When I use local directory path

   Error playing audio: url file:///var/mobile/Applications/AA719447-BF17-4706-BDAE-F1295A7B0990/myapp.app/www/assets/mysound.mp3 was not in cache  

    sound1 = new AR.Sound("assets/mysoud.mp3", {

                                   onLoaded : function(){

                                      sound1.play();

                                   },

                                   onError : function(){

                                   },

 

                                   });

 

Best Regards,

Tarun K       

 

 
Login or Signup to post a comment