处理音频文件的播放,同时流式传输,并在流完成后将数据保存到本地URL。已在Calm的iOS生产版中得到实战验证Calm
将以下代码添加到您的Podfile文件中
pod 'PersistentStreamPlayer'
PersistentStreamPlayer *remoteAudioPlayer = [[PersistentStreamPlayer alloc] initWithRemoteURL:myHTTPURL
localURL:myFileURL];
remoteAudioPlayer.delegate = self;
[remoteAudioPlayer play];
play
、pause
和 destroy
方法(destroy
清除所有内存资源)player.looping = YES
timeBuffered
,有助于在UI中显示缓冲进度条《PersistentStreamPlayerDelegate》协议有一些有用的事件指示器,所有都是可选的
/* called when the data is saved to localURL */
- (void)persistentStreamPlayerDidPersistAsset:(PersistentStreamPlayer *)player;
/* called when the audio file completed */
- (void)persistentStreamPlayerDidFinishPlaying:(PersistentStreamPlayer *)player;
/* called when the play head reaches the buffer head */
- (void)persistentStreamPlayerStreamingDidStall:(PersistentStreamPlayer *)player;
/* called as soon as the asset loads with a duration, helpful for showing a duration clock */
- (void)persistentStreamPlayerDidLoadAsset:(PersistentStreamPlayer *)player;
/* on failure to load asset */
- (void)persistentStreamPlayerDidFailToLoadAsset:(PersistentStreamPlayer *)player;