MPMoviePlayerController doesn't play video - ios

I'm using this code to try and play a video. However the video is never played, the call back is never made to say it's finished. I can't see anything that I'm missing or have where it shouldn't be. I've checked the path and that's fine. The video playback view does appear. It just doesn't play at that point.
Any suggestions?
NSURL *movieURL = [[NSBundle mainBundle] URLForResource:#"IntroMovie" withExtension:#"mov"];
NSLog(#"%#", movieURL);
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(playbackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController];
[moviePlayerController prepareToPlay];
[moviePlayerController.view setFrame:self.view.bounds];
[self.view addSubview:moviePlayerController.view];
[moviePlayerController play];

The problem lies within the fact, that your moviePlayerController is being cleaned up due to ARC.
Try if it helps to introduce a strong property for the MPMoviePlayerController.

Related

video not playing through MPMoviePlayer

I am very new to IOS app development , I am trying to play a video from gallery through MPMoviePlayer. I have list of all the video's urls in an array, but when trying to play the video MPMoviePlayer launches but does not play any video. Here is the code that I am using:
NSURL *fileURL = [NSURL fileURLWithPath:[urlArr objectAtIndex:indexPath.row]];
playMovie = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[self.view addSubview:playMovie.view];
playMovie.fullscreen = YES;
[playMovie play];
Below is the code from apple documentation, I think you are not using [player prepareToPlay], which Prepares the player for playback by preloading its buffers. rest all looks fine.
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]

How to loop mp4 file in UIWebView

I would like to loop a mp4 file in UIWebView.
e.g.
If you go to this link (http://techslides.com/demos/sample-videos/small.mp4) to open UIWebView, you won't be able to play it in loop. But I would like to watch this mp4 video for loop and loop again.
Please give me any tips to overcome!
Cheers,
You can simply use MPMoviePlayerController with setRepeatMode:MPMovieRepeatModeOne.
This should allow seamless looping of any video, and it's simple to implement.
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"Your Cool Video File" ofType:#"mp4"]];
MPMoviePlayerViewController *playerController = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playerController];
[playerController.moviePlayer prepareToPlay];
playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
playerController.moviePlayer.controlStyle = MPMovieControlStyleNone;
playerController.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
playerController.moviePlayer.repeatMode = MPMovieRepeatModeOne;
[playerController.moviePlayer play];
Important to remember to subscribe to the end playback notification like so:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer];
Start playback manually in moviePlayBackDidFinished method

Live Streaming in iOS

I would like to implement live streaming in iOS app, i found some suggestions to convert and play already recorded videos, but i need to implement direct live streaming video from iPhone/Webcam to iOS App.
How to convert webcam/iPhone or any other recording video to .M3U8?, How to send this video to Server?
Please give me some suggestions and tutorials. Thanks
use MPMoviePlayerController
NSURL *mediaURL = [NSURL URLWithString:#"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:mediaURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[mp setControlStyle:MPMovieControlStyleFullscreen];
[mp setMovieSourceType:MPMovieSourceTypeStreaming];
[mp setFullscreen:YES];
[self.view addSubview:[mp view]];
[mp prepareToPlay];
[mp play];
For youtube streams, you can use youtube-ios-player-helper lib.
https://github.com/youtube/youtube-ios-player-helper

Video not loading in iOS 5 (invoked with unrecognized keys)

Hopefully somebody can point me in the correct direction with this error. I have an application that loads a video when a view becomes visible, and starts it automatically. It works fine in iOS 4, but when I tried to use it in iOS 5, it no longer works.
This is the message that it gives me
2011-11-06 19:16:34.396 App[2923:16403] -[AVAsset loadValuesAsynchronouslyForKeys:completionHandler:] invoked with unrecognized keys (
playable
).
Here is the code:
- (void) viewDidAppear:(BOOL)animated{
NSString *url = [[NSBundle mainBundle]
pathForResource:#"Video"
ofType:#"m4v"];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(movieFinishedCallback:)name:MPMoviePlayerPlaybackDidFinishNotification object:player];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(movieStateChangedCallback:)name:MPMoviePlayerLoadStateDidChangeNotification object:player];
player.view.frame = CGRectMake(0, -1, 817, 460);
[self.videoDetailView addSubview:player.view];
self.moviePlayer = player;
[player release];
}
Rather than creating an instance of MPMoviePlayerController in the viewDidAppear method, make it data member of the class. I think this may work for you.

Cocoa touch SDK 3.2 - How to play video [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Using MPMoviePlayerViewController in SDK 3.2 for iPad
How do I play video on SDK 3.2 (iPad)?
Read many questions here but they talked mostly for iPhone.
For example, the MoviePlayer example here http://developer.apple.com/iphone/library/samplecode/MoviePlayer_iPhone/Introduction/Intro.html
That works on 3.1.3 but when I run it on 3.2, it doesn't work.
So basically I'm able to play a video on 3.1.3 using this code but the same code won't run on 3.2
NSString *moviePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"Movie.mp4"];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]];
moviePlayer.movieControlMode = MPMovieControlModeDefault;
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
[moviePlayer play];
Thanks,
Tee
MPMoviePlayerController doesn't work on the iPad anymore - only audio is played. You have to use MPMoviePlayerViewController to get the correct functionality
Using MPMoviePlayerViewController in SDK 3.2 for iPad
Thanks for the update Apple :(
I got it to work. Here is how:
NSURL* videoURL = [NSURL URLWithString:url];
MPMoviePlayerController moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[moviePlayer prepareToPlay];
[moviePlayer play];
[self.view addSubview:moviePlayer.view];
Thanks,
Tee

Resources