From f725ed0b2c3e7611f4a3ea3704befc709d374a84 Mon Sep 17 00:00:00 2001 From: Thong Nguyen Date: Mon, 3 Feb 2014 13:50:15 +0000 Subject: [PATCH] Added additional queue/play methods --- README.md | 4 +- StreamingKit/StreamingKit/STKAudioPlayer.h | 32 +++++++++++++-- StreamingKit/StreamingKit/STKAudioPlayer.m | 45 +++++++++++++++++++--- 3 files changed, 70 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 95ea761..db26b07 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,8 @@ STKAudioPlayer* audioPlayer = [[STKAudioPlayer alloc] init]; ```objective-c STKAudioPlayer* audioPlayer = [[STKAudioPlayer alloc] init]; -[audioPlayer queueDataSource:[STKAudioPlayer dataSourceFromURL:@"http://fs.bloom.fm/oss/audiosamples/sample.mp3"]]; -[audioPlayer queueDataSource:[STKAudioPlayer dataSourceFromURL:@"http://fs.bloom.fm/oss/audiosamples/airplane.aac"]]; +[audioPlayer queue:@"http://fs.bloom.fm/oss/audiosamples/sample.mp3"]; +[audioPlayer queue:@"http://fs.bloom.fm/oss/audiosamples/airplane.aac"]; ``` diff --git a/StreamingKit/StreamingKit/STKAudioPlayer.h b/StreamingKit/StreamingKit/STKAudioPlayer.h index d42e401..e247ad4 100644 --- a/StreamingKit/StreamingKit/STKAudioPlayer.h +++ b/StreamingKit/StreamingKit/STKAudioPlayer.h @@ -149,16 +149,40 @@ typedef void(^STKFrameFilter)(UInt32 channelsPerFrame, UInt32 bytesPerFrame, UIn /// Initializes a new STKAudioPlayer with the given options -(id) initWithOptions:(STKAudioPlayerOptions)optionsIn; -/// Plays an item from the given URL (all pending queued items are removed) +/// Plays an item from the given URL string (all pending queued items are removed). +/// The NSString is used as the queue item ID -(void) play:(NSString*)urlString; /// Plays an item from the given URL (all pending queued items are removed) --(void) playWithURL:(NSURL*)url; +-(void) play:(NSString*)urlString withQueueItemID:(NSObject*)queueItemId; + +/// Plays an item from the given URL (all pending queued items are removed) +/// The NSURL is used as the queue item ID +-(void) playURL:(NSURL*)url; + +/// Plays an item from the given URL (all pending queued items are removed) +-(void) playURL:(NSURL*)url withQueueItemID:(NSObject*)queueItemId; /// Plays the given item (all pending queued items are removed) --(void) playWithDataSource:(STKDataSource*)dataSource; +/// The STKDataSource is used as the queue item ID +-(void) playDataSource:(STKDataSource*)dataSource; -/// Queues a DataSource with te given Item ID for playback +/// Plays the given item (all pending queued items are removed) +-(void) playDataSource:(STKDataSource*)dataSource withQueueItemID:(NSObject*)queueItemId; + +/// Queues the URL string for playback and uses the NSString as the queueItemID +-(void) queue:(NSString*)urlString; + +/// Queues the URL string for playback with the given queueItemID +-(void) queue:(NSString*)urlString withQueueItemId:(NSObject*)queueItemId; + +/// Queues the URL for playback and uses the NSURL as the queueItemID +-(void) queueURL:(NSURL*)url; + +/// Queues the URL for playback with the given queueItemID +-(void) queueURL:(NSURL*)url withQueueItemId:(NSObject*)queueItemId; + +/// Queues a DataSource with the given queueItemId -(void) queueDataSource:(STKDataSource*)dataSource withQueueItemId:(NSObject*)queueItemId; /// Plays the given item (all pending queued items are removed) diff --git a/StreamingKit/StreamingKit/STKAudioPlayer.m b/StreamingKit/StreamingKit/STKAudioPlayer.m index 0cd63f7..023b418 100644 --- a/StreamingKit/StreamingKit/STKAudioPlayer.m +++ b/StreamingKit/StreamingKit/STKAudioPlayer.m @@ -481,20 +481,35 @@ static void AudioFileStreamPacketsProc(void* clientData, UInt32 numberBytes, UIn } -(void) play:(NSString*)urlString +{ + [self play:urlString withQueueItemID:urlString]; +} + +-(void) play:(NSString*)urlString withQueueItemID:(NSObject*)queueItemId { NSURL* url = [NSURL URLWithString:urlString]; - [self setDataSource:[STKAudioPlayer dataSourceFromURL:url] withQueueItemId:urlString]; + [self setDataSource:[STKAudioPlayer dataSourceFromURL:url] withQueueItemId:queueItemId]; } --(void) playWithURL:(NSURL*)url +-(void) playURL:(NSURL*)url { - [self setDataSource:[STKAudioPlayer dataSourceFromURL:url] withQueueItemId:url]; + [self playURL:url withQueueItemID:url]; } --(void) playWithDataSource:(STKDataSource*)dataSource +-(void) playURL:(NSURL*)url withQueueItemID:(NSObject*)queueItemId { - [self setDataSource:dataSource withQueueItemId:dataSource]; + [self setDataSource:[STKAudioPlayer dataSourceFromURL:url] withQueueItemId:queueItemId]; +} + +-(void) playDataSource:(STKDataSource*)dataSource +{ + [self playDataSource:dataSource withQueueItemID:dataSource]; +} + +-(void) playDataSource:(STKDataSource*)dataSource withQueueItemID:(NSObject *)queueItemId +{ + [self setDataSource:dataSource withQueueItemId:queueItemId]; } -(void) setDataSource:(STKDataSource*)dataSourceIn withQueueItemId:(NSObject*)queueItemId @@ -516,6 +531,26 @@ static void AudioFileStreamPacketsProc(void* clientData, UInt32 numberBytes, UIn [self wakeupPlaybackThread]; } +-(void) queue:(NSString*)urlString +{ + return [self queueURL:[NSURL URLWithString:urlString] withQueueItemId:urlString]; +} + +-(void) queue:(NSString*)urlString withQueueItemId:(NSObject*)queueItemId +{ + [self queueURL:[NSURL URLWithString:urlString] withQueueItemId:queueItemId]; +} + +-(void) queueURL:(NSURL*)url +{ + [self queueURL:url withQueueItemId:url]; +} + +-(void) queueURL:(NSURL*)url withQueueItemId:(NSObject*)queueItemId +{ + [self queueDataSource:[STKAudioPlayer dataSourceFromURL:url] withQueueItemId:queueItemId]; +} + -(void) queueDataSource:(STKDataSource*)dataSourceIn withQueueItemId:(NSObject*)queueItemId { pthread_mutex_lock(&playerMutex);