Black video when using PBJVideoPlayer on iOS 10 - ios

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

Related

MPMoviePlayerViewController locks up application with unusual appearance?

So, I've tried this a number of ways with the same result.
I've tested by using a YouTube MP4 URL, such as:
This
The way I do it looks pretty much like:
self.moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:videoUrlString]];
And then I play the video. If I play the video and it goes fullscreen, the whole app locks up. The video player appears, but parts of the status bar (such as the time and bars) disappear leaving only the carrier name. The volume slider is only half there, and it loads indefinitely, and ignores any further touch input until I kill the app. If I rotate the iPhone, the volume slider and the rest of the status bar reappear, but it still will not respond to touch or finish loading. Screenshot of issue.
If, instead, I pass the MPMoviePlayerViewController object to a UINavigationController with presentViewController:, the app seems to hang: until I rotate, then suddenly the video appears correctly and starts playing! However, again, all touch input is ignored and the application is essentially locked.
This is one of the strangest issues I've troubleshot.
So I tried using tools others have built. I tried XCDYouTubeKit and YKMediaKit using the Youtube ID instead of the direct link, with the exact same result. After looking at their code, they both use MPMoviePlayerViewControllers.
What's happening here? Can anyone help me figure out what's wrong?
That's surprising. Have you tried playing around with AV Foundation? It's a more modern media API than MediaPlayer.framework.
If you can target iOS 8 only, then AVPlayerViewController is a simple way to playback media via AVPlayer.

AVPlayer not working on iPhone 5s 64bit iOS 7.0.3

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!

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

iOS - How to play a video with transparency?

I recorded a video with a bluescreen. We have the software to convert that video to a transparent background. What's the best way to play this video overlaid on a custom UIView? Anytime I've seen videos on the iPhone it always launches that player interface. Any way to avoid this?
Don't know if anyone is still interested in this besides me, but I'm using GPUImage and the Chromakey filter to achieve this^^ https://github.com/BradLarson/GPUImage
EDIT: example code of what I did (may be dated now):
-(void)AnimationGo:(GPUImageView*)view {
NSURL *url = [[NSBundle mainBundle] URLForResource:#"test" withExtension:#"mov"];
movieFile = [[GPUImageMovie alloc] initWithURL:url];
filter = [[GPUImageChromaKeyBlendFilter alloc] init];
[movieFile addTarget:filter];
GPUImageView* imageView = (GPUImageView*)view;
[imageView setBackgroundColorRed:0.0 green:0.0 blue:0.0 alpha:0.0];
imageView.layer.opaque = NO;
[filter addTarget:imageView];
[movieFile startProcessing];
//to loop
[imageView setCompletionBlock:^{
[movieFile removeAllTargets];
[self AnimationGo:view];
}];
}
I may have had to modify GPUImage a bit, and it may not work with the latest version of GPUImage but that's what we used
You'll need to build a custom player using AVFoundation.framework and then use a video with alpha channel. The AVFoundation framework allows much more robust handeling of video without many of the limitations of MPMedia framework. Building a custom player isn't as hard as people make it out to be. I've written a tutorial on it here:
http://www.sdkboy.com/?p=66
I'm assuming what you're trying to do is actually remove the blue screen in real-time from your video: you'll need to play the video through OpenGL, run pixel shaders on the frames and finally render everything using an OpenGL layer with a transparent background.
See the Capturing from the Camera using AV Foundation on iOS 5 session from WWDC 2011 which explains techniques to do exactly that (watch Chroma Key demo at 9:00). Presumably the source can be downloaded but I can't find the link right now.
The GPUImage would work, but it is not perfect because the iOS device is not the place to do your video processing. You should do all your on the desktop using a professional video tool that handles chromakey, then export a video with an alpha channel. Then import the video into your iOS application bundle as described at playing-movies-with-an-alpha-channel-on-the-ipad. There are a lot of quality and load time issues you can avoid by making sure your video is properly turned into an alpha channel video before it is loaded onto the iOS device.
Only way to avoid using the player interface is to roll your own video player, which is pretty difficult to do right. You can insert a custom overlay on top of the player interface to make it look like the user is still in your app, but you don't actually have control of the view. You might want to try playing your transparent video in the player interface and see if it shows up as transparent. See if there is a property for the background color in the player. You would want to set that to be transparent too.
--Mike
I'm not sure the iPhone APIs will let you have a movie view over the top of another view and still have transparency.
You can't avoid launching the player interface if you want to use the built-in player.
Here's what I would try:
get the new window that is created by MPMoviePlayerController (see here)
explore the view hierarchy in that window, using [window subviews] and [view subviews]
try to figure out which one of those views is the actual player view
try to insert a view BEHIND the player view (sendSubviewToBack)
find out if the player supports transparency or not.
I don't think you can do much better than this without writing your own player, and I have no idea if this method would work or not.
Depending on the size of your videos and what you're trying to do, you could also try messing around with animated GIFs.
if you could extract the frames from your video and save them as images then your video could be reproduced by changing the images. Here is an example of how you could reproduce your images so that it looks like a video:
in this image that I uploaded the names of the images have a different name but if you name your images as: frame1, fram2, fram3.... then you could place that inside a loop.
I have never tried it I just know it works for simple animations. Hope it works.

Resources