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];
Related
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!
A video from the internet like so:
NSURL *url = [NSURL URLWithString:#"http://www.example.com/myvideo.m4v"];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
[player play];
Unable to play movie on Simulator Black Screen displays
You should try some frameworks (for example HCYoutubeParser) that can fetch a direct link to video from Youtube for you.
// Gets an dictionary with each available youtube url
NSDictionary *videos = [HCYoutubeParser h264videosWithYoutubeURL:[NSURL URLWithString:#"http://www.youtube.com/watch?v=8To-6VIJZRE"]];
// Presents a MoviePlayerController with the youtube quality medium
MPMoviePlayerViewController *mp = [[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:[videos objectForKey:#"medium"]]] autorelease];
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
This may be a silly question. But, don't know where the problem actually. I'm trying to stream my http streaming (HLS) through MPMoviePlayercontroller video streaming is fine. But, audio isn't working on real device (Working in Simulator) Here is my code,
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"http://mydomain:1935/coder/%#/playlist.m3u8", self.streamField.text]];
theMoviPlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
theMoviPlayer.controlStyle = MPMovieControlStyleFullscreen;
theMoviPlayer.movieSourceType = MPMovieSourceTypeStreaming;
theMoviPlayer.view.transform = CGAffineTransformConcat(theMoviPlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2));
UIWindow *backgroundWindow = [[UIApplication sharedApplication] keyWindow];
[theMoviPlayer.view setFrame:backgroundWindow.frame];
[backgroundWindow addSubview:theMoviPlayer.view];
[theMoviPlayer play];
Has anyone worked on this? I'm getting only with device for audio issue.
Edit
I have tried below one,
NSURL *url = [NSURL URLWithString:#"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:player];
This(URL only given to safari) works fine both iPad and Simulator iPad of Safari browser with Audio. But, not working as application on iPad except Simulator.
First add AVFoundation.framework and add below code.
in .h file
#import <AVFoundation/AVFoundation.h>
and .m file
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
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?