Question

I know how to play music file from library using MPMusicPlayerController, but I wonder if there's a way to play recorded audio file (.caf format) using the MPMusicPlayerController? I am recording and saving file into NSDocuments Directory. I google it around but couldn't find a way to do so? I can do the same using AVAudioPlayer. But want to do with MPMusicPlayerController. Any suggestions appriciated. Thanks.

Was it helpful?

Solution

Here is a post similar to what you are asking.

how to convert nsdata to MPMediaitem song iOS Sdk

Unfortunately MPMusicPlayer only plays songs from the iPod library, and third party apps cannot add to the library. I would suggest playing it with the MPMoviePlayerController as it can play audio-only files (as the answer on the other question suggests).

For example:

NSURL *audioPathURL = [NSURL fileURLWithPath:videoFilepath];
MPMoviePlayerController *audio;
audio = [[MPMoviePlayerController alloc] initWithContentURL:audioPathURL];
[audio play];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top