Iphone 从url本地保存音频,以便以后播放
如何将url中的音频保存到本地以便以后播放。我可以使用avplayer流式播放音频,但无法在本地保存并稍后播放。我尝试使用AVURLASET。有人能帮我吗 这是我试图在本地保存的代码: 在这里,我使用avplayer播放音频流 //用于在本地保存数据的代码Iphone 从url本地保存音频,以便以后播放,iphone,ipad,Iphone,Ipad,如何将url中的音频保存到本地以便以后播放。我可以使用avplayer流式播放音频,但无法在本地保存并稍后播放。我尝试使用AVURLASET。有人能帮我吗 这是我试图在本地保存的代码: 在这里,我使用avplayer播放音频流 //用于在本地保存数据的代码 请发布您的代码。您可以将音频存储在文档目录中,以便以后播放。当你想播放它时,只需将该路径作为音频url。谢谢你的回复。@ShahPaneri:你是对的。但我无法获取要保存的流数据。它正在avplayer中播放。是否仍然可以从avpalyer获
请发布您的代码。您可以将音频存储在文档目录中,以便以后播放。当你想播放它时,只需将该路径作为音频url。谢谢你的回复。@ShahPaneri:你是对的。但我无法获取要保存的流数据。它正在avplayer中播放。是否仍然可以从avpalyer获取数据??
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:@"status"])
{
AVPlayerItem * item = (AVPlayerItem *)object;
if (item.status == AVPlayerItemStatusReadyToPlay)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *myPathDocs = [documentsDirectory stringByAppendingPathComponent: @"audio.m4a"];
asset=player.currentItem.asset;
NSURL *url1 = [NSURL fileURLWithPath:myPathDocs];
// 5 - Create exporter
AVAssetExportSession *assetEx = [[AVAssetExportSession alloc] initWithAsset:player.currentItem.asset presetName:AVAssetExportPresetAppleM4A];//tried with asset2 also
assetEx.outputURL=[NSURL fileURLWithPath:myPathDocs];
assetEx.outputFileType = AVFileTypeAppleM4A;
assetEx.shouldOptimizeForNetworkUse = YES;
[assetEx exportAsynchronouslyWithCompletionHandler:^{
int status = assetEx.status;
dispatch_async(dispatch_get_main_queue(), ^{
[self exportDidFinish:assetEx];
});
}];
}
}
}
but there is no file created in the documents directory.