[英]Play mp3 files with AVAudioPlayer with PlayAndRecord category?
嗨,我有一個錄制音頻的設置(帶有AVAudioSessionCategoryPlayAndRecord類別),現在我想像往常一樣使用AVAudioPlayer實例播放和MP3文件,但是聽不到任何聲音。
AVAudioPlayer不會在其委托回調中引發任何錯誤。
有沒有類似的經歷? 如何克服呢?
請使用這個-
NSString *docDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
filePath = [NSString stringWithFormat:@"%@/%@.mp3", docDirPath , @"Welcome"];
NSError *error;
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
avPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&error];
if (avPlayer == nil)
{
NSLog(@"AudioPlayer did not load properly: %@", [error description]);
}
else
{
[avPlayer play];
avPlayer.delegate=self;
}
並告訴我它是否有效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.