我已经跟踪了我能找到的每一种资源,而且我不知道为什么这不起作用。我试图在模拟器上播放它。此外,我已经验证我的urlString是准确的,并且它粘贴到浏览器时播放。我错过了什么?
.h文件
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface MyViewController : UIViewController <AVAudioPlayerDelegate>
@end
.m文件
@interface SessionsListViewController ()
@property (strong, nonatomic) AVAudioPlayer *audioPlayer;
@end
- (void) viewDidLoad
{
NSString *urlString = [NSString stringWithFormat:@"%@%@", AUDIO_URL, @"test.mp3"];
NSURL *url = [NSURL URLWithString:urlString];
NSError *err = nil;
self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&err];
[self.audioPlayer prepareToPlay];
[self.audioPlayer setDelegate:self];
self.audioPlayer.volume = 1.0;
[self.audioPlayer play];
}