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.
Related
I read Similar questions like this question
I have an app that should access to recorded sound (with voice Memos or other Recording apps) - I don't want to record sound in my app - I just want to access the recorded sound - I know that there are some limits in Ios for doing this But I think It is possible please help me
Remember That I read Similar questions But My question is different because I don't want to record sounds in my app
Why don`t you try to use AVAudioPlayer of AVFoundationFramework?
You could also try some third-party framework like SwiftySound
https://github.com/adamcichy/SwiftySound
Just to mention: there is also a plenty of system sounds which is sometimes quite useful.
You can see the list at the following link
https://github.com/TUNER88/iOSSystemSoundsLibrary
You can play them by implementing AudioToolbox framework in your project.
Add this into a file (if you are using Objective-c)
#import <AudioToolbox/AudioToolbox.h>
Then run AudioServicesPlaySystemSound(PUT_SOUND_ID_HERE); somewhere.
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
This question already has an answer here:
Audio Information of Current Track iOS Swift
(1 answer)
Closed 6 years ago.
How can I access another app's currently playing audio - the actual audio item but metadata is welcome too. I can see that this question has been asked a lot but with few solutions being offered over the years. I understand apple's philosophy for probably not wanting an app to be able to do this. I also understand that such a request is probably outside of the iOS API. With that being said, I would really like some kind of solution.
Logically, I feel that
MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo
should return the info for whatever is currently playing; however, as others have mentioned, this value is always nil for audio being played outside of your app. Notably, popular audio apps seem to fail to use the MPNowPlayingInfoCenter class, making such audio fail to appear.
If using the default music app, one can use
MPMusicPlayerController.systemMusicPlayer().nowPlayingItem
However, what is a more consistent way to access audio playing through the podcasts app, Spotify, Pandora, Safari, etc?
Has anyone found a solution to this? Are there any old Objective-C frameworks that support this functionality?
One approach might be viable if there is there some way I can access the audio path of the item currently being played. For example, if I could get the path of the currently playing item, I could create an AV object from it:
AVAudioPlayer(contentsOfURL: audioUrl)
So is there a way I can get the audio url of the currently playing item and use it that way?
Is another approach better?
If a native solution does not exist, is it possible to bodge something together for it to work? Any advice or ideas welcome.
Edit: I don't believe anybody has been able to achieve this; however, I think a lot of people would like to. If this has been addressed, please link it! :)
This isn't currently possible in iOS. Just changing your AVAudioSession category options to .MixWithOthers, what will be an option to get info Song Info from other apps, causes your nowPlayingInfo to be ignored.
iOS only considers non-mixing apps for inclusion in MPNowPlayingInfoCenter, because there is uncertainty as to which app would show up in (e.g.) Control Center if there are multiple mixing apps playing at the same time.
Proposal: An option would be to use a music fingerprinting algorithm to recognize what is being played by recording it from your App.
Some interesting projects in this direction:
Gracenote https://developer.gracenote.com/ Gracenote (which is owned by Sony) has opened up it's SDKs and APIs and has a proper dev portal.
EchoNest & Spotify API http://developer.echonest.com/ Fusioned with Spotify since March 2016
ACRCloud https://www.acrcloud.com/ offers ACR solutions for custom files such as TV commercials, music tec
I'm in the process of building an app that uses the IPod Library Access API, so that I can play songs from iTunes in the app. However I also need to access the audio data of whatever song is playing, like how a music visualizer would.
So far, looking through the Audio Session documentation and the Core Audio documentation, I haven't found any officially supported means of achieving this. As I understand it, it would require accessing audio data from another audio session, as in the iPod access api, technically iTunes is playing in the background as I understand it and thus has a different audio session.
So basically how can you access audio data from another audio session? Specifically getting the audio data of songs played through the iPod Access API?
See the AudioTapProcessor iOS Sample sample app in Apple's iOS Developer Library (sign on required), for the use of the AVFoundation MTAudioProcessingTap API.
I am using UIImagePickerController for recording video in one of my application. i have successfully Recorded video. But now i want to mute mic (video without audio) while recording video.
i have searched Alot but not a single clue about it.
please help me about this issue.
is it possible or not. if possible than how.
thanks in advance.
If you want your app to be in app store , then there is no apple approved method to actually mute whole iPhone.There are certain libraries but they are not approved.
Apple's documentation on Audio Session
According to the documentation you can only ask the user to have the phone silenced physically and you can respond to certain audio changes such as other sounds,phone calls, email sounds but you cannot mute programmatically.
Also See this Documentation on Programming in iPhone See the part 3.3 for Audio.(Events that can be accessed and performed in iOS).
You can use AVFoundation framework to record a video without the sound, check at this :
AVFoundation Programming Guide