0
我一直在使用以下代码来检测iPhone无声按钮状态,但它有时可以正常工作,但通常不工作。我搜索了很多,但不能找出解决方案。如何在iOS6中检测iPhone无声按钮状态
- (空)playWordSoundWithFile:(的NSString *)文件路径{
audioPlayer = nil;
if (filePath) {
NSArray *list = [filePath componentsSeparatedByString:@"."];
if (list && [list isKindOfClass:[NSArray class]] && [list count] > 1) {
//audioPlayer = [self audioPlayerWithFile:[list objectAtIndex:0] andExtension:@"mp3"];//[list objectAtIndex:1]
NSString *soundFileIs=[NSString stringWithFormat:@"%@.%@",[list objectAtIndex:0],[list objectAtIndex:1]];
NSString *paths = [[NSBundle mainBundle] resourcePath];
NSString *audioFile = [paths stringByAppendingPathComponent:soundFileIs];
NSData *cdata =[NSData dataWithContentsOfFile:audioFile];
NSLog(@"Sound file %@",soundFileIs);
audioPlayer = [[AVAudioPlayer alloc] initWithData:cdata error:nil];
audioPlayer.delegate = self;
}
}
if (audioPlayer) {
[audioPlayer setVolume:1.0];
playerId = 16;
[audioPlayer play];
}
}
你想实现什么? – IronManGill
其实问题是当我播放声音,然后切换iPhone静音声音继续播放它不会去静音这就是为什么马试图这样做。 –
我已经发布了用于播放声音的代码。 –