ObjectiveC AVAudioPlayer 音量为 0

ObjectiveC AVAudioPlayer volume is 0

我看过很多关于 AVAudioPlayer 的帖子,但没有帮助:我再也听不到声音了(尽管在升级到 8.3.2 之前它曾与 Xcode 一起使用)

这是我的代码:

AVAudioPlayer *audioPlayerObj;
AVAudioSession *session;
[...]
- (IBAction)playSound:(id)sender {
audioPlayerObj.delegate = self;

if(playButton.isSelected){        
    playButton.selected=NO;
    (void) [audioPlayerObj stop];
}
else{
    session = nil;
    {NSError * _error;

        session = [AVAudioSession sharedInstance];
        [session setCategory:AVAudioSessionCategoryPlayback
                       error:&_error];
        [session setActive:YES error:&_error];
        if(_error !=nil)
        {   NSLog(@"could not init the audio player session %@ ", _error);
        }

    }

    NSString * tune =[NSString stringWithFormat:@"%@.wav",[pickerViewArray objectAtIndex:[pickerView selectedRowInComponent:0]]];
    NSString *path =[[NSBundle mainBundle] pathForResource:tune ofType:@""];

    NSURL * actualFilePath= [NSURL fileURLWithPath:path];
NSError *error;

(void)[audioPlayerObj initWithContentsOfURL:actualFilePath error:&error];

    [audioPlayerObj prepareToPlay];


    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0"))
    {
    [audioPlayerObj setVolume:0.99 fadeDuration: 1];

    }
    NSLog(@"syst volume : %f", [session outputVolume]);
    NSLog(@"vol : %f\n",[audioPlayerObj volume] );

if(error !=nil)
{   NSLog(@"could not init the audio player %@ ", error);
    audioPlayerObj=nil;

}
else
{
    (void) [audioPlayerObj setNumberOfLoops:-1  ];
    (void) [audioPlayerObj play];
    NSLog(@"playing with vol : %f\n",[audioPlayerObj volume] );
    [audioPlayerObj setVolume:0.99 fadeDuration: 1];
    playButton.selected=YES;
}
}

`

输出是 syst volume : 0.476119 vol : 0.000000 playing with vol : 0.000000 任何有关如何提高音量的提示都将不胜感激。该视图也有一个 MPVolumeView,但对其进行的任何操作只会更改系统音量。

错误在这里:

(void)[audioPlayerObj initWithContentsOfURL:actualFilePath error:&error];

应该是:

 audioPlayerObj = [[AVAudioPlayer alloc] initWithContentsOfURL:actualFilePath error:&error];