(iOS)为什么AVAudioPlayer initWithContentsOfURL总是失败并显示错误代码= -43 [英] (iOS) Why does AVAudioPlayer initWithContentsOfURL always fail with error code=-43

查看:81
本文介绍了(iOS)为什么AVAudioPlayer initWithContentsOfURL总是失败并显示错误代码= -43的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NSString *songNameEscaped = [songName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];    
NSURL *songURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", @"http://somerootpath/Music/", songNameEscaped]];

NSLog(@"songURL = %@", songURL);
NSError *avPlayerError = nil;

AVAudioPlayer *avPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:songURL error:&avPlayerError];
if (avPlayerError)
{
    NSLog(@"Error: %@", [avPlayerError description]);
}
else
{
    [avPlayer play];
}

如果我从NSLog(@"songURL = %@", songURL);复制NSLog输出并将其粘贴到safari中,则Quicktime插件不会播放文件,因此我知道URL有效.我尝试使用.m4a.mp3文件,并尝试从songName中删除空格,但是不管我总是得到什么错误:

If I copy the NSLog output from NSLog(@"songURL = %@", songURL); and paste it in safari, Quicktime plugin plays the files no problem so I know the URLs are valid. I've tried with .m4a and .mp3 files and have tried removing the spaces from songName but not matter what I always get Error:

Error Domain = NSOSStatusErrorDomain代码= -43操作无法完成.(OSStatus错误-43.)".

Error Domain=NSOSStatusErrorDomain Code=-43 "The operation couldn’t be completed. (OSStatus error -43.)".

但是它们只是在iTunes中创建的标准.m4a/.mp3文件.

But they are just standard .m4a / .mp3 files created in iTunes.

推荐答案

显然,AVAudioPlayer不支持流媒体. Apple建议为此使用AVPlayer,尽管它不便于查找当前时间和持续时间之类的东西.

Apparently AVAudioPlayer doesn't support streaming. Apple recommends AVPlayer for this although it is not as conveinient for finding things like current time and duration .

这篇关于(iOS)为什么AVAudioPlayer initWithContentsOfURL总是失败并显示错误代码= -43的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