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