start playing music on spotify from another iphone app - iphone

iv created an app but id like to add a feature where when i press a button it opens my spotify app and automatically plays music... if this is even possible that is... iv got most of it done i think, iv got the button and it opens spotify but cant find out how to auto play, has anyone done this or knows how to?
-(IBAction)spotify:(id)sender {
NSString *stringURL = #"spotify:";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
}
please help :)

You can open most spotify: URLs (using [[UIApplication sharedApplication] openURL:];) and the Spotify iOS client will open and show them.
There's some documentation here - make sure you use spotify: URIs and not HTTP URLs.
However, the iOS client currently doesn't support autoplay that I'm aware of - it'll be up to the user to push play.
Alternatively, you could use CocoaLibSpotify to embed Spotify playback right inside your app.

Related

How to embed the Google Maps iPhone app within my own native iphone application?

The Apple Developer Documentation explains that if you place a link in a web page and then click it whilst using Mobile Safari on the iPhone, the Google Maps application that is provided as standard with the iPhone will launch.
How can I launch the same Google Maps application with a specific address from within my own native iPhone application (i.e. not a web page through Mobile Safari) in the same way that tapping an address in Contacts launches the map?
For iOS 6.1.1 and lower, use the openURL method of UIApplication. It will perform the normal iPhone magical URL reinterpretation. so
[someUIApplication openURL:[NSURL URLWithString:#"http://maps.google.com/maps?q=London"]]
should invoke the Google maps app.
From iOS 6, you'll be invoking Apple's own Maps app. For this, configure an MKMapItem object with the location you want to display, and then send it the openInMapsWithLaunchOptions message. To start at the current location, try:
[[MKMapItem mapItemForCurrentLocation] openInMapsWithLaunchOptions:nil];
You'll need to be linked against MapKit for this (and it will prompt for location access, I believe).
You can also use
UIApplication *app = [UIApplication sharedApplication];
[app openURL:[NSURL URLWithString: #"http://maps.google.com/maps?q=London"]];
To open Google Maps at specific co-ordinates, try this code:
NSString *latlong = #"-56.568545,1.256281";
NSString *url = [NSString stringWithFormat: #"http://maps.google.com/maps?ll=%#",
[latlong stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
You can replace the latlong string with the current location from CoreLocation.
You can also specify the zoom level, using the (ā€zā€œ) flag. Values are 1-19. Here's an example:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://maps.google.com/maps?z=8"]];

Load YouTube outside Application

I have a simple UIWebView showing a page including YouTube thumbnail. When I click it, it loads it inside the application, but I want it to be loaded outside application in the YouTube-app.
How can this be done?
Thanks.
It should be as simple as loading the YouTube-video-url like this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.youtube.com/watch?v=abcde12345"]];
It won't work in the simulator because it doesn't have the YouTube-app, but it will work on the iPhone (i hope, untested).
(I also see that your accept-rate is pretty low, you should click the little āœ” next to the answer that you think is the best answer. That way people wondering about the same thing can find the most useful answer fast and the person posting the answer will be accredited.)
EDIT:
Here is an example of what you could do to catch the YouTube-urls and opening them in the YouTube-app instead of in your app:
- (BOOL)webView:(UIWebView *)wv shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
// Determine if we want the system to handle it.
NSURL *url = request.URL;
if ([url.host isEqual:#"youtube.com"] && ([url.query rangeOfString:#"watch"] != 0)) {
if ([[UIApplication sharedApplication]canOpenURL:url]) {
[[UIApplication sharedApplication]openURL:url];
return NO;
}
}
return YES;
}
This is not tested, but should work :)
From http://apiblog.youtube.com/2009/02/youtube-apis-iphone-cool-mobile-apps.html
Method 2: Embed the YouTube player in a UIWebView
No, the iPhone still doesn't do Flash, but if you haven't already
noticed, the Safari browser on the iPhone is clever enough to turn any
YouTube embed into a clickable thumbnail that launches the native
YouTube player app on the phone. You can take advantage of this
feature in your app by using a UIWebView. Here's how:
Set up a UIWebView in your app. You can make it part of a xib or create it programmatically. Size the UIWebView according to how large
you want the clickable thumbnail to be.
Grab the video url using the same method as the one described above.
Call the loadHTMLString:baseURL: method on the UIWebView instance with some carefully constructed HTML that contains the YouTube
embedded player code snippet and some supporting HTML to make sure
that the video thumbnail appears correctly. Set the base URL to the
URL of your website (it doesn't do anything here -- ordinarily
UIWebView uses it to handle relative URL links correctly).
The best way to illustrate this is with a code snippet. Note the use
of the viewport HTML meta parameter and the consistent use of width
and height parameters throughout.
// webView is a UIWebView, either initialized programmatically or
loaded as part of a xib.
NSString *htmlString = #" ";
[webView loadHTMLString:htmlString baseURL:[NSURL
URLWithString:#"http://www.your-url.com"]];
One of the biggest benefits of this approach is that your app does not
have to quit in order for the video to start playing. In fact, the
iPhone will keep your app running in the background while it fires up
the YouTube player to play the video. After the video finishes playing
(or when the user hits "Done"), the user is automatically taken back
to your app. This experience is very similar to watching embedded
YouTube videos in the iPhone Safari browser and is just as seamless.

Play a movie in another app then return to my app

I wanted to be able to play a divx or mkv file from my app. So I'm using url schema method, calling a player like Buzz Player via
UIApplication *ourApplication = [UIApplication sharedApplication];
NSString ourPath = #"http://buzzplayer:http://www.mylocalserver.com/file.avi";
NSURL *ourURL = [NSURL URLWithString:ourPath];
[ourApplication openURL:ourURL];
And that works great, it opens the file in the video player fine. But when I press Done in that player, it goes to the Buzz Player menu not back to my app.
It makes sense I guess as I did send the URL request to the player and I'm assuming this isn't Buzz Player specific but something any app would do.
Is there any way I can get an external player to work as the Apple built in video player works; when I press done it jumps back to my app? Or maybe a better solution to this?
I didn't want to reinvent the wheel and build a video player into my app when there are so many great apps that do this out there.
There is no way to get iOS to bring your app back to the front after the other app is done. In your case it seems you'll need to build a movie player into your app. Which isn't that hard to do. Have a look at the MediaPlayer class in the Foundation framework.

Use Vimeo videos inside iPhone/iPad app

our client's video archive is hosted on vimeo, so I want to know if it is possible to use vimeo videos inside of iOS app so that user could press button and get fullscreen video playing in default video player. Is there any kind of API available for that?
upd: I know that in 2010 there was same question on SO, but maybe things changed during last year.
Get the video id, and load it into a webview using the vimeo player url. It will open the quicktime player in full screen mode on tap of the play button.
urlAddress = [NSString stringWithFormat:#"http://player.vimeo.com/video/%#",videoID];
NSURL *url = [NSURL URLWithString:urlAddress];
self.requestObj = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:requestObj];
You can use YTVimeoExtractor to extract the mp4 url that is usable in MPMoviePlayerViewController.

Why is this link to an item in iTunes not opening the music store from my application?

I need a user of my application to purchase and download music from iTunes to their iPhone.
I used the following code:
NSString *text=#"<img src=\"http://ax.phobos.apple.com.edgesuite.net/images/web/linkmaker/badge_itunes-lrg.gif\" alt=\"Esperanza - Esperanza Spalding\" style=\"border: 0;\" />";
[webview loadHTMLString:text baseURL:nil];
but the iTunes music store is not opening. What could be wrong with this code?
What you are doing is just displaying an image link in a UIVebView.
If you want to open the iTunes app you can do this:
NSString *link = #"http://itunes.apple.com/us/album/sports/id14659264";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:link]];
Your code works fine, you will not be able to run it on the Simulator though.