【发布时间】:2014-03-03 02:33:34
【问题描述】:
我正在使用最新的 Xcode,Xcode 5.0.2,我用 iPad Simulator 7.0 测试它,我的音频文件 是 m4a,在我的 iPad 上用 GarageBand 导入和编写的,但是当我尝试播放它时,它运行了 nil,我将 AVFoundation.framework 导入到我的项目中,这里是 .h 文件
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface NastyCansViewController : UIViewController
{
AVAudioPlayer *audioPlayer;
}
@end
这是 .m 文件。我使用 NSLog 来查看我的 audioPlayer 是否为 nil。
- (void)viewDidLoad
{
NSURL *songURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/song.m4a"], NSBundle mainBundle] resourcePath];
NSError * error
audioPlayer = [[AVAudioPlayer alloc] initWithContentOfURL:songURL error:&error];
if (audioPlayer == nil) {
NSLog(@"audioPlayer is nil");
}
}
当我运行应用程序时,出现 NSLog 并显示“audioPlayer is nil” 我也尝试了很多其他代码,但我得到的都是零,请帮忙,谢谢
【问题讨论】:
-
在您尝试创建
AVAudioPlayer后是否设置了error?如果是这样,它告诉你什么?
标签: ios iphone avaudioplayer null