playing video in ios 6 - objective-c

I wanted to play a video in ios 6. I am using Xcode 4.5. I write code below but getting error
Test Demo[736:14003] [MPAVController] Autoplay: Disabling autoplay for pause
Test Demo[736:14003] [MPAVController] Autoplay: Disabling autoplay
Test Demo[736:14003] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
and my code
NSString *videoPath = [[NSBundle mainBundle] pathForResource:#"TestVideo" ofType:#"m4v"];
NSURL *streamURL = [NSURL fileURLWithPath:videoPath];
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: streamURL];
[player prepareToPlay];
[player.view setFrame: self.view.bounds]; // player's frame must match parent's
[self.view addSubview: player.view];
// ...
[player play];`

There could be many issues for your error.
1) Set a property for your MPMoviePlayerController and synthesize it. This may occur, if your MPMoviePlayerController releases before it plays.
2) add this code player.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
3) As per documentation, .m4v extension is not mentioned to play.
4) Below screenshot will help you about supported formats.

NSString *url = [[NSBundle mainBundle] pathForResource:#"santaMessage" ofType:#"mp4"];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
[self.view addSubview:moviePlayer.view];
moviePlayer.fullscreen = YES;
moviePlayer.allowsAirPlay = YES;
[moviePlayer play];
///this worked like a charm

Related

HTTP load failed and I have tried all of the SO suggestions, but nothing works

Error 9802 is a "Fatal Alert" according to the Apple's docs. I have looked at Google and SO and found nothing referencing 9802 that fixes this problem. I can change my code to go for "apple.com" and I get the page, but using my own URL, I get the error above. I have tried everything that I can think of, and nothing works. Time to ask for help! :D
The result of using
/usr/bin/nscurl --ats-diagnostics https://pragerphoneapps.com
is all tests fail (results are uploaded here)
This is an image of my app's .plist file (only pertinent part)
and this is an image of the target info:
And this is my code:
- (IBAction)showHTMLHelp:(UIButton *)sender {
// make the popover
UIViewController* popoverContent = [UIViewController new];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 450, 500)];
popoverView.backgroundColor = [UIColor colorWithWhite:(CGFloat)1.0 alpha:(CGFloat)1.0]; // frame color?
popoverContent.view = popoverView;
//resize the popover view shown in the current view to the view's size
popoverContent.preferredContentSize = CGSizeMake(450, 500);
NSString *urlAddress = #"https://pragerphoneapps.com"; // #"https://www.pragerphoneapps.com/bookstore-inventory-manager/upload-help/";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
// add the UIWebView for RichText
UIWebView *webView = [[UIWebView alloc] initWithFrame: popoverView.frame];
webView.backgroundColor = [UIColor whiteColor]; // change background color here
// add the webView to the popover
[webView loadRequest:requestObj];
[popoverView addSubview:webView];
// if previous popoverController is still visible... dismiss it
if ([popoverController isPopoverVisible]) {
[popoverController dismissPopoverAnimated:YES];
}
//create a popover controller
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
[popoverController presentPopoverFromRect:((UIButton *)oShowHelp).frame inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
I seriously recommend you to fix your SSL certificate.
ATS requires you to have a valid SSL certificate, TLS version 1.2 or above and support for forward secrecy.
This will be a requirement at the beginning of 2017 so better get ready.
Anyway, meanwhile try the following steps to get this working.
Put this on top of your file:
#interface NSURLRequest (InvalidSSLCertificate)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString*)host;
+ (void)setAllowsAnyHTTPSCertificate:(BOOL)allow forHost:(NSString*)host;
#end
Disable App Transport Security in Info.plist.
Allow invalid SSL certificates before loading request:
[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
Sample code that successfully loads your site:
NSString *urlAddress = #"https://pragerphoneapps.com"; // #"https://www.pragerphoneapps.com/bookstore-inventory-manager/upload-help/";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
UIWebView *webView = [[UIWebView alloc] initWithFrame: self.view.frame];
webView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:webView];
[webView loadRequest:requestObj];
I wonder why it can't work for setting "NSAllowArbitraryLoads to YES".If there are caches, try to reboot your Mac or Xcode.
And your "Exception Domains" settings have the wrong format.

iOS 7 Video not playing MPMoviePlayerController

This code is working perfect in iOS 8 . but unable to play video in iOS7.The player shows up but plays nothing.Thanks
NSString *url = #"http://.../playlist.m3u8";
NSURL *streamURL = [NSURL URLWithString:url];
self.streamPlayer = [[MPMoviePlayerController alloc] initWithContentURL:streamURL];
self.streamPlayer.controlStyle= MPMovieControlStyleFullscreen;
self.streamPlayer.movieSourceType = MPMovieSourceTypeStreaming;
self.streamPlayer.shouldAutoplay = YES;
[self.view addSubview:self.streamPlayer.view];
[self.streamPlayer prepareToPlay];
[self.streamPlayer play];
From the documentation:
When you add a movie player’s view to your app’s view hierarchy, be sure to size the frame correctly, as shown here:
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: myURL];
[player prepareToPlay];
[player.view setFrame: myView.bounds]; // player's frame must match parent's
[myView addSubview: player.view];
// ...
[player play];
Try to set the frame of your video player.

MPMoviePlayerController: sound but no picture in fullscreen mode

I'm using the following code to play a movie on an iPad 1 running iOS6:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"myMovie.mov" ofType:#""]];
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayer];
// Use the new 3.2 style API
self.moviePlayer.controlStyle = MPMovieControlStyleDefault;
[self.moviePlayer prepareToPlay];
self.moviePlayer.view.frame = CGRectMake(0, 0, 1024, 768);
[self.uiView addSubview:self.moviePlayer.view];
//[self.moviePlayer setFullscreen:YES animated:YES];
[self.moviePlayer play];
This works.
If however I uncomment the line for setFullscreen, I get the movie audio but with a completely black screen, no picture.
I've tried changing the order of a few lines, in particular the play call and the setFullscreen call, with no effect.
Update
This question appears to be directly relevant:
MPMoviePlayerController in full screen issue (showing blank black screen)
first of all change this line : [[NSBundle mainBundle] pathForResource:#"myMovie.mov" ofType:#""] to: [[NSBundle mainBundle] pathForResource:#"myMovie" ofType:#"mov"] and try again
Use this as its working for me:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"myMovie" ofType:#"mov"]];
MPMoviePlayerViewController *movieView = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
movieView.moviePlayer.scalingMode = MPMovieScalingModeFill;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
[movieView.moviePlayer.view setFrame:CGRectMake(0,0,480,320)];
else
[movieView.moviePlayer.view setFrame:CGRectMake(0,0,1024,768)];
movieView.moviePlayer.view.userInteractionEnabled = FALSE;
movieView.moviePlayer.controlStyle=0;
[movieView setFullscreen:YES];
self.view=movieView.view;

How can I know when video play?

I have video in my project. I play it with MPMoviePlayerController but app will take time to load for a sec. Now I want to lunch another func. when video start to play. How can I know when video already load and start play and How to call another func. when it play ???
Could U guide me please ?
here is some simple code
-(IBAction)testVideoLongPress:(id)sender
{
NSString *moviePath = [[NSBundle mainBundle] pathForResource:#"video1" ofType:#"MOV"];
movie = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]];
movie.view.backgroundColor = [UIColor blackColor];
movie.controlStyle = MPMovieControlStyleDefault;
movie.shouldAutoplay = YES;
movie.view.frame = CGRectMake(0, 50, 720, 1280);
[self.view addSubview:movie.view];
[movie play];
}
-(void)wannalunchthismethod
{
....
}
Look at the MPMoviePlayerLoadStateDidChangeNotification notification of MPMoviePlayerController and you'll be able to catch your movie player state changing to "play".

MpMoviePlayerController streaming video problem in simulator

I am working on MPMoviePlayerController, I am playing a video which is in URL #"http://www... xyz... ITs not playing in simulator.
I am
NSString *url = #"hhttp://www... xyz... ";
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:url]];
NSString *urlStr = [[NSBundle mainBundle] pathForResource:#"video.mp4" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:urlStr];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.view addSubview:moviePlayer.view];
moviePlayer.view.frame = CGRectMake(50, 50, 200, 200);
[moviePlayer play];