MapMapM
MapMapM
采纳率79.6%
2013-03-20 03:00

服务器的音频文件不播放

从服务器中直接播放音频文件时它不播放,如果先播放本地文件再播放服务器的就可以。

    //NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/audiofile.mp3", [[NSBundle mainBundle] resourcePath]]];

NSURL *url = [NSURL URLWithString:@"http://celeritas-solutions.com/pah_brd_v1/productivo/1.mp3"];


NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = -1;

if (audioPlayer == nil)
    NSLog([error description]);             
else 
    [audioPlayer play];
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • love_loveec love_loveec 8年前
    AVPlayer * player = [AVPlayer playerWithURL:[NSURL URLWithString:@"YOUR URL"]];
    [player play];
    

    这样看看

    点赞 评论 复制链接分享
  • xinyoulingxi1_tong xinyoulingxi1_tong 8年前

    这段代码应该可以帮你

    NSData *_objectData = [NSData dataWithContentsOfURL:[NSURL URLWithString:http://celeritas-solutions.com/pah_brd_v1/productivo/1.mp3]];
    NSError *error;
    
    audioPlayer = [[AVAudioPlayer alloc] initWithData:_objectData error:&error];
    audioPlayer.numberOfLoops = 0;
    audioPlayer.volume = 1.0f;
    [audioPlayer prepareToPlay];
    
    if (audioPlayer == nil)
        NSLog([error description]); 
    else
        [audioPlayer play];
    
    点赞 评论 复制链接分享