Is it possible to programmatically start playing music on a watchOS 2 device connected to Bluetooth headphones? - apple-watch

I have a watchOS 2.0 app where I want to be able to start playing music for a user on their device from their iTunes library. I can currently start playing music on the iPhone if I use sendMessage from the WatchConnectivity framework. I am hoping to be able to start playing music from the Apple Watch if the iPhone is not present, but I can't seem to find an API to do this. Does anyone know if this is possible, and if so what API's are available?
UPDATE:
I see that I can play audio files from the Apple Watch using WKAudioFileAsset. I am still not able to figure out how to play music that has been synced by the Music app however.

Related

iOS output stream music in background

to cut story short Im developing an app thats like Sonos. That is, Im trying to stream music from the iPod library to a hardware over wifi. Hence the sound will come out of a hardware that is connected to the iPhone by wifi.
Doing this is easy enough when the app is foreground but in the background the app will be terminated. It is different when outputting the audio in the background in the iPhone device itself.
Also I notice that Sonos supports this feature only for iOS 6 so I wonder if theres some new magical API that allows this.
I hope any of you gurus can guide me to the right path.

iPhone iOS5 what are my options for playing audio I do not have bundled in?

I currently have 3 ways to play audio within my app:
Using AudioServicesPlaySystemSound for vibration and simple
sounds
Using Audio Toolbox for bundled files (3rd party class)
Using AudioServices with AudioFX
What I'm currently investigating is, if I can play other kinds of audio that are already present on the iPhone. I would like to reduce my app's download size, as well as offer more flexibility in terms of the kind of sound that the user can play.
Can I play from within my app:
Audio recordings from the Voice Memos app, or do I have to
create my own recordings? Items from an iPod playlist or Music app?
Items from youtube by pre-loading them, or will I have to stream them every time?
Existing ringtone for the phone?
I am a complete beginner when it comes down to playing audio on an iPhone and am already using two 3rd party classes for audio tasks.
Is there an easy way to accomplish some of the tasks listed above?
1) Audio recordings from the Voice Memos app
It's been asked before and I don't believe it's possible from your app sandbox.
iPhone: Access voice memos programmatically
2) Items from an iPod playlist or Music app
There's an API for that, the iPod Access Library:
http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/iPodLibraryAccess_Guide/Introduction/Introduction.html
3) Items from youtube
Should be possible, using a UIWebView.
http://iphoneincubator.com/blog/audio-video/how-to-play-youtube-videos-within-an-application
4) Existing ringtone for the phone
No, you can't access the current ringtone programatically.
How can I programmatically determine the default ringtone on an iPhone?
You can download sound files on first start (not in your didFinishLaunchingWithOptions method or your app will likely be killed) and save them locally, then you can just play them when needed. You can play files in their iTunes library, but won't know what they have in the library.
To play from their library, this is a handy example:
http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-music-library-access/
You can also record user input from your app with AVAudioRecorder, save that and then play it whenever.

How to allow ipod music to play while my app is running?

I'm using SimpleAudioEngine to play my sounds and I was wondering if there is anyway to check if iPod music is playing when the app is launched. If so, I want it to continue playing. I'm starting to think it may be called the simple engine for a reason as it doesn't allow features like this, where AVAudioEngine does...
Thanks :)
You should check out the official Audio Session Programming Guide and make sure that you are setting the correct session category. You will want to pick the category that allows your audio to mix with the iPod audio.

How to control wether or not my app will stop any iPod music playing?

When my app launches, there are rumors that I can decide if any currently playing music is stopped or not.
My goal is to use Audio Queue Services, because I believe that's the most powerful audio technology in iPhone OS.
So, could I really decide that when my app launches? How? Which one of the many audio technologies on the iPhone OS is responsible for managing this?
See the class MPMusicPlayerController and the class method +iPodMusicPlayer

ipod app replacement-in-a-tab?

With the new media-library capabilities in the 3.0 SDK, I'd like to have a tab in my application to control the music that's playing. Not just pause and play (i'm aware that pressing the home button twice brings up controls for this), but also the ability to browse and queue albums/artists/songs/playlists. Basically a copy of the ipod app functionality.
Any chance someone has already done this and made it freely available?
I'm not aware of any readily available source for you. However, the Media Player Framework Reference is pretty straight-forward, and you should be able to mimic the iPod app pretty easily (sans CoverFlow and other niceties, of course). Good luck!
The Media Player framework gives you very limited access to the iPod music player. For example, you can't know where the currently playing song is in its playlist. If you use the application music player, it stops the currently playing song, and when you quit, it stops playing, but the app music player does give you more control over playlists.
In short, you can't replicate all the features of the iPod app in a tab in the OS 3.0 through 3.1.3, but you can do a good job of the basic features of the pop-up control when you double-click the home button.