0
我見過有關AVAudioPlayer但諾內斯相當多的職位幫助:我不能播放聲音了(即使它用於升級到8.3.2之前的Xcode工作)的ObjectiveC AVAudioPlayer量爲0
這裏是我的代碼:
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
,但其上的任何操作只會改變系統音量。
試試這個'AVAudioSession * audioSession = [AVAudioSession sharedInstance] [audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];' –
@pawan:上面的發佈代碼已經設置了AVaudiosession,我很樂意嘗試你的建議,但它在哪裏改變了一些東西? – toto