AVPlayer not working on iPhone 5s 64bit iOS 7.0.3 - ios

I'm trying to figure out an issue that only appears on the iPhone5s having to do with an AVPlayer playing a video. The issue is that a movie will play on all devices I have tested so far except for the 5s 64bit model.
My theory is that it is tied to being 64bit but I haven't been able to tie it to anything. I found another stackoverflow post relating a similar issue with the fix being tied to using autolayout. However, I am not using autolayout.
This code has been working great until the 5s:
-(void)viewWillAppear:(BOOL)animated
{
self.player = [[AVPlayer alloc] initWithURL:[NSURL URLWithString:#"http://www.somemovieurlhere.mp4"]];
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
playerLayer.frame = self.view.bounds;
playerLayer.backgroundColor = [UIColor orangeColor].CGColor;
[self.view.layer addSublayer:playerLayer];
[self.player play];
}
I know the layer is added, because if you set the background color it shows up in the view, but no movie ever plays. In my project I can tell the movie is playing by logging out the "currentTime" property like so:
float time = CMTimeGetSeconds([player currentTime]);
Here is an image of the movie from an iphone4s and what I see in an iphone5s. I have also tested this with an original iphone5 and it works fine.
Any ideas as to what might be causing this? Thanks in advance for any help.

It looks like Apple's latest update 7.0.4 fixed this issue. Their update just came out today.
Thanks!

Related

AVPlayerViewController stuck on first frame of local video

In one of my ViewControllers, I have an AVPlayerViewController. In my viewDidLoad I have
self.videoPlayerController = [AVPlayerViewController new];
Then, I play a video using the following method
- (void)playVideo:(NSURL*)videoURL {
[self presentViewController:self.videoPlayerController animated:YES completion:^(){
AVPlayer *player = [[AVPlayer alloc] initWithURL:videoURL];
[self.videoPlayerController setVideoGravity:AVLayerVideoGravityResizeAspect];
[self.videoPlayerController setPlayer:player];
[self.videoPlayerController.player play];
}];
}
When playing a video for the first time, the AVPlayerViewController appears, but the video is stuck on the first frame, and will not play. No audio plays either.
In iOS 10.0, the seekbar in the on screen controls show that the video is playing (it will progress to the end). In iOS 10.2 however, the seekbar is stuck at 0:00 as well.
I am experiencing this problem on iPads with iOS versions 10.0 and 10.2, however, it works in the XCode simulator (both 10.0 and 10.2).
My problem is similar in nature to this.
Also, the video plays correctly if you close the ViewController containing the AVPlayerViewController, reopen it, and attempt to play the video again.
I guess that the problem is in your video file. Try to download another video mp4 video sample. Add it to your project and try.

Black video when using PBJVideoPlayer on iOS 10

I am using PBJVideoPlayer to show videos on my iOS app, using the following code:
_videoPlayerController = [[PBJVideoPlayerController alloc] init];
_videoPlayerController.delegate = self;
_videoPlayerController.view.frame = _playerView.bounds;
[self addChildViewController:_videoPlayerController];
[_playerView addSubview:_videoPlayerController.view];
[_videoPlayerController didMoveToParentViewController:self];
_videoPlayerController.videoPath = [self finalVideoPath];
On about 50% of the time, the video is shown as black while the sound is fine.
The bounds are good (since I do see a black box) and the video path is good since I do have the correct video created.
I am using a device with iOS 10, and I still do not have a device with an older iOS to check..
Any ideas what might be the problem? I have seen other questions regarding black videos but non of them help.
So, after several hours of investigating this, it seems to be an iOS10 bug.
See this: AVPlayer playback fails while AVAssetExportSession is active as of iOS 10
What worked for me, is removing the watermark layer I had on the video and then removing the animationTool property from the video composition

Objective-C MPMoviePlayerController iOS7 issue

I've seen this mentioned a few places around the web but have yet to find a concrete answer anywhere.
I'm trying to update an app so that it runs properly on iOS7. Part of that involves running a full-screen .mp4 video file (15.4mb / 40 Seconds long). Here is the code i use to setup the video, which runs fine in iOS6:
videoPlayer= [[MPMoviePlayerController alloc] initWithContentURL: [NSURL fileURLWithPath: [[NSBundle mainBundle]pathForResource: [NSString stringWithFormat:#"introIpad"] ofType:#"mp4"]]];
videoPlayer.fullscreen = YES;
videoPlayer.movieSourceType = MPMovieSourceTypeFile;
videoPlayer.view.frame = self.view.bounds;
[self.view addSubview:videoPlayer.view];
[videoPlayer play];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(videoFinished) name:MPMoviePlayerPlaybackDidFinishNotification object:videoPlayer];
As mentioned above this code ran perfectly on iOS6, however on iOS7 it now gives me the following error log:
_itemFailedToPlayToEnd: {
kind = 1;
new = 2;
old = 0;
}
I've seen a few people saying that all they had to do is change the name of the video files so i've tried that with no luck. I also found some people mention the movieSourceType being a problem but i've tried to set it to "MPMovieSourceTypeStreaming" and that didn't work either.
Bit of a frustrating one and any help someone can give me would be greatly appreciated!
Thanks in advance.
So it seems that this issue is a generic response when the device cannot play the video file.
I've tried with different encodings and multiple types of video without much luck.
However I've just tried a video with a different dimension and it plays, my original video file was 1536x2048 (iPad Retina resolution) and it doesn't like it. I've re-rendered the video out at 768x1024 (Half the original size) and it works perfectly.
It's not a very useful error log but i guess if you have the same problem as me then try as many different types of video and find the one that works.

prevent MPMoviePlayerController from automatically playing in iOS 4.2.1

I have an MPMoviePlayerController where I load a video from a URL. In iOS 3.2.2 the video started downloading when I added it to a view, but it didn't play until I hit the play button (which is what I want). However, since iOS 4.2.1 came out, it started behaving differently; the video starts downloading and plays automatically.
Here's how I load my MPMoviePlayerController:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc]
initWithContentURL:[NSURL URLWithString:theVideo.fileUrl]];
player.view.frame = articleVideoFrame;
[mainView addSubview:player.view];
I even tried to perform a [player pause]; after the addSubview part, but it still plays automatically. Could you guys help me with this one?
Got it! I used player.shouldAutoplay = NO; and that did the trick. Documentation says it is by default YES, which explains it all. Probably in 3.2 default was NO, but has been switched in 4.2.
I have noticed some other behavior changes in video playback in 4.2.1...namely the video player does not become visible until it starts receiving the data for the movie...
In the previous versions it used to come up instantaneously with "Loading movie..." text on top.
Sometimes, the player gets stuck in when not in full screen mode, with no Done button available or not responding to touches on Pause and Zoom...
I am having other more subtle issues with the playback but I can't isolate the issue just yet...

MPMoviePlayerController: Removing ±1sec black screen, when changing contentURL?

I'm working on an iPad project where i have to play short video files one after another smoothly. For playing the videos i'm using MPMoviePlayerController. The problem i'm facing is that when i call
[self.moviePlayer setContentURL:videoURL]
it does start the next video, but there is ±1 sec delay of black screen before it starts to play the next video (the videos are read from the disk, not streamed). I need to avoid this black screen as well as the delay.
So maybe some of you also experienced this problem and have some solutions? Thanks.
Btw, for now, as to at least avoid the black screen, I capture the last frame of the ending video, show it in a UIImageView, and remove it after 1 sec delay. But i'm hoping to find a more elegant fix.
The effect you are talking about is actually a combination of two problems: a black blink when you change the video (which doesn't happen upon assigning the video for the first time) and the delay before the controller starts playing video.
I'm currently screwed with the second one and don't know how to solve yet. As for the first one, just try to use another instance of MPMoviePlayerController. I mean when a video finishes playing (you can subscribe to a corresponding notification) just remove the old player, create a new one and put video there. This way you will avoid blinking, but there will be a delay (not sure, because of loading the video or because of player creation) before the next video starts playing.
Hope this helps a bit.
Fond solution here
http://joris.kluivers.nl/blog/2010/01/04/mpmovieplayercontroller-handle-with-care/
you need to use [self.moviePlayer prepareToPlay]; and catch MPMoviePlayerReadyForDisplayDidChangeNotification to use [self.moviePlayer play];
Old post but Googlers will still come. :)
Creating a new MPMoviePlayerController then assigning it back to my previous player worked for me, no more black screen!
...
[self playVideoWithFilename:#"video1.mp4"];
}
- (void)playVideoWithFilename:(NSString *)fileName
{
MPMoviePlayerController *player = [MPMoviePlayerController new];
_myVidPlayer = player;
player = nil;
NSURL *vidPath = [[NSBundle mainBundle] URLForResource:fileName withExtension:nil];
[_myVidPlayer.view setBackgroundColor:[UIColor whiteColor]];
[_myVidPlayer.view setFrame:CGRectMake(0, 64, 320, 320)];
[_myVidPlayer setContentURL:vidPath];
[_myVidPlayer setControlStyle:MPMovieControlStyleNone];
[_myVidPlayer setRepeatMode:MPMovieRepeatModeOne];
[_myVidPlayer prepareToPlay];
[self.view addSubview: _myVidPlayer.view];
[_myVidPlayer play];
}
Note:
Available in iOS 2.0 and later
Deprecated in iOS 9.0
"Use AVPlayerViewController in AVKit."
I think that the problem is that the controller will fade out and back in between the movies.
You can control the background view color and contents, but I'm not sure that you can eliminate the fade in/out.

Resources