我正在使用 AVFoundation 播放 wav 文件。但我无法让它播放。也没有出现错误或警告。
XCode 是 4.2,设备是 iOS 5。
- (IBAction) playSelectedAlarm:(id)sender {
UIButton *button = (UIButton *)sender;
int bTag = button.tag;
NSString *fileName = [NSString stringWithFormat:@"%d23333", bTag];
NSLog(@"%@", fileName);
NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"wav"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: path];
AVAudioPlayer *theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:NULL];
theAudio.volume = 1.0;
theAudio.delegate = self;
[theAudio prepareToPlay];
[theAudio play];
}
这是解决方案;
我在头文件中设置了 AVAudioPlayer ..
@property(非原子,保留)AVAudioPlayer *theAudio;
我想“保留”解决了我的问题。因为在我发送“play”之后,它会发送“release”来平衡分配。当 AVAudioPlayer 被释放时,它会停止播放音频。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)