Skip to content

Commit

Permalink
Merge pull request #10 from antondarki/block_fix
Browse files Browse the repository at this point in the history
Fixes for crashing app if progress block is nil
  • Loading branch information
AlvaroFranco committed Jun 29, 2014
2 parents da1821a + a02c43d commit 4206e98
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions Classes/AFSoundManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,17 @@ -(void)startPlayingLocalFileWithName:(NSString *)name andBlock:(progressBlock)bl

percentage = (int)((_audioPlayer.currentTime * 100)/_audioPlayer.duration);
int timeRemaining = _audioPlayer.duration - _audioPlayer.currentTime;

block(percentage, _audioPlayer.currentTime, timeRemaining, error, NO);

if (block) {
block(percentage, _audioPlayer.currentTime, timeRemaining, error, NO);
}
} else {

int timeRemaining = _audioPlayer.duration - _audioPlayer.currentTime;

block(100, _audioPlayer.currentTime, timeRemaining, error, YES);

if (block) {
block(100, _audioPlayer.currentTime, timeRemaining, error, YES);
}
[_timer invalidate];
_status = AFSoundManagerStatusFinished;
[_delegate currentPlayingStatusChanged:AFSoundManagerStatusFinished];
Expand Down Expand Up @@ -90,22 +93,28 @@ -(void)startStreamingRemoteAudioFromURL:(NSString *)url andBlock:(progressBlock)

percentage = (int)((CMTimeGetSeconds(_player.currentItem.currentTime) * 100)/CMTimeGetSeconds(_player.currentItem.duration));
int timeRemaining = CMTimeGetSeconds(_player.currentItem.duration) - CMTimeGetSeconds(_player.currentItem.currentTime);

block(percentage, CMTimeGetSeconds(_player.currentItem.currentTime), timeRemaining, error, NO);

if (block) {
block(percentage, CMTimeGetSeconds(_player.currentItem.currentTime), timeRemaining, error, NO);
}
} else {

int timeRemaining = CMTimeGetSeconds(_player.currentItem.duration) - CMTimeGetSeconds(_player.currentItem.currentTime);

block(100, CMTimeGetSeconds(_player.currentItem.currentTime), timeRemaining, error, YES);


if (block) {
block(100, CMTimeGetSeconds(_player.currentItem.currentTime), timeRemaining, error, YES);
}

[_timer invalidate];
_status = AFSoundManagerStatusFinished;
[_delegate currentPlayingStatusChanged:AFSoundManagerStatusFinished];
}
} repeats:YES];
} else {

block(0, 0, 0, error, YES);

if (block) {
block(0, 0, 0, error, YES);
}
[_audioPlayer stop];
}
}
Expand Down

0 comments on commit 4206e98

Please sign in to comment.