|
| 1 | +#import <AudioToolbox/AudioQueue.h> |
| 2 | +#import <AudioToolbox/AudioFile.h> |
| 3 | +#import <AudioToolbox/AudioToolbox.h> |
| 4 | + |
| 5 | + |
| 6 | +#define kNumAQBufs 3 // number of audio queue buffers we allocate |
| 7 | +#define kAQMaxPacketDescs 128 |
| 8 | +#define kAQBufSize 64 * 1024 |
| 9 | + |
| 10 | +typedef enum { |
| 11 | + EAudioStateClosed, |
| 12 | + EAudioStateStopped, |
| 13 | + EAudioStatePlaying, |
| 14 | + EAudioStatePaused, |
| 15 | + EAudioStateSeeking |
| 16 | +} EAudioState; |
| 17 | + |
| 18 | +@protocol PlayerDelegate; |
| 19 | + |
| 20 | +@interface Player : NSObject |
| 21 | +{ |
| 22 | + id delegate; |
| 23 | + AudioFileStreamID audioFileStream; |
| 24 | + AudioQueueRef audioQueue; |
| 25 | + //AudioQueueBufferRef audioQueueBuffer[kNumAQBufs]; |
| 26 | + AudioQueueBufferRef *audioQueueBuffer; |
| 27 | + AudioStreamPacketDescription packetDescs[kAQMaxPacketDescs]; |
| 28 | + |
| 29 | + NSURLConnection *connection; |
| 30 | + NSURLRequest *request; |
| 31 | + |
| 32 | + UInt64 fillBufferIndex; |
| 33 | + UInt64 fillBufferCount; |
| 34 | + UInt64 enqueuedBuffer; |
| 35 | + UInt64 emptieddBuffer; |
| 36 | + UInt32 bytesFilled; |
| 37 | + UInt32 packetsFilled; |
| 38 | + |
| 39 | + UInt64 packetIndex; |
| 40 | + UInt32 numPacketsToRead; |
| 41 | + UInt32 ckeckIFEnded; |
| 42 | + |
| 43 | + //BOOL inuse[kNumAQBufs]; |
| 44 | + BOOL *inuse; |
| 45 | + BOOL started; |
| 46 | + BOOL failed; |
| 47 | + BOOL repeat; |
| 48 | + BOOL closed; |
| 49 | + BOOL ended; |
| 50 | + |
| 51 | + |
| 52 | + EAudioState audioState; |
| 53 | + |
| 54 | +} |
| 55 | + |
| 56 | + - (BOOL) PlayerDidStablishConnection; |
| 57 | +- (void)setDelegate:(id)val; |
| 58 | +- (id)delegate; |
| 59 | + |
| 60 | +//- (void)init; |
| 61 | +- (void)LoadUrl:(NSString*)url; |
| 62 | +- (void)stop; |
| 63 | +- (void)pause; |
| 64 | +- (void)setGain:(Float32)gain; |
| 65 | +- (void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data; |
| 66 | +- (void)propertyChanged:(AudioFileStreamPropertyID)propertyID flags:(UInt32*)flags; |
| 67 | +- (void)packetData:(const void*)data |
| 68 | + numberOfPackets:(UInt32)numPackets |
| 69 | + numberOfBytes:(UInt32)numBytes |
| 70 | +packetDescriptions:(AudioStreamPacketDescription*)packetDescriptions; |
| 71 | +- (void)playBackIsRunningStateChanged; |
| 72 | +- (void)enqueueBuffer; |
| 73 | +- (int)findQueueBuffer:(AudioQueueBufferRef)inBuffer; |
| 74 | +- (void)outputCallbackWithBufferReference:(AudioQueueBufferRef)buffer; |
| 75 | +- (void)close; |
| 76 | +- (void)dealloc; |
| 77 | + |
| 78 | +@end |
| 79 | + |
| 80 | +@protocol PlayerDelegate<NSObject> |
| 81 | + |
| 82 | +@optional |
| 83 | + |
| 84 | +- (void)PlayerDidStablishConnection:(Player *)player; // called when scrolling animation finished. may be called immediately if already at top |
| 85 | + |
| 86 | +@end |
| 87 | + |
| 88 | + |
0 commit comments