简体   繁体   中英

Play mp3 files with AVAudioPlayer with PlayAndRecord category?

Hi I have a setup that records audio (with AVAudioSessionCategoryPlayAndRecord category), now I want to playback and MP3 file as usual with AVAudioPlayer instance, but no any sound can be hear.

AVAudioPlayer do not throw any error, nor in its delegate callbacks.

Has anybody similar experience? How to overcome this?

Please use this -

 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;
               } 

And tell me if it is working or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM