Skip to content

Commit

Permalink
made iOS only(for my needs) and attempted background.
Browse files Browse the repository at this point in the history
  • Loading branch information
keverw committed Aug 21, 2012
1 parent 0e37e08 commit 9c49dce
Show file tree
Hide file tree
Showing 24 changed files with 959 additions and 4,294 deletions.
315 changes: 5 additions & 310 deletions AudioStreamer.xcodeproj/project.pbxproj
100644 → 100755

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions AudioStreamer/AudioStreamer.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@
/* This file has been heavily modified since its original distribution bytes
Alex Crichton for the Hermes project */

#import <UIKit/UIKit.h>

#import <AudioToolbox/AudioToolbox.h>
#import <Foundation/Foundation.h>

#include <pthread.h>

/* Maximum number of packets which can be contained in one buffer */
#define kAQMaxPacketDescs 512

Expand Down Expand Up @@ -162,6 +166,9 @@ struct queued_packet;
* AudioStreamer objects need to be created/managed.
*/
@interface AudioStreamer : NSObject {
#if TARGET_OS_IPHONE
UIBackgroundTaskIdentifier bgTaskId; //background support related code
#endif
/* Properties specified before the stream starts. None of these properties
* should be changed after the stream has started or otherwise it could cause
* internal inconsistencies in the stream. Detail explanations of each
Expand Down
28 changes: 28 additions & 0 deletions AudioStreamer/AudioStreamer.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#import "AudioStreamer.h"

#import "UIDevice+Hardware.h"

#define BitRateEstimationMaxPackets 5000
#define BitRateEstimationMinPackets 50

Expand Down Expand Up @@ -260,6 +262,11 @@ - (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;
Expand All @@ -272,6 +279,11 @@ - (BOOL) play {
if (state_ != AS_PAUSED) return NO;
assert(audioQueue != NULL);
err = AudioQueueStart(audioQueue, NULL);

if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)]) { //background support related code
bgTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
}

if (err) {
[self failWithErrorCode:AS_AUDIO_QUEUE_START_FAILED];
return NO;
Expand Down Expand Up @@ -796,6 +808,11 @@ - (int) enqueueBuffer {
assert(packetsFilled > 0);
err = AudioQueueEnqueueBuffer(audioQueue, fillBuf, packetsFilled,
packetDescs);

if (bgTaskId != UIBackgroundTaskInvalid) {
bgTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
}

if (err) {
[self failWithErrorCode:AS_AUDIO_QUEUE_ENQUEUE_FAILED];
return -1;
Expand All @@ -807,6 +824,12 @@ - (int) enqueueBuffer {
* start the audio queue and the file stream should remain ahead of it */
if (bufferCnt < 3 || buffersUsed > 2) {
err = AudioQueueStart(audioQueue, NULL);

if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)]) { //background support related code
bgTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
}


if (err) {
[self failWithErrorCode:AS_AUDIO_QUEUE_START_FAILED];
return -1;
Expand All @@ -826,6 +849,11 @@ - (int) enqueueBuffer {
if (queued_head == NULL &&
CFReadStreamGetStatus(stream) == kCFStreamStatusAtEnd) {
err = AudioQueueFlush(audioQueue);

if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)]) {
bgTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
}

if (err) {
[self failWithErrorCode:AS_AUDIO_QUEUE_FLUSH_FAILED];
return -1;
Expand Down
44 changes: 0 additions & 44 deletions Classes/MacStreamingPlayerController.h

This file was deleted.

Loading

0 comments on commit 9c49dce

Please sign in to comment.