Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

AudioPlayer change state inconsistencies

I'm currently finding that when I create an event listener that listens to the audioPlayer change state, the state reported varies widely across platforms and even devices.

Take the folowing code for instance (no affiliation with the URL, just for example purposes:)

Ti.API.log("Audio Stream App Started");

var url ='http://www.parishiltonjustme.com/downloads/audio/08_Screwed.mp3';

var streamer1 = Ti.Media.createAudioPlayer();

streamer1.addEventListener('change',function(e)
{ 
    Ti.API.log("AudioPlayer addEventListener 'change' says : "+e.description);
});

streamer1.url = url;

streamer1.start();

When this runs, i get several different relults depending on device OS and even device vs. emulator.

iPhone 4.1 Emulator

[INFO] Audio Stream App Started
[INFO] AudioPlayer addEventListener 'change' says : waiting_for_data
[INFO] AudioPlayer addEventListener 'change' says : waiting_for_data
[INFO] AudioPlayer addEventListener 'change' says : waiting_for_queue
[INFO] AudioPlayer addEventListener 'change' says : playing
[INFO] AudioPlayer addEventListener 'change' says : stopping
[INFO] AudioPlayer addEventListener 'change' says : stopped
[INFO] AudioPlayer addEventListener 'change' says : initialized

Android 1.6 Emulator

[INFO] Audio Stream App Started
[INFO] AudioPlayer addEventListener 'change' says : starting
[INFO] AudioPlayer addEventListener 'change' says : initialized
[INFO] AudioPlayer addEventListener 'change' says : playing
[INFO] AudioPlayer addEventListener 'change' says : playing

^never reports stopping or stopped^

Andriod 2.2 Emulator

[INFO] Audio Stream App Started
[INFO] AudioPlayer addEventListener 'change' says : starting
[INFO] AudioPlayer addEventListener 'change' says : initialized
[INFO] AudioPlayer addEventListener 'change' says : playing
[INFO] AudioPlayer addEventListener 'change' says : playing
[INFO] AudioPlayer addEventListener 'change' says : stopping
[INFO] AudioPlayer addEventListener 'change' says : stopped

Android 2.2 T- Mobile G2 (ADB logcat)

I/TiAPI   ( 4260): (kroll$3) [22,25] [Audio Stream App Started] null
I/TiAPI   ( 4260): (kroll$3) [2207,2232] [AudioPlayer addEventListener 'change' says : starting] null
I/TiAPI   ( 4260): (kroll$3) [33,2265] [AudioPlayer addEventListener 'change' says : initialized] null
I/TiAPI   ( 4260): (kroll$3) [4,2269] [AudioPlayer addEventListener 'change' says : playing] null
I/TiAPI   ( 4260): (kroll$3) [2,2271] [AudioPlayer addEventListener 'change' says : playing] null

^never reports stopping or stopped^

Considering this, How, for instance, might one go about coding a music stream player that auto-advances on all devices in Titanium Mobile?

— asked October 8th 2010 by Darin Dahlinger
  • android
  • audioplayer
  • iphone
  • mobile
1 Comment
  • Might any one else have experience trying to implement such functionality into an app?

    Also, at what point might it be acceptable to raise this issue to the attention of the development community via a ticket over at https://appcelerator.lighthouseapp.com?

    — commented October 20th 2010 by Darin Dahlinger

3 Answers

  • bump

    — answered October 29th 2010 by Darin Dahlinger
    permalink
    0 Comments
  • bump

    — answered October 29th 2010 by Darin Dahlinger
    permalink
    0 Comments
  • The tumbleweed is blowing through this one Darin isn't it? I expect you've given up by now and gone to live on a desert island.

    Seriously though, my implementation of a streaming player on iPhone worked very well by sensing the different values of 'change' event, principally so if for instance the stream suddenly stopped my button would know to change back to it's "start" icon and not be left stranded on "play" - on Android it's a nightmare as this just doesn't work. I'm only getting a 'state' of 6, then 5 when I stop and no state at all when I play!

    Perhaps somebody could explain why this doesn't work properly?

    Titanium SDK 1.5 Android API's 2.2

    — answered December 15th 2010 by Patrick Mounteney
    permalink
    1 Comment
    • After further experiments I moved my addEventListener outside of the function that creates the player and now get more states!
      4 : starting, 1 : initialized, 3 : playing then after clicking "stop" we get 6 : stopping and 5 : stopped - so some improvement.

      — commented December 15th 2010 by Patrick Mounteney
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.