background audio

87 views
Skip to first unread message

carlos lloyd garibay loredo

unread,
Sep 13, 2013, 1:32:05 AM9/13/13
to codenameone...@googlegroups.com
I'm totally stuck developing an app that mandatory needs to be capable of playing background audio from live streaming on a wowza server or shoutcast.

This are links of the wowza audio, to check which could be used (it's supposed that the 1st is for IOS, and some Android versions, the 2nd if for Android and Blackberry and the 3rd is a shoutcast url usable in all platforms)

1. http://play.gvstream.net:554/discoverymusic-radio/default.stream/playlist.m3u8
2. rtsp://play.gvstream.net:554/discoverymusic-radio/default.stream
3. http://play.gvstream.net:9290/

It's evident that it's prefereable that the app detects/accepts the remote buttons of IOS.

There are 2 other questions I have to complete this app, specifically in Android platform.

How to detect if you press Home instead of back to ask if you reallywant to leave the app?

and the second, derived from developing in phonegap, but detected the same problem in Appcelerator, how to detect incoming call to mute the background audio? It's really annoying to hear both call and music, and if you are in a call, if u press vol buttons, you move volume of the phone call, to move it for multimedio u need to hang the call.


This is the second time I write this question; I wrote it again cause I couldn't see it after posting, but if it was because you check posts before aproving them, maybe cancel the other one and leave this, it's more clear (I apologize my English)

Shai Almog

unread,
Sep 13, 2013, 2:14:33 AM9/13/13
to codenameone...@googlegroups.com
To get iOS apps to run in the background and play audio in the background use the following:

ios.application_exits=false

ios.plistInject=<key>UIBackgroundModes</key><array><string>audio</string> </array>

ios.viewDidLoad=AVAudioSession *audioSession = [AVAudioSession sharedInstance];     NSError *setCategoryError = nil;     BOOL success = [audioSession setCategory:
AVAudioSessionCategoryPlayback error:&setCategoryError];     if (!success) {         NSLog(@"ERROR");     }     NSError *activationError = nil;     success = [audioSession setActive:YES error:&activationError];     if (!success) {         NSLog(@"ERROR");     } [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

Notice these are 3 separate arguments, the value for the 3rd is just really long and unreadable but it works.

To handle events you can use the standard key event bindings and the getGameKey(keycode) method, if it it will return one of the Display.MEDIA_* values then its a media key and should be handled as such.

We don't broardcast a specific event for minimization on android but you can use setBackCommand(cmd) on your home form and install any command. A command can show a dialog "Are you sure" and then invoke Display.getInstance().minimizeApplication();

Tom Tantisalidchai

unread,
Sep 13, 2013, 8:15:58 AM9/13/13
to codenameone...@googlegroups.com
Hi Shai,

I didn't realise we could inject the code like that (ios.viewDidLoad). Will it work for the app-level events as well (e.g. didFinishLaunchingWithOptions)?

Sorry for asking a question not relevant to the topic.

Regards,
Tom

Shai Almog

unread,
Sep 13, 2013, 2:35:45 PM9/13/13
to codenameone...@googlegroups.com
Hi,
it might work for some of them. We added some hooks mostly based on requests from pro users. Naturally not a very convenient way of solving things but it works for some cases.

Tom Tantisalidchai

unread,
Sep 14, 2013, 9:04:32 AM9/14/13
to codenameone...@googlegroups.com
OK thanks.
Reply all
Reply to author
Forward
0 new messages