Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Classes/AFSoundPlayback.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ typedef NS_ENUM(NSInteger, AFSoundStatus) {
};

-(id)initWithItem:(AFSoundItem *)item;
-(id)initWithItem:(AFSoundItem *)item avAudioSessionCategory:(NSString *)categoryName;

@property (nonatomic, strong) AVPlayer *player;
@property (nonatomic) AFSoundStatus status;
Expand Down
15 changes: 15 additions & 0 deletions Classes/AFSoundPlayback.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ -(id)initWithItem:(AFSoundItem *)item {
return self;
}

-(id)initWithItem:(AFSoundItem *)item avAudioSessionCategory:(NSString *)categoryName {
if (self == [super init]) {
_currentItem = item;
[self setUpItem:item avAudioSessionCategory:categoryName];
_status = AFSoundStatusNotStarted;
}
return self;
}

-(void)setUpItem:(AFSoundItem *)item {

_player = [[AVPlayer alloc] initWithURL:item.URL];
Expand All @@ -55,6 +64,12 @@ -(void)setUpItem:(AFSoundItem *)item {
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
}

-(void)setUpItem:(AFSoundItem *)item avAudioSessionCategory:(NSString *)categoryName {
[self setUpItem:item];
[[AVAudioSession sharedInstance] setCategory:categoryName error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
}

-(void)listenFeedbackUpdatesWithBlock:(feedbackBlock)block andFinishedBlock:(finishedBlock)finishedBlock {

CGFloat updateRate = 1;
Expand Down
1 change: 1 addition & 0 deletions Classes/AFSoundQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ typedef void (^feedbackBlock)(AFSoundItem *item);
typedef void (^itemFinishedBlock)(AFSoundItem *nextItem);

-(id)initWithItems:(NSArray *)items;
-(id)initWithItems:(NSArray *)items avAudioSessionCategory:(NSString *)categoryName;

@property (nonatomic) AFSoundStatus status;

Expand Down
19 changes: 17 additions & 2 deletions Classes/AFSoundQueue.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ @interface AFSoundQueue ()
@property (nonatomic, strong) NSMutableArray *items;

@property (nonatomic, strong) NSTimer *feedbackTimer;
@property (nonatomic, copy) NSString *avAudioSessionCategoryName;

@end

Expand All @@ -31,7 +32,11 @@ -(id)initWithItems:(NSArray *)items {

_items = [NSMutableArray arrayWithArray:items];

_queuePlayer = [[AFSoundPlayback alloc] initWithItem:items.firstObject];
if (_avAudioSessionCategoryName) {
_queuePlayer = [[AFSoundPlayback alloc] initWithItem:items.firstObject avAudioSessionCategory:_avAudioSessionCategoryName];
} else {
_queuePlayer = [[AFSoundPlayback alloc] initWithItem:items.firstObject];
}

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
}
Expand All @@ -40,6 +45,12 @@ -(id)initWithItems:(NSArray *)items {
return self;
}

-(id)initWithItems:(NSArray *)items avAudioSessionCategory:(NSString *)categoryName {

_avAudioSessionCategoryName = categoryName;
return [self initWithItems:items];
}

-(void)listenFeedbackUpdatesWithBlock:(feedbackBlock)block andFinishedBlock:(itemFinishedBlock)finishedBlock {

CGFloat updateRate = 1;
Expand Down Expand Up @@ -172,7 +183,11 @@ -(void)playItem:(AFSoundItem *)item {
// [_feedbackTimer resumeTimer];
}

_queuePlayer = [[AFSoundPlayback alloc] initWithItem:item];
if (_avAudioSessionCategoryName) {
_queuePlayer = [[AFSoundPlayback alloc] initWithItem:item avAudioSessionCategory:_avAudioSessionCategoryName];
} else {
_queuePlayer = [[AFSoundPlayback alloc] initWithItem:item];
}
[_queuePlayer play];
[[MPRemoteCommandCenter sharedCommandCenter] playCommand];

Expand Down