iOS 断点续传 下载音频 读取音频 访问链接

- (IBAction)Downfrequencybutton:(id)sender {
    NSURL *url = [NSURL URLWithString:??????????];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    request.downloadProgressDelegate = self;
    request.delegate = self;
    [request startAsynchronous];
    //下载存储路径

    NSString *nowDownDirectory = [mainDelegate.documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.ququer",mainDelegate.nowNews.nId]];

//临时存储路径

    NSString *tempDirectory = [mainDelegate.documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.temp",mainDelegate.nowNews.nId]];
    
    
    [request setDownloadDestinationPath:nowDownDirectory];
    [request setTemporaryFileDownloadPath:tempDirectory];
    [request setAllowResumeForFileDownloads:YES];//断点续传
}

//这个方法可以返回下载的状态 以后对写状态条有很大帮助
-(void)setProgress:(float)newProgress{
    NSLog(@"%f",newProgress);
    
}

-(void)requestFinished:(ASIHTTPRequest *)request{
    // Use when fetching binary data
    NSData *responseData = [request responseData];
    NSLog(@"responseData:%@",responseData);
}

- (void)requestFailed:(ASIHTTPRequest *)request
{
    NSError *error = [request error];
    NSLog(@"error:%@",error);

}
//音频播放
- (IBAction)playerButton:(id)sender {
    NSString *nowDownDirectory = [mainDelegate.documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.ququer",mainDelegate.nowNews.nId]];
    
    NSURL *url = [NSURL fileURLWithPath:nowDownDirectory];
    player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
    player.delegate=self;
    [player prepareToPlay];
    //播放
    [player play];
    
    
}
//访问链接
- (IBAction)newsLinkButton:(id)sender {
    //NSString *newslinkUrl=self.newslinkbutton.titleLabel.text;
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:XXXXXXXXXXXXXXXXXXXXXXXXXXX]];
    
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值