好吧现在我试图让滑块上的音量改变
这是代码
@implementation MainerViewController
@synthesize fxVolumeSlider;
- (IBAction)pushPlay:(id)sender; {
NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"wav"];
if (theAudio) [theAudio release];
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];
volumeTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(updateVolume) userInfo:nil repeats:YES];
}
-(void)updateVolume {
[theAudio setVolume:fxVolumeSlider.value];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Setup custom slider images
UIImage *minImage = [UIImage imageNamed:@"grey_track.png"];
UIImage *maxImage = [UIImage imageNamed:@"white_track.png"];
UIImage *tumbImage= [UIImage imageNamed:@"metal_screw.png"];
minImage=[minImage stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
maxImage=[maxImage stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
// Setup the FX slider
[fxVolumeSlider setMinimumTrackImage:minImage forState:UIControlStateNormal];
[fxVolumeSlider setMaximumTrackImage:maxImage forState:UIControlStateNormal];
[fxVolumeSlider setThumbImage:tumbImage forState:UIControlStateNormal];
fxVolumeSlider.minimumValue = 0.0;
fxVolumeSlider.maximumValue = 1.0;
fxVolumeSlider.continuous = YES;
//fxVolumeSlider.value = [sharedSoundManager fxVolume];
// Attach an action to sliding
[fxVolumeSlider addTarget:self action:@selector(fxSliderAction:) forControlEvents:UIControlEventValueChanged];
// Cleanup
minImage = nil;
maxImage = nil;
tumbImage = nil;
}
- (void) fxSliderAction:(id)sender {
[theAudio setFxVolume:fxVolumeSlider.value];
}
但我现在收到此错误
警告:'AVAudioPlayer'可能无法响应'-setFxVolume:'
因此,每当我播放播放按钮时,我都会尝试调整音量,但我会被踢出应用
答案 0 :(得分:1)
检查声明中的下划线。在.h文件中,您有:
IBOutlet UISlider *_fxVolumeSlider;
你应该:
IBOutlet UISlider *fxVolumeSlider;
此外,在.m文件中,编辑行
@synthesize _fxVolumeSlider;
是
@synthesize fxVolumeSlider;
关于修订后的问题:
- (void) fxSliderAction:(id)sender {
[theAudio setFxVolume:fxVolumeSlider.value];
}
应改为读作
- (void) fxSliderAction:(id)sender {
[theAudio setVolume:fxVolumeSlider.value];
}
注意拼写错误(并在张贴前查找!)
答案 1 :(得分:1)
您已将ivar和属性声明为_fxVolumeSlider
,但您在方法中使用的是fxVolumedSlider
。两者都不一样。您应该使用_fxVolumeSlider
或您可能意味着将该属性声明为
@property(retain, nonatomic) IBOutlet UISlider *fxVolumeSlider;
并使用
进行合成@synthesize fxVolumeSlider = _fxVolumeSlider;
但即便如此,你也不能将其用作fxVolumeSlider
。您可以将其用作self.fxVolumeSlider
或_fxVolumeSlider
。如果您想将其用作普通fxVolumeSlider
,则应将所有_fxVolumeSlider
替换为fxVolumeSlider
。