How can I pause music coming from another app in my own app? - ios

I'm very new to xcode and am trying to figure out how I can pause music coming in from another app such as iTunes or Spotify so that it does not run in the background of my app. Is there a command I'm missing or do I have to have a button to shut it off?

Please have a look at the Audio Session Programming Guide. You have to create an audio session with category AVAudioSessionCategorySoloAmbient.

Related

Background Audio is enabled but not needed

following the examples, I enabled the Background Audio capability in my app, even though I do not need it. I want simple playback only, with midi triggering sounds (sf2) from the app bundle only, in foreground only. I got everything working and submitted my first version to the App Store and I get complaints from the reviewer saying that if I don't use background audio (so they can't test it) then I should switch it off in the Capabilities. If I do that my foreground audio triggering stops working. Can anyone help in what is the proper way configure AKSettings and the app in this case, so I could pass the app store review?

How to launch an associated watch app from an IOS application

How do I launch an associated Watch App from an IOS App?
I do see questions where the user flow is in reverse, where the Watch App starts the IOS App in the background. However I want the reverse. I want to launch the Watch App, make it visible on the watch when the associated IOS App is running.
My current user experience is not good; I launch the IOS App from the Phone, then fiddle with the watch to find the associated Watch App.
The current IOS App plays music at times, and I have added the Now Playing View. I have also noticed that when I start the watch application "not programatically", some minutes later (after the watch goes to sleep and raised again to awake) the default music player Watch App is made the current watch application when playing music via the IOS App.
I would have preferred that the associated watch application is active on the watch, and that the Now Playing View controls the music.
The watch application has two views/pages where the user would swipe to move to the next page. The first page has some text and the second page has the Now Playing View
It would be far better, if the users starts the IOS App and auto launches the associated Watch App.
I am not sure what the design decisions are regarding this. Perhaps a Notification needs to be sent, and the user can then decide whether to launch the Watch App.
Please assist by giving brief API calls to make or adjusting properties in the plist.
Thanks.
You can do so by sending a workout configuration to your watch app via
startWatchAppWithWorkoutConfiguration
I'm not sure it would get past the App Review for non workout apps. You might have to call this method twice to reliably start the app, due to a timeout: forum discussion

Play Apple Music's App Songs using SystemMusic Play API

I have simple application through which i want to play apple music songs from my application. I have implemented this code to play & pause music from the application.
[[MPMusicPlayerController systemMusicPlayer] play];
[[MPMusicPlayerController systemMusicPlayer] pause];
The issue i am facing with this implmentation:-
I need to manually open the Apple Music App once, play the music and
pause it before testing the app.
The Apple music app then have instance and a song in queue to be
played by my app.
If i test my app with above code, it works fine for sometime but
stops playing the songs after few iterations.
Actual requirement is just i need to run the song without starting the Apple Music app before testing my application and it should run by and when i am testing.
Please guide me that what implementation is required and can this doable or not.

Playing audio files in background in iOS

I'm trying to find responses to this in Apple's documents, but I don't:
1) Is it technically possible to start playing an audio file when an app goes to background?
2) If technically possible... is it "legal"? Would Apple approve an app that starts playing an audio file without an explicit interaction of the user?
Thanks in advance
An app can start playing an audio file in the background if it is already playing audio before the app goes into the background, has the appropriate audio background mode capabilities key set, and mixes the new audio file into an already playing audio unit, queue or player without stopping. There are plenty of approved apps in the App store that do this (e.g. they sequence through playlists).
An app can't start playing an audio file in the background if it is not already playing or recording audio, as the OS will take away and disable the app's audio session as it goes into the background.
Reports are that apps that play "silence" to get around this restriction are currently being rejected by Apple, although some legacy examples (alarm clocks?) may still exist in the iOS App store. But for private (non-App-store) apps, this trick currently seems to work just fine.
Also, remote notifications can start playing very short audio files contained within an app's bundle, even if the app is in the background without an active audio session.

How to allow external music/audio to continue in Corona SDK apps when they launch?

In Corona SDK how do you allow existing music/audio already playing in the background when your app (corona sdk based app) is launched and run? In particular:
iTunes Music/Podcasts - ability to have background music/audio to keep playing when you launch your app (i.e. corona sdk built)
Other Apps (e.g. audible.com app for audiobooks) - ability to have audio from such an app continuing when you launch your app (i.e. corona sdk built)
I'm guessing (2) may not be possible, but at least how do you implement (1)? I know there are apps out there (well I've seen IOS ones at least) which offer the ability for your background music to keep playing, but need to find out how to do this with Corona SDK? or if it's not yet possible just to understand this
Note, my app was intending to just play short audio clips (e.g. menu button pushes) on top of the background music/audio. That is wasn't planning to stream music in my app
From my understanding, Corona allows background music to be played no matter if it's from iTunes or other apps.
However since build 2126, there was a regression bug that made external (background) music stops when the app launched.
And it is fixed in the recent Corona daily build, 2179.
Please take a look at this Corona forum post if you want to know the detailed development for this issue:http://forums.coronalabs.com/topic/40837-allow-external-music/
I have tested it & verified that the background music continues when my app launches if I build with build 2179 or before build 2126.
http://docs.coronalabs.com/api/library/audio/index.html
you can check the about audio load, play, streaming, pause etc.
audio.loadSound() — loads an entire sound into memory. It should be used for shorter audio files that may be used repeatedly throughout the app.
audio.loadStream() — reads in small chunks of an audio file over the course of its duration. It should be used for longer audio tracks like background music. Note that streamed files may have a slightly higher latency cost and CPU cost than files loaded with audio.loadSound()
Go through the above link.
I found this post corona post very useful related to it and it has content to resolve your issue, Please check:
http://developer.coronalabs.com/code/sample-code-loop-background-music-synchronized-your-apps

Resources