Problems with audio stream with certain phones

Hello.

I’m having troubles with a “simple” radio app that I’m developing with Ionic.

I want to play a HTML audio stream in my app, but there’s no case with certain phones. I’ve tested with Galaxy S6, Galaxy Note 5, Galaxy S6 Edge, and an Xperia Z4, and there’s no audio, but when I test with the Emulator, or run the app with Geny Motion and other devices like Xperia M2, LG G3 or Alcatel Idol the sound works great!

Also, the app work great in iOS.

I’ve tested 3 ways:

First, I’ve tested this JS code inside the app:

var audioElement = document.createElement(‘video’);

audioElement.setAttribute(‘src’, ‘http://69.175.58.196:80/stream’);
audioElement.setAttribute(‘id’, ‘audio’);
audioElement.setAttribute(‘preload’, ‘auto’);
audioElement.setAttribute(‘autoplay’, ‘true’);
audioElement.setAttribute(‘volume’,‘1’);

audioElement.oncanplay=function(){
console.log(“Ready to play”);
audioElement.play();
}

It works if I call audioElement.play(); from another button, but it takes up to 15 seconds from loggin “Ready to play” in the console to actually playing, or it won’t start. It is kinda random.
If I press a play button calling audioElement.play(), it works perfectly, after oncanplay triggers.

Secondlly, I’ve tested this other JS code:

var media = new Audio(“http://69.175.58.196:80/stream”);
media.play();
media.oncanplay = function(){
media.play();
}

Same result as before.

Finally, I’ve tested Cordova Plugin Media like this:

document.addEventListener(“deviceready”, onDeviceReady, false);
function onDeviceReady() {
function playAudio() {
// Create Media object from src
my_media = new Media(‘http://69.175.58.196:80/stream’, Success(), onError);
// Play audio
my_media.play();
}
// onSuccess Callback
function Success() {
console.log(“Playing.”)
}

  // onError Callback
  function onError(error) {
      console.log('code: ' + error.code + '\n' +
          'message: ' + error.message + '\n');
  }
  playAudio();

}

I obtain the same compatibility result, and also, when in the phones that it doesn’t work, it doesn’t log an error, but logs like it could load and play the source.

This is driving me crazy a little bit.

Regards.