I am playing a video with mpmovieplayer, but I need to know when the video has loaded completely so I can turn off the network activity indicator. is there a notification that would tell me when the video is completely loaded?
I was thinking the four load states would help:
MPMovieLoadStateUnknown
MPMovieLoadStatePlayable
MPMovieLoadStatePlaythroughOK
MPMovieLoadStateStalled
I tried the playthroughok load state but that doesn't tell me when the video is completely loaded.
Here is some of my .m code for my video player:
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:self.videoitem];
self.moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
self.moviePlayer.view.frame = CGRectMake(0, 0,320, 480);
[self.view addSubview:self.moviePlayer.view];
}
Thank you for your help!
Related
It will showing black screen with loading activity indicator When i click the video in full screen and touch up the forward or Backward button.
I have using the following code for movie player
NSURL *fURL = [NSURL URLWithString:[self.winnersCircleDictionary objectForKey:#"videoname"]];
self.players=nil;
self.players=[[MPMoviePlayerController alloc]initWithContentURL:fURL];
[self.players setContentURL:fURL];
self.players.scalingMode = MPMovieScalingModeAspectFit;
self.players.repeatMode=MPMovieRepeatModeOne;
[[self.players view] setFrame:_webviewWinnerCircle.frame];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayerPlaybackStateChanged:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:self.players];
object:nil];
self.players.shouldAutoplay=NO;
self.players.currentPlaybackTime=0.0;
[scrollViewWinnerCircle addSubview:self.players.view];
Forward and Backward button working fine in iOS 6 and this issue only have in iOS 7.
Thank You.
I just tried your code and got the issue , And solved like this.
Prepared the MoviePlayer like [self.players prepareToPlay]; for playing the selected video after adding the self.player.view as subview to the scrollViewWinnerCircle.
The code is as follows.
self.players = [[MPMoviePlayerController alloc]initWithContentURL:fURL];
[self.players setContentURL:fURL];
self.players.scalingMode = MPMovieScalingModeAspectFit;
self.players.repeatMode = MPMovieRepeatModeOne;
[[self.players view] setFrame:_containerView.frame];
self.players.shouldAutoplay = NO;
self.players.currentPlaybackTime = 0.0;
[_containerView addSubview:self.players.view];
[self.players prepareToPlay]; // Prepares a movie player for playback.
[self.players pause]; // Pause playback of the loaded movie
It was the problem with the source, also didn't specified the source type.
Do like the following, its working for me with the url i used here.
NSURL *fURL = [NSURL URLWithString:#"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
self.players = nil;
self.players = [[MPMoviePlayerController alloc]initWithContentURL:fURL];
[self.players setContentURL:fURL];
// Specifying media source type
self.players.movieSourceType = MPMovieSourceTypeStreaming;
It take some time to load initially.
you have to use this code instead of MPMovieplayerController and import these library in you class:
AVKit
AVFoundation
NSURL *videoURL = [NSURL URLWithString:#"https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"];
AVPlayer *player = [AVPlayer playerWithURL:videoURL];
AVPlayerViewController *playerViewController = [AVPlayerViewController new];
playerViewController.player = player;
[player play];
[self presentViewController:playerViewController animated:YES completion:nil];
after using above code you will be able to forward and back forward video.
I want to play mp4 video files using MPMoviePlayerController.
Here is the code I am currently using:
NSURL *url = [NSURL URLWithString:
videoLink];
MPMoviePlayerController *controller = [[MPMoviePlayerController alloc ]init];
[controller`enter code here` prepareToPlay];
self.mp = controller; //Save obj reference
Also I am re using same player object because have to load another video file as soon as next or previous clicked on UI.
controller.view.frame = CGRectMake(0, yMargin, self.view.frame.size.width, self.view.frame.size.width*9/16); //Set the size
[self.view addSubview:controller.view];//Show the view
[controller setContentURL:url];
[controller play]; //Start playing
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification object:self.mp ];
Sometimes it's loading video properly but randomly showing an error message as given below.
itemFailedToPlayToEnd: {
kind = 1;
new = 2;
old = 0;
}
If error comes it doesn't load any other video afterwards at least for next 15(approx.) attempts.This behaviour is very random as sometimes it keeps showing the error in log and player doesn't load the video at all.
Has someone else faced this similar issue ? I found many questions posted related to this problem but nothing seems to be working for me.
Other solution i found playing a video using web view but auto play
doesn't work for web view.
I'm developing a iPhone app and need to play the animation video in the background. This video should run until the user touch's the screen of the app. Not exactly the screensaver but this should happen for the first time when the app is opened.
How can play the video file in the background and screen buttons on top of the video in the app?
Add video player in your view of subview and your view must be a transparent layer makes.
your app delegate check the user coming first time or not.
NSString *path = [[NSBundle mainBundle] pathForResource:#"testVideo" ofType:#"mp4"];
MPMoviePlayerController *myPlayer = [[MPMoviePlayerController alloc] init];
myPlayer.shouldAutoplay = YES;
myPlayer.repeatMode = MPMovieRepeatModeOne;
myPlayer.fullscreen = YES;
myPlayer.movieSourceType = MPMovieSourceTypeFile;
myPlayer.scalingMode = MPMovieScalingModeAspectFit;
myPlayer.contentURL =[NSURL fileURLWithPath:path];
[self.view addSubview:myPlayer.view];
[myPlayer play];
Simply add MPMoviePlayerController as background and play the video,
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: video_url];
[player prepareToPlay];
[player.view setFrame: requiredFrame];
[self.view addSubview: player.view];
After that, add tap gesture to whole view and remove player on tap gesture method..
I have multiple videos on one view, when one video has finished playing, the user taps a button and the next video starts to play.
The video that has just played goes to a black screen.
I want the video to stop (pause) where it is, so the image is still there.
this is my code;
}
-(IBAction)play {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:#"origami_panel01" ofType:#"mp4"]];
MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc]
initWithContentURL:url];
playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
playercontroller.moviePlayer.controlStyle = NO;
playercontroller.view.frame = CGRectMake(18, 20, 732.5, 360);
[self.view addSubview:playercontroller.view];
[playercontroller.moviePlayer play];
}
-(IBAction)play_3 {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:#"origami_panel02" ofType:#"mp4"]];
MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc]
initWithContentURL:url];
playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
playercontroller.moviePlayer.controlStyle = NO;
playercontroller.view.frame = CGRectMake(18, 395, 233, 233);
[self.view addSubview:playercontroller.view];
[playercontroller.moviePlayer play];
}
It continues like this for a total of five videos.
Please can someone tell me how to make the video pause when another video is played. Thanks!
You can not have more than one playback active when using MPMoviePlayerController. Whereas being paused also counts as active.
You got at least these two options:
Use AVPlayer as that baby supports multiple active video playbacks concurrently.
Stick with MPMoviePlayerController but fake that pause-state by taking a snapshot image from the movie (thumbnailImageAtTime:timeOption:). Then use that image and display it instead of the player.
I have a large .m4v video file on an HTTP server. The video1.m4v file is 2GB in this example. As an example, this is the URL I want to hit:
http://www.myurl.com/movies/video1.m4v
When I load that URL in my UIWebView browser on my iPhone the file starts playing automatically and perfectly. I can skip ahead, go back, use Airplay, and everything works great and fast:
[webView loadRequest:[NSURLRequest requestWithURL:movie.fileURL]];
When I load it up with this MPMoviePlayerController code it just hangs on Loading forever:
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:url];
[moviePlayerController.view setFrame:CGRectMake(0, 70, 320, 270)];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
Why does it start buffering and playing so much quicker in my UIWebView (or mobile Safari if I load the URL from there) so much quicker than from MPMoviePlayerController?
Try to use MPMoviePlayerViewController of MPMoviePlayerController
Check this link:
Apple Reference
Try something like this
MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
mpvc.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[self presentMoviePlayerViewControllerAnimated:mpvc];