我使用NSURLConnection的从服务器上下载的MP3文件,我的代码是使用NSURLConnection下载的内容不显示在我的iPhone上?
- (IBAction)download:(id)sender
{
NSURL *url = [NSURL URLWithString:@"http://viadj.viastreaming.net/start/psalmsmedia/ondemand/Nin%20snehamethrayo.mp3"];
NSLog(@"%@", url);
NSURLRequest *theRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];
receivedData = [[NSMutableData alloc] initWithLength:0];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self startImmediately:YES];
}
- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[receivedData setLength:0];
}
- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[receivedData appendData:data];
}
- (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[connection release];
}
- (NSCachedURLResponse *) connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse
{
return nil;
}
- (void) connectionDidFinishLoading:(NSURLConnection *)connection
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [[paths objectAtIndex:0]stringByAppendingPathComponent:@"myFile.mp3"];
[receivedData writeToFile:documentsDirectoryPath atomically:YES];
[connection release];
}
当我点击下载按钮,将活动的指标开始动画和一段时间(我认为这是下载)后停止。但在此之后,我无法在我的iPhone磁盘上找到下载的文件。实际上这些文件在下载后存储在哪里 我编辑了我的info.plist来支持iTunes文件共享。
是他们对这段代码的任何错误?或者为什么我看不到下载的文件?
此文件实际下载到哪里?文件目录?抱歉,我只是一个初学者,让我问一下如何从文档目录中检索文件?或者我可以下载文件到我的本地iPhone驱动器,以便我可以在下载后播放! –
@NeerajNeeru,看到你的Mac文件中的文件,甚至你连接iPhone与Mac ...路径上的文件位置/用户/ mac用户名/库/应用程序支持/ iPhone模拟器/ 5.0 /应用程序/ urAppBundleID /文件 – Tirth
@NeerajNeeru,是你也可以使用文件目录路径播放该文件给Audioplayer – Tirth