0
我有一个问题。以下代码无法管理播放任何内容。根据编译器没有错误。我已经建立了必要的联系。事实上,如果我使用AudioServicesPlaySystemSound
,而不是AVAudioPlayer
,那么一切正常。如果有人能帮助我,我会很高兴。因为我需要为我的项目使用AVAudioPlayer,并且我尝试了我所知道的一切。AVAudioPlayer不会工作
感谢
.h文件中
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>
@property(strong,nonatomic) AVAudioPlayer *audioPlayer;
- (IBAction)cal:(id)sender;
.m文件
- (IBAction)cal:(id)sender {
NSString *path = [[NSBundle mainBundle] pathForResource:@"demo" ofType:@"mp3"];
NSURL *pathURL = [NSURL fileURLWithPath : path];
audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:pathURL error:nil];
[audioPlayer play];
}