Play Apple Music's App Songs using SystemMusic Play API - ios

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.

Related

MPRemoteCommandCenter and Play Pause Update with the AVSpeechSynthesizer

I am currently using AVSpeechSynthesizer for Text to Speech. Category used for the playback is AVAudioSessionCategoryPlayback and AVAudioSession is set to Active YES.
During the start of the play, [TTS] TTSPlaybackCreate unable to initialize dynamics: -3000 in the Xcode console. When i pause the playback i get [TTS] _BeginSpeaking: couldn't begin playback.
My major issue is MPRemoteCommandCenter doesn't get updated to pause when TTS stopped.
For Stop functionality, I am using this code;
BOOL speechStopped = [self.ttsSpeechSynthesizer stopSpeakingAtBoundary:AVSpeechBoundaryImmediate];
if(!speechStopped) {
[self.ttsSpeechSynthesizer stopSpeakingAtBoundary:AVSpeechBoundaryWord];
}
I had Airplay connected to an Airplay station.
I had a similar issue after updating iOS to the latest version on my phone.
I spent much time trying to understand why my app stopped talking using TextToSpeech while all worked before and code seemed ok.
Siri was talking aloud fine, and the sound in other apps worked as well
Mine was giving no error message in the code and the following in the device log:
Error (730) / LearnByHeart.iOS(TTSSpeechBundle): TTSPlaybackCreate unable to initialize dynamics: -3000
Rebooting the phone did not help.
As funny as it is, all got resolved by turning the physical sound button off and back on.
Hope this saves someone a day

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

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.

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

How play music for alarm app in ios6?

How play music in my alarm app from musiclibrary in ios6 ?
Is there a new API or new feature UILocalNotification ?
It's only new in the standard Clock app, the API (MediaPlayer) has been around for a while.
Here's some links:
Apple's documentation
A tutorial on TutsPlus

Resources