Cordova Audio Streaming Delay in Android

763 Views Asked by At

When I try to call audio with html5 or cordova media plugin, there is a delay approximately 40seconds. But it works in pc browser.

I send my code below.

var my_media = new Media("http://85.111.25.40:8000/stream/1/;", onSuccess, onError, status);    
my_media.play();

OR

<audio controls autoplay>
                <source src="http://85.111.25.40:8000/stream/1/;" type="audio/mp4"></source>
            </audio>

config.xml

<content src="index.html" />
<access origin="*" />
1

There are 1 best solutions below

3
On

There is a delay because cordova-plugin-media download the full file and after this its starts playing.

I was able to perform the streaming of mp3 file, the trick is use mu3 file instead of a mp3 file.

So I get my mp3 file e create a mu3 file like this:

#EXTM3U
#EXTINF:924, Example artist - Example title
http://s3.amazonaws.com/path/my_audio_file.mp3

I saved the below code as file.mu3 and upload it to my S3 bucket.

The 924 number after #EXTINF: represents the time of the audio (my_audio_file.mp3) in seconds.

More about M3U: Click Here

And I use the link of the file.mu3 instead the mp3 file on cordova-plugin-media. And plays right away, no delay at all.

I'm using Ionic2 with the plugin arielfaur/ionic-audio to manage audio files, and this plugin uses the cordova-plugin-media to play native audio. I have the same problem and post that same solution here: Github Issue Link and worked for another person.

Best regards