Note: Build on Xcode 5
self.player = [[HSUAudioStreamPlayer alloc]
initWithURL:[NSURL URLWithString:@"http://goo.gl/ATX7Ea"]
cacheFilePath:nil];
[self.player play];
Figure 1-1. Demo screenshot
self.player = [[HSUAudioStreamPlayer alloc]
initWithURL:[NSURL URLWithString:urlString]
cacheFilePath:cacheFile];
self.player = [[HSUAudioStreamPlayer alloc]
initWithURL:nil
cacheFilePath:cacheFile];
self.player = [[HSUAudioStreamPlayer alloc]
initWithURL:[NSURL URLWithString:urlString]
cacheFilePath:cacheFile];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(playBackStateChanged:)
name:HSUAudioStreamPlayerStateChanged
object:self.player];
- (void)playBackStateChanged:(NSNotification *)notification
{
HSUAudioStreamPlayer *player = notification.object;
HSUAudioStreamPlayBackState state = player.state;
…
}
if (state == HSU_AS_STOPPED) {
[self.player play];
}
else if (state == HSU_AS_PLAYING) {
[self.player pause];
}
else if (state == HSU_AS_WAITTING) {
[self.player stop];
}
else if (state == HSU_AS_PAUSED) {
[self.player play];
}
else if (state == HSU_AS_STOPPED) {
[self.player play];
}
else if (state == HSU_AS_FINISHED) {
[self.player play];
}
[self.player seekToTime:time];
#import <AVFoundation/AVFoundation.h>
self.player = ...
self.player.audioSessionCategory =
AVAudioSessionCategoryPlayAndRecord;
// replace default value (AVAudioSessionCategoryPlayback)
or control category by yourself:
self.player.audioSessionCategory = nil;
[[AVAudioSession sharedInstance]
setCategory:AVAudioSessionCategoryPlayAndRecord
error:nil];
double duration = self.player.duration;
double progress = self.player.progress;
double currentTime = self.player.currentTime;
float volume = self.player.currentVolume;
BOOL isCached = [HSUAudioCacheControl
isCacheCompletedForCachePath:cacheFilePath]
Figure 1-2. Components and Data
Ask me on twitter, @tuoxie007