【发布时间】:2010-10-04 19:23:15
【问题描述】:
我正在使用 AVAudioPlayer 来管理一些声音,但 isPlaying 方法似乎崩溃了。
在我启动页面时完成:
self.soundClass = [AVAudioPlayer alloc];
我如何播放声音:
-(void)playSound:(NSString *)fileName:(NSString *)fileExt {
if ( [self.soundClass isPlaying] ){
[self.soundClass pause];
}
else if (newSoundFile == currentSoundFile) {
[self.soundClass play];
}
else {
NSLog(@"PlaySound with two variable passed function");
[[NSBundle mainBundle] pathForResource: fileName ofType:fileExt]], &systemSoundID);
[self.soundClass initWithContentsOfURL:[NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource: fileName ofType:fileExt]] error:nil];
[self.soundClass prepareToPlay];
[self.soundClass play];
}
self.currentSoundFile = fileName;
}
我的 soundClass 现在很空:
声音类.h
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
#import<AVFoundation/AVFoundation.h>
@interface SoundClass : AVAudioPlayer <AVAudioPlayerDelegate> {
}
@end
SoundClass.m
#import "SoundClass.h"
@implementation SoundClass
-(void)dealloc {
[super dealloc];
}
@end
你有没有看到我可能做错了什么?它在if ( isPlaying ) 处崩溃
【问题讨论】:
标签: objective-c xcode ipad ios4