MPMoviePlayerController showing up late with http url request - ipad

I'm developing an iPad app with 4.1 and deployment-target 3.2.
I have a UITableViewController which adds a new View to the main view if a row becomes selected.
In the UIViewController of the new view I've following code in the viewDidLoad method:
- (void)viewDidLoad
{
MPMoviePlayerController* player = [[MPMoviePlayerController alloc] initWithContentURL:movieurl];
[[self.view viewWithTag:1] addSubview:player.view];
player.view.frame = CGRectMake(0, 0, 512, 289);
[player play];
[super viewDidLoad];
}
movieurl is an URL with a http address of our CDN.
the viewWithTag:1 is a simple standard UIView with the same frame like the player.
Now, if I click on the tablerow, the new view appears with the subview (with tag 1) in it.
And the player is not showing up. After some time, when the movie is ready to play, the movieplayer shows up like wanted and starts playing the movie.
The movieplayer works fine, it only appears really lately.
Is there any way to show the movieplayer directly on the view? Just before the movie has finished preloading. The player can be in a loadingstate or something like this.
The mainpoint is, that the player shows up from beginning, so there's no empty space in the view.
Thank you for your help!

I have the same question and a comment that before I upgraded to the most recent XCode that forced me to use 4.2 as base SDK this was working fine for me. I had 4.1 iPhone and the player showed up immediately with Movie Loading... label ...
This is no longer the case after upgrade and 4.2 base sdk selection even with 3.2 as target.

Related

iOS - MPMoviePlayerController resets view transform on repeat

Using an MPMoviePlayerController.view as a background (think spotify). A user can tap login or signup and they are taken to the appropriate viewController, which has a clear background so that the moviePlayer.view remains as the background (i.e., user continues to see the video regardless of the currently active viewController) throughout the flow.
On some viewControllers the form needs to be lifted up so that the keyboard doesn't cover the field. I'm doing this using a transform.
The background video of the moviePlayer is set to repeat, so the video is on a continuous loop. Each time the video resets (video status goes from 1 to 2 - paused to playing) the transform resets in the child viewControllers. My initial thought was that the view was being redrawn, but this doesn't appear to be the case based on logs (I put nslogs in the drawRect of the views but it's only ever called once at instantiation).
Has anyone come across this?
My setup in the root viewController:
// lazy load moviePlayer
-(MPMoviePlayerController *)moviePlayer
{
if (_moviePlayer) return _moviePlayer;
NSURL *videoURL = [[NSBundle mainBundle] URLForResource:#"resources.bundle/videos/auth_bg" withExtension:#"mp4"];
_moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
_moviePlayer.controlStyle = MPMovieControlStyleNone;
_moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
_moviePlayer.repeatMode = MPMovieRepeatModeOne;
_moviePlayer.shouldAutoplay = true;
return _moviePlayer;
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
self.moviePlayer.view.frame = self.view.frame;
self.moviePlayer.view.hidden = false;
// 'still' is an imageView of the first frame to show while video loading
[self.navigationController.view insertSubview:self.moviePlayer.view aboveSubview:still];
}
I suspect this has to do with Autolayout -- I found a few other questions where views were being reset (one example here: https://stackoverflow.com/a/17849584/1542275) ... My solution was to adjust the layout constraint constants as opposed to transforming the view coordinates. Things are now staying put.
All of that said, I'm still not sure why the video restart is resetting the transforms.

Play video in app instead of default player

I use the following code to play videos:
MPMoviePlayerViewController *theMovie=
[[MPMoviePlayerViewController alloc] initWithContentURL: movieURL];
theMovie.moviePlayer.repeatMode=MPMovieRepeatModeOne;
[self presentMoviePlayerViewControllerAnimated:theMovie];
This causes a the default movie player to cover the app. Instead I want the video to play inside the app itself as follows:
Can this be achieved?
You can set its frame like this:
theMovie.view.frame = CGRectMake(10, 10, 300, 300);
Then without presenting it add it as subview:
[self.view addSubview: theMovie.view];
Hope this helps.. :)
Yes, this can be achieved by using the AVPlayerLayer. Please see examples here:
"AV Foundation Programming Guide", "Putting It All Together: Playing a Video File Using AVPlayerLayer" section
A tutorial from the iosguy.com
Appuccino's "Playing Movies With AVPlayerLayer In iOS 6" video tutporial

Control buttons in AVPlayer and frame

I have to play a series of videos in my app. I am using AVQueuePlayer to play the videos using the code:
AVQueuePlayer *queuePlayer = [[AVQueuePlayer alloc] initWithItems:items];
AVPlayerLayer *myPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:queuePlayer];
myPlayerLayer.frame = CGRectMake(0, 0, 320, 350);
[self.view.layer addSublayer:myPlayerLayer];
[self.queuePlayer play];
I am facing two issues.
When the video plays, the frame of player is not according to the given values(i.e. 0, 0, 320, 350).
No control buttons(volume,play,stop, forward etc) are being showed as they are shown when we play video with MPMediaPlayer. Am i missing something for both cases?
(I am using AVFoundation for the first time so these questions may seem stupid).
Thanks in advance.
When the video plays, the frame of player is not according to the
given values(i.e. 0, 0, 320, 350).
Apple's sample code doesn't use -playerLayerWithPlayer:. It creates a UIView subclass whose layer is an AVPlayerLayer. Perhaps there's a reason for that. I do that in my code and it works great. Take a look at the AVPlayerDemo code and try doing it that way.
No control buttons(volume,play,stop, forward etc) are being showed as
they are shown when we play video with MPMediaPlayer. Am i missing
something for both cases? (I am using AVFoundation for the first time
so these questions may seem stupid).
AVPlayer does not provide these for you. That's what MPMoviePlayerController is for. If you want controls and you want to use AVPlayer, you'll need to create and manage the controls yourself.
As an alternative to Dave's answer to your first question...
If using auto layout, you can store, as a local property, a reference to the player's layer returned by playerLayerWithPlayer: and update its frame whenever the view controller's view lays out its subviews -
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
self.playerLayer.frame = self.view.layer.bounds;
}
Or if you're working in a UIView subclass -
- (void)layoutSubviews
{
[super layoutSubviews];
self.playerLayer.frame = self.layer.bounds;
}
This assumes that you would like the player to fill the view; you can update the code if you have other intentions.

