帮助大家:) 我已经尽一切努力让 AVAudioPlayer 的音频在我的应用程序中工作。由于某种原因,它不会在 iPhone 模拟器上播放。代码如下——
#import "ViewController.h"
#import "AVFoundation/AVFoundation.h"
@interface ViewController ()
{
AVAudioPlayer *avPlayer;
}
@end
@implementation ViewController
@synthesize myProgressView;
@synthesize sliderVolumeOutlet;
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *stringPath = [[NSBundle mainBundle]pathForResource:@"audioapp" ofType:@"mp3"];
NSURL *url = [NSURL fileURLWithPath:stringPath];
NSError *error;
avPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:&error];
[avPlayer setNumberOfLoops:1];
[avPlayer setVolume:self.sliderVolumeOutlet.value];
[NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(updateProgress) userInfo:nil repeats:YES];
}
歌曲本身在项目文件中,我真的不知道我做错了什么。