Open movie app with precise video on iOS - ios

I would like to open the iPad movie player from my app to play a video.
The video will already be on the device, and the app is destined to ad-hoc distribution on pre-configured device, thus we can say the video will always be here.
My problem is that I can't figure out how to open the video app! I've searched a lot of things, including UTI, or embedded video, but that doesn't meet my needs.
Is there any way to simply open the player with the specified file ?

Do you need to open the video app per se? Or do you just need to play local video file from your app? In the latter case, you can just use MPMoviePlayerController (or the wrapping MPMoviePlayerViewController for iOS > 3.2).
Something like this works for me.
NSURL * url = [[NSBundle mainBundle] URLForResource:#"yourvideo" withExtension:#"mov"];
player = [[MPMoviePlayerController alloc] initWithContentURL:url];
player.view.frame = self.view.bounds;
player.movieSourceType = MPMovieSourceTypeFile;
[self.view addSubview:player.view];
player.shouldAutoplay = NO;
player.fullscreen = YES;
[player prepareToPlay];

Related

Playing videos from data obtained in chunks

I have recently started adding videos to ios apps using AVPlayer.But,now I have to get video data in chunks(HLS) rather than getting all data together ,but I am not able to understand the difference between this concept of playing data obtained in chunks or playing the whole data obtained altogether as implemented below .I have tried understanding this thing and looked for examples on internet but got the same thing as already implemented by me.Kindly give your suggestions and guidance that can help me to move forward.Thanks in advance!
-(void)playVideo:(NSURL*)videoURL
{
AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:videoURL];
AVPlayer* playVideo = [[AVPlayer alloc] initWithPlayerItem:playerItem];
_playerViewController = [[AVPlayerViewController alloc] init];
_playerViewController.player = playVideo;
_playerViewController.view.frame = self.view.bounds;
[self.view addSubview:_playerViewController.view];
[playVideo play];
}
Read this Document from Apple.
When you init player, it doesn't mean that player is ready to play. You should observe player's status until you get AVPlayerStatusReadyToPlay status.
From your code, you init player and directly start playing video. You should observe status of player by following code.
[player addObserver:self forKeyPath:#"status" options:0 context:&PlayerStatusContext];

Playing a mp4 video file using MPMoviePlayerController showing error randomly

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.

Play background video in iphone App

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..

Why does my video play instantly in a UIWebView but takes forever to buffer and load with MPMoviePlayerController?

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];

Movieplayercontroller using a m4v with two audio tracks

I need use in my App a m4v video with two audio tacks. But when I play the video, it starts with the two audio tracks at the same time. I need to load the audio track with the device's default language (English by default).
Here is my code:
_moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[_moviePlayer shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeLeft];
_moviePlayer.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[self presentMoviePlayerViewControllerAnimated:_moviePlayer];
MPMoviePlayerController just as well as the wrapping MPMoviePlayerViewController do not support the selection of audio tracks.

Resources