Say there are two apps on my iPhone. One is a music player developed by others, the other is developed by me. After my app interrupts the music player's audio session, I want to re-active its audio session without de-activating my app's audio session.
Two questions:
1. Is it workable?
If not, are there any other ways to finish the task?[I don't want to give up my audio session because my app should record all the time.]
In a word, is there other way to reactive interrupted audio session except running "setActive:NO" in current session?
Hope someone can help me. Thx
Related
I need the same behaviour as seen in SnapChat, but for a longer duration.
I already have an AVCaptureSession that records video and audio from the built-in microphone.
What I need is to also record music running in the background, i.e. from Spotify, Apple Music etc.
I assume there is two parts to this:
1) Setting the correct category on AVAudionSession (in order to allow background music while recording)
2) Setting some (custom?) input AVCaptureDevice to grap audio playing in the background.
But how do I do it?
Spotify, iTunes etc generally have the music encrypted and the keys protected via a DRM mechanism, so in theory you can't capture or record the music.
Even if you do find a workaround, without the rights for the music you will face copyright issues if this is for an app you want to make available to others, unfortunately.
I was wondering if there is a way the app could know if a user started to play music from the Music app or any other source (Spotify etc.). I am trying to do a specific function every time a user plays a song even if my app is not active. Is this even possible? Can I also retrieve the song information?
With AVKit you can make use:
AVAudioSession.sharedInstance().isOtherAudioPlaying
A Boolean value indicating whether another app is currently playing
audio.
Note that this will not work when your app is inactive. You canĀ“t do that and Apple will reject your app. You can only make this check if your app is active.
I want to know -- what happens to a user's music when an AVPlayer starts to play? Does nothing happen, does it stop, or does the action cancel itself? If so, how would I check and see if the user is playing music?
Apple's Documentation for this confused me.
Alright, looking up the info for this, it seems that AVAudioPlayer objects only interrupts the user's audio if the app's AVAudioSession's category is set to Solo Ambient, the default.
I saw this answer: App with AVPlayer plays mp4 interrupt iPod music after launched
I also saw this table in the Apple Developer documentation that explains whether or not different categories interrupt the user's music, with examples of different scenarios, including one for a game: https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/Sound.html#//apple_ref/doc/uid/TP40006556-CH44-SW1
In order to not interrupt the user's music, I need to set this to Ambient.
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.
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