Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-4544] Android: AudioPlayer AAC streams do not work for some streams

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionWon't Fix
Resolution Date2014-04-21T21:25:22.000+0000
Affected Version/sRelease 1.7.1
Fix Version/sn/a
ComponentsAndroid
Labelsaacp, audioplayer
ReporterPaul Dowsett
AssigneeHieu Pham
Created2011-07-03T12:00:07.000+0000
Updated2017-03-22T17:56:48.000+0000

Description

As per [this Q&A question](http://developer.appcelerator.com/question/121172/aacp-shoutcast-radio-stream), AAC streams don't work on Android 2.1, and rarely work on 2.2, when using Titanium 1.7.X. See the notes next to the URLs in the following code for more info. Note that code allows each stream to be tested in sequence.
var url = [];
url.push("http://st2.webradioworld.net:8036");  // direct stream - exception on 2.1, exception on 2.2
url.push("http://radio.musicvictim.com:8012");  // direct stream - exception on 2.1, works on 2.2

// Info page: http://www.radioparadise.com/content.php?name=Listen
url.push("http://www.radioparadise.com/musiclinks/rp_64aac.m3u"); // exception on 2.1, exception on 2.2
url.push("http://173.244.214.174:8008");  // direct stream - exception on 2.1, exception on 2.2

// Info page: http://kzsulive.stanford.edu/
url.push("http://kzsulive.stanford.edu/audio/kzsu-1-48.pls"); // exception on 2.1, exception on 2.2
url.push("http://171.66.118.51/kzsu-1-48.aac");  // direct stream - exception on 2.1, does not work on 2.2 but no exception


var win = Ti.UI.createWindow({
  backgroundColor : "white",
  layout:'vertical',
  exitOnClose:true
});

Ti.Media.audioSessionMode = Ti.Media.AUDIO_SESSION_MODE_AMBIENT;

var urlIndex = 0;
var audio = Ti.Media.createAudioPlayer({
  url:url[urlIndex],
  preload:false,
  allowBackground:true
});

audio.format = Ti.Media.AUDIO_FORMAT_AAC;
audio.audioSessionMode = Ti.Media.AUDIO_SESSION_MODE_PLAYBACK;

var buttonControl = Ti.UI.createButton({
  title: 'Play',
  isSound:false,
  top:50
});

win.add(buttonControl);
win.open();

var nav_hidden = false;

Ti.API.info("Starting stream: "+ url[urlIndex]);
buttonControl.addEventListener('click', function(){
  if(buttonControl.isSound){
    audio.stop();
    buttonControl.title = 'Play';
    buttonControl.isSound = !buttonControl.isSound;
    Ti.API.info("Stream stopped");
    if(urlIndex === url.length-1){
      urlIndex = 0;
    } else {
      urlIndex++;
    }
    audio.url = url[urlIndex];
  } else {
    Ti.API.info("Starting stream: "+ audio.url);
    audio.start();
    buttonControl.title = 'Stop';
    buttonControl.isSound = !buttonControl.isSound;
    Ti.API.info("Stream started");
  }
});

audio.addEventListener('change', function(e){
  Ti.API.info("Current audio state: " + e.state);
});
The following shows output generated using Android 2.2 when the first and second streams were played, the first caused an exception, the next played successfully.
  628                   TiAPI  I  (kroll$1: app://app.js) [2568,5385] Starting stream: http://st2.webradioworld.net:8036
   34       StagefrightPlayer  I  setDataSource('http://st2.webradioworld.net:8036')
  118                dalvikvm  D  GC_EXPLICIT freed 144 objects / 7536 bytes in 132ms
  628             MediaPlayer  E  error (1, -2147483648)
  628                 TiSound  W  (kroll$1: app://app.js) [1381,6766] Issue while initializing : 
  628                 TiSound  W  java.io.IOException: Prepare failed.: status=0x1
  628                 TiSound  W  	at android.media.MediaPlayer.prepare(Native Method)
  628                 TiSound  W  	at ti.modules.titanium.media.TiSound.initialize(TiSound.java:118)
  628                 TiSound  W  	at ti.modules.titanium.media.TiSound.play(TiSound.java:177)
  628                 TiSound  W  	at ti.modules.titanium.media.AudioPlayerProxy.play(AudioPlayerProxy.java:111)
  628                 TiSound  W  	at ti.modules.titanium.media.AudioPlayerProxy.start(AudioPlayerProxy.java:104)
  628                 TiSound  W  	at ti.modules.titanium.media.AudioPlayerProxyBindingGen$9.invoke(AudioPlayerProxyBindingGen.java:355)
  628                 TiSound  W  	at org.appcelerator.kroll.KrollMethod.call(KrollMethod.java:51)
  628                 TiSound  W  	at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1701)
  628                 TiSound  W  	at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:854)
  628                 TiSound  W  	at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
  628                 TiSound  W  	at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426)
  628                 TiSound  W  	at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3177)
  628                 TiSound  W  	at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:162)
  628                 TiSound  W  	at org.appcelerator.titanium.kroll.KrollCallback.callSync(KrollCallback.java:139)
  628                 TiSound  W  	at org.appcelerator.titanium.kroll.KrollCallback$1.run(KrollCallback.java:164)
  628                 TiSound  W  	at android.os.Handler.handleCallback(Handler.java:587)
  628                 TiSound  W  	at android.os.Handler.dispatchMessage(Handler.java:92)
  628                 TiSound  W  	at android.os.Looper.loop(Looper.java:123)
  628                 TiSound  W  	at org.appcelerator.titanium.kroll.KrollHandlerThread.run(KrollHandlerThread.java:86)
  628                   TiAPI  I  (kroll$1: app://app.js) [57,6823] Stream started
  628                   TiAPI  I  (kroll$1: app://app.js) [6,6829] Current audio state: 4
  628                   TiAPI  I  (kroll$1: app://app.js) [24,6853] Current audio state: 5
  628                   TiAPI  I  (kroll$1: app://app.js) [34684,41537] Stream stopped
  161         EventLogService  I  Aggregate from 1309717206104 (log), 1309717206104 (data)
  161                dalvikvm  D  GC_FOR_MALLOC freed 4070 objects / 443448 bytes in 94ms
  628                   TiAPI  I  (kroll$1: app://app.js) [4457,45994] Starting stream: http://radio.musicvictim.com:8012
   34       StagefrightPlayer  I  setDataSource('http://radio.musicvictim.com:8012')
   34           AwesomePlayer  I  calling prefetcher->prepare()
   34              Prefetcher  I  [0x782b8] cache below low water mark, filling cache.
   34           AwesomePlayer  I  prefetcher is done preparing
   34               AudioSink  D  bufferCount (4) is too small and increased to 12
  628                   TiAPI  I  (kroll$1: app://app.js) [1950,47944] Stream started
  628                   TiAPI  I  (kroll$1: app://app.js) [2,47946] Current audio state: 4
  628                   TiAPI  I  (kroll$1: app://app.js) [28,47974] Current audio state: 1
  628                   TiAPI  I  (kroll$1: app://app.js) [29,48003] Current audio state: 3
  628                   TiAPI  I  (kroll$1: app://app.js) [16,48019] Current audio state: 3
   34            AudioFlinger  W  write blocked for 74 msecs, 2573 delayed writes, thread 0xb3f0
   34           AwesomePlayer  E  Not sending buffering status because duration is unknown.
   34            AudioFlinger  W  write blocked for 73 msecs, 2600 delayed writes, thread 0xb3f0
   34            AudioFlinger  W  write blocked for 72 msecs, 2629 delayed writes, thread 0xb3f0
   34            AudioFlinger  W  write blocked for 72 msecs, 2654 delayed writes, thread 0xb3f0
   34            AudioFlinger  W  write blocked for 75 msecs, 2678 delayed writes, thread 0xb3f0

Comments

  1. Paul Dowsett 2011-07-05

    Please note that the streams included in the usecase have yet to be checked against Android's official list of [supported codecs](http://developer.android.com/guide/appendix/media-formats.html) (sample rates, container formats, etc)
  2. Alexis Gaitan 2012-09-22

    any news on this :) im trying to reproduce aac stream too without luck
  3. Hieu Pham 2014-04-21

    Please reopen if you can reproduce this on newer devices.
  4. Lee Morris 2017-03-22

    Closing ticket as the issue will not fix and with reference to the above comments.

JSON Source