帮助大家:)我已经尝试了一切,以获得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];
}
歌曲本身就在项目文件中,我真的不知道我做错了什么。
答案 0 :(得分:0)
检查错误并尝试
-(IBAction) playAudio{
NSError *error;
NSURL *url = [NSURL fileURLWithPath:self.audioName];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.delegate = self;
if (error)
NSLog(@"Error: %@", [error localizedDescription]);
else
[audioPlayer play];
}