0
我正在使用AVAudioPlayer来管理一些声音,但isPlaying方法似乎崩溃了。AVAudioPlayer正在播放崩溃的应用程序
当我开始做页:
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是很空的现在:
soundclass.h
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
#import<AVFoundation/AVFoundation.h>
@interface SoundClass : AVAudioPlayer <AVAudioPlayerDelegate> {
}
@end
SoundCl ass.m
#import "SoundClass.h"
@implementation SoundClass
-(void)dealloc {
[super dealloc];
}
@end
你在这里看到什么我可能会做错吗?它崩溃在if (isPlaying)
嗯,当我开始时,程序还没有被告知要玩什么,我可以初始化什么?或者我应该加载一些东西?如果我改变剪辑,我只是重新initWithContentsOfURL? – emachine 2010-10-04 19:47:54
在这种情况下,将其设置为零。这通常是在你的类的init ...方法(“self”指向这种情况的实例的类)中完成的。 – 2010-10-04 19:52:04
so self.soundClass = nil?这不是设置它被删除? – emachine 2010-10-04 20:01:22