Titanium Community Questions & Answer Archive

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

createAudioPlayer and system control

I'm creating an iPhone app and part of my app allows for the playback of remote audio files. I've created two buttons - one to play an audio file and one to pause an audio file.

var url = "http://www.mydomain.com/path/to/file.mp3";

// load from remote url
var sound = Titanium.Media.createAudioPlayer({
    url:url,
    audioSessionMode:Ti.Media.AUDIO_SESSION_MODE_PLAYBACK
});

var play = Titanium.UI.createButton({
    ... play button properties here ...
});

play.addEventListener('click', function()
{
    sound.start();
});

win.add(play);

var pause = Titanium.UI.createButton({
    ... pause button properties here ...
});

pause.addEventListener('click', function()
{
    sound.pause();
});
win.add(pause);

Also, in my info.plist to allow the audio to keep playing when a user exits the app, I have the following:

<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>

As far as the audio playing in the background and pausing it's working great. What I can't figure out is how to make the system iPod control (the control when you double-click the home button and swipe all the way to the left - where you see the orientation lock, rewind, play/pause, forward, and current playing app icons) pause and start the audio playing.

Any help is greatly appreciated!

— asked July 31st 2010 by E Telford
  • createaudioplayer
  • iphone
0 Comments

4 Answers

  • I am also looking for this

    — answered August 1st 2010 by Johan Pyfferoen
    permalink
    0 Comments
  • Did either of you guys figure this out? I'm trying to get a playlist of remote audio files to play and be controlled by the lock and dock controllers. I can get the audio to play in the background and can pause it but can't figure out how to hook into the back and next buttons.

    Any help is appreciated.

    — answered November 5th 2010 by Dave F
    permalink
    0 Comments
  • I would also really like to integrate with iPod controls (play/pause, back, next). It looks like those button events are Remote Control Events and need to be subscribed to. As per http://stackoverflow.com/questions/3361619/iphone-ios4-replacing-ipod-dock-icon-whilst-playing-background-audio-stream. I've searched the mobile API docs and I don't see any mention of Remote Control events or iPod control events. Titanium please provide an API for these!

    — answered January 17th 2012 by Nick Robillard
    permalink
    0 Comments
  • I've put a module in the marketplace for that.
    https://marketplace.appcelerator.com/apps/1109

    — answered November 21st 2011 by manuele capp
    permalink
    0 Comments
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.