在iPhone中下载歌曲时停止播放背景音乐

时间:2011-10-03 05:27:04

标签: iphone objective-c asihttprequest

我正在用asihttp请求下载歌曲 我的问题是当我点击网址下载歌曲,歌曲开始在我的视图中播放 我如何阻止这一点,我不希望下载时应播放歌曲 请帮忙

1 个答案:

答案 0 :(得分:0)

 obj.tagvalue=[sender tag];
NSString * tmp =[NSString stringWithString:[obj.ringArray objectAtIndex:obj.tagvalue]]; 
NSString *filename=[RingUrlArray objectAtIndex:obj.tagvalue];
NSLog(@"%@",filename);


NSURL *url=[NSURL URLWithString:tmp];
NSLog(@"url %@",url);
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];

NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];



NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"Song"];

if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
    [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:nil]; 

NSString *filePath =[NSString stringWithFormat:@"%@/%@.mp3",dataPath,filename];

NSLog(@"%@",filePath);
[request setDownloadDestinationPath:filePath];
[request  startAsynchronous]; 

UIAlertView *v=[[UIAlertView alloc] initWithTitle:@"Download Message " message:@"Your download has been started" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[v show];
[v release];