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

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.

Related

Vine’s Infinite Video Loops in iOS 9 (seamlessly video)

I need some help with Infinite Video Loops like a Vine did.
I tried a lot of approaches and all of them have a short delay.
One of most popular:
__weak typeof(self) weakSelf = self; // prevent memory cycle
NSNotificationCenter *noteCenter = [NSNotificationCenter defaultCenter];
[noteCenter addObserverForName:AVPlayerItemDidPlayToEndTimeNotification
object:nil // any object can send
queue:nil // the queue of the sending
usingBlock:^(NSNotification *note) {
// holding a pointer to avPlayer to reuse it
[weakSelf.avPlayer seekToTime:kCMTimeZero];
[weakSelf.avPlayer play];
}];
Is there any way to eliminate the delay and play local videos seamlessly?
I know that Apple add some updates in iOS 9, but I need that it work from 8+ ios
Sorry for Ojc-C sample, I use Swift
Try this
-(void)startPlaybackForItemWithURL:(NSURL*)url {
// First create an AVPlayerItem
AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:url];
// Subscribe to the AVPlayerItem's DidPlayToEndTime notification.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(itemDidFinishPlaying:) name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem];
// Pass the AVPlayerItem to a new player
self.avPlayer = [[AVPlayer alloc] initWithPlayerItem:playerItem];
// Begin playback
[player play]
}
-(void)itemDidFinishPlaying:(NSNotification *) notification {
[self.avPlayer play];
// Will be called when AVPlayer finishes playing playerItem
}

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

MPMoviePlayerController doesn't play video

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.

MPMoviePlayerController doesn't loop on iPad 1 with iOS 5

I have a short movie for looping in the background of my view. I use MPMoviePlayerController to play the movie. repeatMode is set to MPMovieRepeatModeOne and this works fine on iPad 2, 3 and in Simulator. On iPad 1 however, the movie loops once and stops right after the second playback. The project is iOS 5 w/o ARC (tested from GM up to 5.1.1).
- (void)loadVideo {
NSString *urlStr = [[NSBundle mainBundle] pathForResource:#"movieFileName.m4v" ofType:nil];
self.videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:urlStr]];
self.videoPlayer.controlStyle = MPMovieControlStyleNone;
self.videoPlayer.scalingMode = MPMovieScalingModeFill;
self.videoPlayer.repeatMode = MPMovieRepeatModeOne;
self.videoPlayer.view.userInteractionEnabled = NO;
[self.videoPlayer.view setFrame:self.movieContainer.bounds];
[self.movieContainer addSubview:self.videoPlayer.view];
}
How can I get the movie looping on iPad 1?
After trying out a lot, I finally found a solution to this problem:
After registering for the notification of changed playback-state MPMoviePlayerPlaybackStateDidChangeNotification, the movie loops endlessly and doesn't stop after the second playback on iPad 1. Keep in mind, that this behaviour didn't take place on iPad 2, 3 or Simulator.
The selector performed for the notification must not be empty. Just assign a bool or something. The extended code from above would be:
- (void)loadVideo {
// Create the controller
NSString *urlStr = [[NSBundle mainBundle] pathForResource:#"movieFileName.m4v" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:urlStr];
self.videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
// Configure the controller
self.videoPlayer.controlStyle = MPMovieControlStyleNone;
self.videoPlayer.scalingMode = MPMovieScalingModeFill;
self.videoPlayer.repeatMode = MPMovieRepeatModeOne;
self.videoPlayer.view.userInteractionEnabled = NO;
[self.videoPlayer.view setFrame:self.movieContainer.bounds];
// Register for notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayerNotification:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:videoPlayer];
self.listeningToMoviePlayerNotifications = YES;
// Add its view to the hierarchy
[self.movieContainer addSubview:self.videoPlayer.view];
}
- (void)moviePlayerNotification:(NSDictionary *)userInfo {
// Do anything here, for example re-assign the listeningToMoviePlayerNotification-BOOL
self.listeningToMoviePlayerNotifications = YES;
}

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