MPMoviePlayerController stops and resets the movie when user tries to play fullscreen [iOS]

I embedded a MPMoviePlayerController on my mail view. I can play/pause the movie and seek forward/backward. But when I touch the "fullscreen button" the movie stops and the playback state is set to MPMoviePlaybackStateStopped... Should the movie be played in full screen?
Here is my code:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoUrl];
player.shouldAutoplay = NO;
player.movieSourceType = MPMovieSourceTypeFile;
player.controlStyle = MPMovieControlStyleEmbedded;
player.allowsAirPlay = YES;
player.view.frame = CGRectMake(xPos, yPos, width, height);
[self.view addSubview:player.view];
I found my bug: when pressing the full screen toggle button in MPMoviePlayerController's view, the method "viewWillLayoutSubviews" is invoked. I could never imagine this behavior...
I hope my experience can be useful to other developers.
Remember that any containing ViewController will have its viewWillDisappear, viewDidDisappear methods invoked when the MPMoviePlayerController goes full screen. Also, viewWillAppear and viewWillDisappear get called when it comes back from full screen.
If you have any logic in there that affects video playback behavior, it'll get called unless you use some conditional logic to see if the video is still playing.

iOS movie player controls jump to middle of player at end of video

My application uses HTTP Live Streaming to play video files. We have run into a problem where as soon as the stream ends the player controls jump from the bottom of the player to the middle as seen in this screenshot (http://postimage.org/image/1dvr9u338/). Is this expected behavior and if not, any thoughts on what is happening?
If the application plays a non-live streaming video, such as an mp4, everything works fine. But as soon as we play a live-streaming video (m3u8), such as Apple's sample streaming video (http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8) this issue occurs.
The application supports iOS 4.2+ and the issue occurs on every version. I have tested this with a brand new project that just embeds an MPMoviePlayerController's view and plays the video. Below is some sample code that loads the contentURL, embeds the view, and plays the video.
- (void)viewDidLoad
{
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:#"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"]];
moviePlayerController.view.frame = CGRectMake(100, 100, 600, 400);
[self.view addSubview:c.view];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidAppear:(BOOL)animated
{
[moviePlayerController play];
[super viewDidAppear:animated];
}

Resources