Difference between AV Foundation framework and Media Player framework - ios

Audio and video files can be played using AV Foundation framework and Media Player framework.
What is the better choice when I just want to play the media file?
With Media Player framework, we can access the iPod library, and can find and play audio-based media items synced from iTunes on the desktop.
With AVFoundation, we can examine, create, edit, or reencode media files.

When you want to much customization then it is better to use AVFoundation for example AVPlayer. You can totally customize player, audio, sessions etc. so, it is better to use AVPlayer instead of MPMoviePlayerController when lot's of customization requires.
MPMoviePlayerController are very easy to implements compare to AVPlayer.
MPMoviePlayerController:
You have to set controlStyle to MPMovieControlStyleNone, set up Timer because currentPlaybackTime is not KVO compliance
AVPlayer:
AVPlayer has no built in controls, but it has addPeriodicTimeObserverForInterval:queue:usingBlock: that makes handling the current time easily. The nicer thing about periodTimeObserver is that “The block is also invoked whenever time jumps and whenever playback starts or stops”
etc etc.
You can refer this document for more details and better understanding.
Hope this will help :)

Media Player framework:
This high-level framework provides easy access to a user’s iTunes library and support for playing tracks and playlists. Use this framework when you want to integrate audio into your app quickly and when you don’t need to control playback behavior.
AV Foundation:
AV Foundation is an Objective-C interface for managing the recording and playback of audio and video. Use this framework for recording audio and when you need fine-grained control over the audio playback process.
https://developer.apple.com/library/content/documentation/Miscellaneous/Conceptual/iPhoneOSTechOverview/MediaLayer/MediaLayer.html

Related

ios Can I use MPMoviePlayerController to play .mp3 url

My app needs to play some music files, like .mp3. I would like to use MPMoviePlayerController because it has implemented all the UI stuff for me, i.e. I do not want to bother implementing progress slide bar and things like this.
I tested to use it to play a .mp3 file and it worked fine but I do not know if it is fine to use it to do this because its name says "movie player" and it seems it is supposed to play a movie. Would apple reject this? Thank you.
For playing audio from a file or memory, AVAudioPlayer is your best option but unfortunately it doesn't support a network stream while MPMoviePlayerController can
From documentation :
An instance of the AVAudioPlayer class, called an audio player,
provides playback of audio data from a file or memory.
Apple recommends that you use this class for audio playback unless you
are playing audio captured from a network stream or require very low
I/O latency.
For the Apple validation I don't think that your application can be rejected because you're using the Media Player Framework to play an audio file. In fact here they explicitly say that you can do just that:
Choose the right technology for your needs:
To play the audio items in a user’s iPod library, or to play local or
streamed movies, use the Media Player framework. Classes in this
framework automatically support sending audio and video to AirPlay
devices such as Apple TV.
Not sure about performance and memory issues though!
Best of luck.

Does Media Player Framework need audio sessions to be managed?

I'd like to include a simple media player in my iOS 7+ app, and I've found some posts dealing with Media Player Framework and the MPMusicPlayerController, and I think that can meet my needs. However, I couldn't find the related documentation in Apple's docs, and instead I found that there are several frameworks related to managing audio in iOS apps.
I've taken a look into the Core Audio Overview and the "Sound" section in iOS Human Interface Guidelines, and I need to clarify if it is also needed to manage audio sessions when using Media Player Framework.
Thanks in advance
I finally found the answer in the Audio Session Programming Guide:
If your app is using a movie player only, or a music player only—and you are not playing your own sounds—then you should not configure an audio session.

iPhone - What's the right audio player for my app?

I'm designing a music app that plays music from the user's iPhone music library and I'm having problems figuring out which audio player is the right one to use for it (AVAudioPlayer, AVPlayer, or MPMusicPlayer).
My app needs to do the following:
Play music from the iPhone music library
Control app music volume separately from device/system volume
Continue to play app music when app moves to background
Catch events when song changes to next song or finishes
From my research it seems like each of the three audio players mentioned above do SOME of the tasks required for my app, but none of them do ALL of them. AVPlayer seems to get the closest, except its volume is dependent on the device/system volume.
Does anyone have any recommendations or workarounds to accomplish this? I've been wracking my brain over this for quite some time so any help at all would be appreciated.
EDIT
The MPMusicPlayerController class does not actually support playing background audio when getting an instance of it via + applicationMusicPlayer. The best option, then, is to simply use MPMusicPlayer to query the iPod music library. Once a song is selected by the user, the resulting MPMediaItem can be queried for it's asset URL and fed into AVPlayer's +playerWithURL, giving you full control of playback parameters.
--
I would recommend MPMusicPlayerController.
MPMusicPlayerControllerhandles the low-level details of playing audio files in the iTunes library.
You can use the class method -applicationMusicPlayer to get a local copy of the iPod singleton; from there, you can control its volume by setting its volume property for just your application.
I would assume MPMusicPlayerController has background audio support already built in. If it doesn't, you can change your app's audio session context to make it work (see Playing background audio in http://www.sagorin.org/2011/11/29/ios-playing-audio-in-background-audio/)
You can setup any object you choose to be a KVO observer of your application-specific MPMusicPlayerController object. This way, you can be notified whenever the nowPlayingItem property is changed.
Hopefully this high-level description suffices. Let me know if you need any further clarification.

Playing a .mov file without UIWebView or MPMoviePlayer

I am trying to play a video file with the .mov extension. It is not playing the video in my MPMoviePlayerController. I need to play this type of file in my application. Is it possible to play a video file without using MPMoviePlayerController or UIWebView?
Please anyone suggest me in this issue.
Thanks in Advance
I've never used it directly before, but take a look at the AVPlayer Class Reference.
Under the "Overview", you'll see:
You use an AVPlayer object to implement controllers and user
interfaces for single- or multiple-item playback. The multiple-item
case supports advanced behaviors.
If you look at the AV Foundation Programming guide (linked here), you'll see Apple builds the Media Player upon AV foundation.

How do you playback live audio in an iPhone?

Say you want to playback exactly what the iPhone mic is picking up in real-time. Which framework/class would be used?
You'll need to use the Core Audio framework for this. Specifically, look into audio graphs, audio units, and RemoteIO. Plenty of sample code for those to get you started.

Resources