How to add a music background in the video chat on iOS? - ios

I have a question about the AVAudioPlayer and its AVAudioSessionCategory parameter.
So, basically, I have a video chat between two users and I want to play music as a background for them. I tried to use the "AVAudioSessionCategoryPlayAndRecord" value for the AVAudioSessionCategory, but in that case, the music will be recorded and send together with the voice to the partner.
I think that I'm looking for a way to play music but do not record it, so each partner will be listening to its own music.

Related

Play but don't record avaudioplayer background music

I have an app that records a video/audio like Instagram stories with avassetwriter and simultaneously plays an audio background music file with avaudioplayer. It both records and plays great.
The problem I am noticing though, is when I play back the recording, the background music is extremely loud, and I'm assuming it's because the mic and the bottom-of-the-phone default speaker, through which the audio background music is playing out of, are situated right next to each other - even though when I record it sounds like it's not that loud.
Is there any possible way or workaround that results in allowing the background music to play while recording but to not have it actually be recorded? I'm stumped on what my options are, and am desperately hoping to see if anyone else had any ideas/thoughts as I couldn't find any existing content addressing this issue.

Recording video with audio using "AVCaptureSession" while background music is playing (iTunes, Spotify)

I am trying to record videos with audio (using "AVCaptureSession") while background music keeps playing from any music player such as iTunes or Spotify.
The CameraViewController is the the default page, so it would be convenient not to pause the user's background music while he/she records a video.
Really hoping someone can help with this issue.

Showing track name and artist for music, podcasts and any apps [Swift]

I've been trying to find a way to access the track name and artist information from any background audio just like the iOS control center player (swipe up view).
I have a part of my app that needs to display the track name and artist of any current music playing in the background.
At the moment I've been testing the MPMusicPlayerController but I can only get it to provide the now playing item of the Music app and not other third-party apps like Spotify or Apple's podcast app.
Any idea how I can replicate the control centers ability to fetch now playing items from any app music using the play audio background mode?
I'm trying to get this working in swift.
Thanks!

Intercept background audio stream on iOS

Is it possible for an iOS app to intercept the background audio stream that's playing?
I'd like to do some visualization for whatever audio is currently playing whether it's iTunes, Spotify, etc.
You can't get access to this, actually.
It's possible to play music with an app that remains in the background when the app isn't active, but you can't get access to another app's audio stream.
Apparently this is possible now, only if another app subscribes to InterApp Audio or Audiobus.
Consolidated from other SO answers for clarity:
Is there a way to intercept audio output from within your app to display back an audio visualizer on iOS?
Intercept/modify audio stream on iOS

Full-featured music player using AVPlayer

I'm writing a music player for iOS that needs to have all the features of the built-in Music app. My app needs to continue running in the background so I have to use the AVPlayer class.
Are there any open source implementations out there that I can use instead of writing the whole thing myself?
Just found this. It works great:
https://github.com/gangverk/GVMusicPlayerController
If you want to play tracks from your iTunes music library, and don't want to use the MPMusicPlayerController class, your best bet is to use AVPlayer or AVQueuePlayer (subclass of AVPlayer). You must establish the appropriate audio session and register to receive remote control events for the app to continue playing music in the background.
There are downsides to this method; you won't be able to play DRM-protected tracks and audiobooks purchased from the iTunes store. There's no way to instantiate an iTunes Match download with the AVPlayer class. Furthermore, you'll have a bit of work on your hands if you want to add gapless playback and equaliser settings (The closest you'll get to gapless playback is with the AVQueuePlayer subclass, though in theory, you could overlap AVPlayers with an NSTimer).
You'll also need to change 'Required Background Modes' in your Info.plist to 'App plays audio'
As for the rest of your app, I suggest you read up on UITabBarControllers and UITableViewControllers along with MPMediaQuerys.
See this solution for the audio part.

Resources