• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

iphone - 音频文件在 iPhone 5 中无法播放

[复制链接]
菜鸟教程小白 发表于 2022-12-12 13:23:14 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我使用一个代码来播放 .caf 音频文件,相同的代码在 iPhone 4s 和 iPad 2 上运行良好,但在 iPhone 5 上根本无法播放...

这是代码:

-(IBAction)checkSoundid)sender
 {
    NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat"%@/Lunatic.caf", [[NSBundle mainBundle] resourcePath]]]; 

NSLog(@"%@",url);

NSError *error;

self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];

self.audioPlayer.numberOfLoops = 0; 

self.audioPlayer.volume = 1; 


NSLog(@"log audioplayer: %@",audioPlayer);

if (audioPlayer != nil)
{
    [self.audioPlayer prepareToPlay];
    [self.audioPlayer play];
}


if (audioPlayer.playing == NO)
{
    NSLog(@"not playing, error: %@",error);
}


if([[NSFileManager defaultManager] fileExistsAtPath"file://localhost/var/mobile/Applications/0D3F5169-8DB1-4398-A09A-DB2FBADF57EF/myApp.app/Lunatic.caf"])
{
    NSLog(@"file exist");
}
else
{
    NSLog(@"file doesn't exist");
}


 }

这是日志输出:

2013-08-07 20:05:52.694 myApp[7006:907] file://localhost/var/mobile/Applications/0D3F5169-8DB1-4398-A09A-DB2FBADF57EF/myApp.app/Lunatic.caf 2013-08-07 20:05:52.697 myApp[7006:907] log audioplayer: (null) 2013-08-07 20:05:52.701 myApp[7006:907] not playing, error: Error Domain=NSOSStatusErrorDomain Code=-43 "The operation couldn’t be completed. (OSStatus error -43.)" 2013-08-07 20:05:52.703 myApp[7006:907] file doesn't exist

如您所见,音频播放器日志给出“null”,错误日志显示错误 -43.... 但我再说一遍...... iphone 4s 一切正常......

任何线索为什么会发生这种情况?他们是否对 iPhone 5 中的音频进行了一些更改?会不会是我的 iPhone 5 中的设置阻止了声音播放?任何帮助将不胜感激



Best Answer-推荐答案


在调用 play 之前,您是否调用了 [audioPlayer prepareToPlay]?您是否还仔细检查了 audioRoutes 以确保它在正确的 channel 中播放?

两个良好的健全性检查是:

1.) 调用 [audioPlayer isPlaying] 并在调用 play 后查看它是否返回 yes 或 no。

2.) 设置 AVAudioPlayerDelegate 并等待 audioPlayerDidFinishPlaying: 上的回调,看看它是否在您的音频长度之后被调用。

http://developer.apple.com/library/ios/#documentation/AVFoundation/Reference/AVAudioPlayerClassReference/Reference/Reference.html

编辑: 由于您的文件实际上没有播放,这很可能意味着您调用的路径有问题。

使用 NSLog 打印出您的路径,并使用以下命令检查文件是否实际存在:

if([[NSFileManager defaultManager] fileExistsAtPath:yourPath])
{

}

关于iphone - 音频文件在 iPhone 5 中无法播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18109273/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap