Permalink
Browse files

made iOS only(for my needs) and attempted background.

  • Loading branch information...
1 parent 0e37e08 commit 9c49dcef0b8c46ea1d60e005bca1496c97abd891 @keverw committed Aug 21, 2012
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
7 AudioStreamer/AudioStreamer.h 100644 → 100755
@@ -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
@@ -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
View
28 AudioStreamer/AudioStreamer.m 100644 → 100755
@@ -26,6 +26,8 @@
#import "AudioStreamer.h"
+#import "UIDevice+Hardware.h"
+
#define BitRateEstimationMaxPackets 5000
#define BitRateEstimationMinPackets 50
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -1,44 +0,0 @@
-//
-// MacStreamingPlayerController.h
-// MacStreamingPlayer
-//
-// Created by Matt Gallagher on 28/10/08.
-// Copyright Matt Gallagher 2008. All rights reserved.
-//
-// This software is provided 'as-is', without any express or implied
-// warranty. In no event will the authors be held liable for any damages
-// arising from the use of this software. Permission is granted to anyone to
-// use this software for any purpose, including commercial applications, and to
-// alter it and redistribute it freely, subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented; you must not
-// claim that you wrote the original software. If you use this software
-// in a product, an acknowledgment in the product documentation would be
-// appreciated but is not required.
-// 2. Altered source versions must be plainly marked as such, and must not be
-// misrepresented as being the original software.
-// 3. This notice may not be removed or altered from any source
-// distribution.
-//
-
-#import <Cocoa/Cocoa.h>
-
-@class AudioStreamer;
-
-@interface MacStreamingPlayerController : NSObject
-{
- IBOutlet NSTextField *downloadSourceField;
- IBOutlet NSButton *button;
- IBOutlet NSTextField *positionLabel;
- IBOutlet NSSlider *progressSlider;
- AudioStreamer *streamer;
- NSTimer *progressUpdateTimer;
-}
-
-- (IBAction)buttonPressed:(id)sender;
-- (void)spinButton;
-- (void)updateProgress:(NSTimer *)aNotification;
-- (IBAction)sliderMoved:(NSSlider *)aSlider;
-
-@end
-
Oops, something went wrong.

0 comments on commit 9c49dce

Please sign in to comment.