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 complete event?

Is there no "complete" event for Titanium.Media.AudioPlayer? I don't see one and after seeing Titanium.Media.Sound has one, i tried adding a listener for "complete" but to no avail. I find it strange that this isn't supported for AudioPlayer. Am I missing something?

— asked October 13th 2010 by Nick Robillard
  • audio
  • audioplayer
  • complete
  • event
  • mobile
1 Comment
  • I'm also not seeing any way to get an audio track's duration…

    — commented October 15th 2010 by Nick Robillard

3 Answers

  • For now I've worked around the complete event issue by checking the progress property after a stop event.

    function playbackStateChange(e) {
        if (e.state == audioPlayer.STATE_STOPPED && audioPlayer.progress > 0) {
            // Track complete
        }
    }
    audioPlayer.addEventListener('change', playbackStateChange);
    

    Still wish there was a complete event - this is a bit hacky. And still not seeing a way to get the total duration (before the track is complete). :(

    — answered October 15th 2010 by Nick Robillard
    permalink
    0 Comments
  • You can fire an event on state change, and the integer of the stat will change when the stream is complete.

    If I remember correctly, the complete state is "6".

    Hope that helps.

    Peter Janett

    http://www.NewMediaOne.net

    — answered October 17th 2010 by Peter janett
    permalink
    1 Comment
    • I'm already listening for state change. And 6 is the "stopping" event, which gets fired anytime the stream is about to stop, which is essentially the same as my workaround.

      — commented October 17th 2010 by Nick Robillard
  • Fyi, I've found using the VideoPlayer is a good workaround for this since it also plays MP3s.

    — answered September 7th 2011 by Nick Robillard
    permalink
    1 Comment
    • Although I'm having great difficulty differentiating between a user stop event and an actual playback complete event. The e.reason is always 0. (referring to VideoPlayer)

      — commented September 8th 2011 by Nick Robillard
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.