Closed keverw closed 12 years ago
I'm not too familiar with how iOS apps work, but from what I understand don't you have to specifically flag the app as being able to run in the background or something like that?
This seems more like a UI-layer type aspect which doesn't really belong in streaming audio. Correct me if I'm wrong and this needs access to the audio queues, but it seems to me like it should possibly be some form of example, but on on the AudioStreamer class.
Yes, you have to edit the info.plist, iPhoneStreamingPlayerViewController and also AudioStreamer. Let me go ahead and add some comments to my code I changed, and post it in a repo.
edit:
Here it is: https://github.com/keverw/AudioStreamer
I was studying https://github.com/wmnf/wmnf_iphone, it added background support to the original AudioStreamer.
edit:
- (BOOL) pause {
if (state_ != AS_PLAYING) return NO;
assert(audioQueue != NULL);
err = AudioQueuePause(audioQueue);
if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)]) { //background support related code
if (bgTaskId != UIBackgroundTaskInvalid) {
bgTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
}
}
if (err) {
[self failWithErrorCode:AS_AUDIO_QUEUE_PAUSE_FAILED];
return NO;
}
[self setState:AS_PAUSED];
return YES;
}
From my understanding you add
if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)]) { //background support related code
if (bgTaskId != UIBackgroundTaskInvalid) {
bgTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
}
}
to certain parts of the code. Also seems to be using some UIDevice+Hardware class to detect device support it looks.
This definitely doesn't look like it belongs in the AudioStreamer
class. It doesn't depend on any internal state, so it's just cluttering up what's already there.
I would be more in favor of putting this in its own class in another file, but then again you pass the argument of NULL
so what if someone actually wanted to register a handler there? This seems like it should be a code snippet in the application, not in the audio streaming framework.
Hey! Can you please add background support? I attempted to add it myself and I've got it working some what, as in if I close the app the music keeps playing but it only seems to work in the simulator. On my iPod touch 4 it fades out. when I press the home button and the music stops.