1
我试图对象didSelectedIndex
UITableViewController
IPhone,音频MP3或M4A等音频文件播放没有声音
音频文件与扩展m4a
文件内播放声音的方法,但我也试图与MP3文件和结果不会改变。
下面我发布,我在TableViewController的方法已经实现了代码:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *soundFilePath = [NSString stringWithFormat:@"%@/testaudio.m4a", [[NSBundle mainBundle] resourcePath]];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
NSLog(@"soundFileURL %@",soundFileURL);
NSError *error;
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:&error];
if(!player){
NSLog(@"ERRORE: %@",error);
}
[player setDelegate:self];
[player prepareToPlay];
[player play];
}
我也试过直接在设备上,它仍然不能播放任何声音。
我还添加了类AVSession如下:
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setActive:YES error:nil];
结果并没有改变,没有人知道是什么问题?
很好...现在播放声音 – macuser