App crashes while streaming radio in webView - ios

I tried to build a radio in my app using webView. But on loading the link my app crashes every time.
- (IBAction)playMusic:(id)sender {
NSString *stream = #"http://www.bbc.co.uk/radio/listen/live/r2.pls"; //just an example link
NSURL *url = [NSURL URLWithString:stream];
NSURLRequest *urlrequest = [NSURLRequest requestWithURL:url];
[Webview loadRequest:urlrequest];
}
...but with a page link (like www.google.com) everything works fine.
Maybe there is also a better solution than using webView to play radio.
Thanks to all of you in advance

UIWebView is indeed not meant to play audio files. I would recommend you to use MPMoviePlayerController (part of the MediaPlayer framework) for what you're trying to achieve. I wrote some sample code to below to show how you how to get started.
If you need more information, I suggest you to take a look at the HTTP Live Streaming Resources or MPMoviePlayerController Class Reference
NSURL *URL = [NSURL URLWithString:#"http://www.bbc.co.uk/radio/listen/live/r2.pls"];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:URL];
[moviePlayerController prepareToPlay];
[[moviePlayerController view] setFrame:CGRectMake(0.f, 0.f, [[self view] frame].size.width, 24.f)];
[[self view] addSubview:[moviePlayerController view]];
[self setMoviePlayerController:moviePlayerController];

Related

Play facebook videos in ios application

I want to embed Facebook videos in my app. I am getting video links from a webservice.
For example:
"video_url": "https://www.facebook.com/urdutimes.ca/videos/520665921438799/"
Is it possible to embed this video in native iOS app using Objective-C?
Thanks in advance
Try this one:
NSURL *url = [NSURL URLWithString:#"https://www.facebook.com/urdutimes.ca/videos/520665921438799/"];
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
mp.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[self presentMoviePlayerViewControllerAnimated:mp];

I am trying to play a video from URL which is playing in VLC media player but not playing in native player i.e MPMoviePlayer

It is showing like this in browser,when I click on play it doesn't do anything.
But the same URL is working fine in Android native player.
Here is my code and URL of that video stored in server, format of video is MP4.
I tried with some other URLs like
NSURL *url=[[NSURL alloc] initWithString:#"http://www.ebookfrenzy.com/ios_book/movie/movie.mov"];
NSURL *urll = [[NSURL alloc]initWithString:#"http://nordenmovil.com/urrea/InstalaciondelavaboURREAbaja.mp4"];
These are working fine but below one is not working
NSURL *url = [[NSURL alloc]initWithString:#"http://****IP****.com:8888/alias_1440247177838"];
moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayer.view.frame = CGRectMake(0, 20, self.videoPlayView.frame.size.width, self.videoPlayView.frame.size.height * (1.0f/3.0f)-20);
moviePlayer.controlStyle=MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay=YES;
[self.videoPlayView addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
Unfortunately MPMoviePlayer can only play video from a direct link. (similar to the ones that you mentioned in your question.
You can either:
use a direct link
Or switch to UIWebView instead of MPMoviePlayer
You can use a UIWebView in following way:
UIWebView* webView = [[UIWebView alloc] initWithFrame:self.view.frame];
[self.view addSubview:webView];
webView.allowsInlineMediaPlayback = YES;
NSURL* url = [NSURL URLWithString:#"http://****IP****.com:8888/alias_1440247177838"];
[webView loadRequest:[NSURLRequest requestWithURL:url]];
Hope this helps!

How to play video player one after another in ios?

i want to play video in ios one after another..I have two video files .m3u8 format. if video one completed then video two start automatically.. after video two complete then again video one should played automatically. and again video two should start automatically. how can i do this thing….I am using Mediaplayer framework. plz give me any idea…..Thanks in advance.
-(void)viewDidLoad
{
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"buyTutorial" ofType:#“m3u8”];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController prepareToPlay];
[moviePlayerController play];
[self setController:moviePlayerController];
}
You should be able to use this notification:
https://developer.apple.com/LIBRARY/IOS/documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/index.html#//apple_ref/c/data/MPMoviePlayerPlaybackDidFinishNotification
And then look for this constant PlaybackEnded:
https://developer.apple.com/LIBRARY/IOS/documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/index.html#//apple_ref/c/tdef/MPMovieFinishReason
Then just start the next movie in your playback queue.
Here's some examples on how to register to the notification:
MPMoviePlayerPlaybackDidFinishNotification being called again in iPhone 4.3 simulator when setting contentURL

IOS - Open videos in Media Player when using UIWebView

I want to launch Media Player upon clicking on a video link within UIWebView. The content of the UIWebView is an HTML5 page on my server, so whether the solution is to change the code in XCode or HTML5 I will be able to handle it.
All the videos in question are of 'mp4' extension - Just in case this addition helps.
Please note this is for an iPad-only App.
This code could be modified to launch a video based on a button click from within the app.
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"filename" ofType:#"mp4"];
//LOCAL FILE
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
//REMOTE FILE
NSURL *fileURL = [NSURL URLWithString:#"http://someurlsomewhere.com/movie.mp4"];
player = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
player.frame = CGRectMake(0, 0, 1024, 768);
[self.view addSubview:player.view];
player.fullscreen = NO;
[player play];
Here is a link that covers detecting taps/clicks from a webview which may be what you need in order to trigger the video.
how to intercept Button click inside UIWebview on IOS?

View Html in ios/ipod Apps

Hi i want to make a few http request and generate html from within my ipod app. I hear i want a WebView to view the html as if it were a browser. So my question is how do i make the http request? How do i parse json (or xml) and how do i save/load data? I figure i can use webstorage to load/save the data however i am thinking since its an ipod app i have a better way of storing it?
Here's a snippet to load a local html web page contained inside your app bundle:
UIWebView *webView = [[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
NSString *path = [[NSBundle mainBundle] pathForResource:#"mywebpage" ofType:#"html"];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]];
Another alternative is to embed a local web server running in a background thread, and use a URL to localhost.
A UIWebview supports HTML5 local storage.
Here is the working code snippet. for iPod/iPhone/iPad;
Works with iOS7 and iOS6.. I have not tested in others...
UIWebView *_webView = [[UIWebView alloc] initWithFrame:self.view.frame];
[self.view addSubview:_webView];
NSURL *url = [NSURL URLWithString:#"http://www.google.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];

Resources