Objective-C MPMoviePlayerController iOS7 issue - ios

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.

Related

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

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!

MPMoviePlayerController restarting instead of resuming

I am trying to have MPMoviePlayerController reach a programmed endPlaybackTime, then reassign the initial, current, and end times and "resume" play
So first play, say, from the start to 4 seconds, stop/pause, then resume and play from 4 to 8, etc...
but after I reassign current, initial, and endPlaybackTimes and run [mplayer play], the video restarts from the originally times (start to 4s) and plays to the original end time, even though debug messages confirm the new times after the second play
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
_mplayer3 = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
_mplayer3.controlStyle = MPMovieControlStyleNone;
[_mplayer3.view setFrame: self.view.bounds];
[self.view insertSubview:_mplayer3.view belowSubview:_TopBrag];
_mplayer3.endPlaybackTime = 4.0;
[_mplayer3 setShouldAutoplay:NO];
[_mplayer3 prepareToPlay];
[_mplayer3 view].userInteractionEnabled=YES;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(parallaxDownDidFinish)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_mplayer3];
[_mplayer3 play];
on the end notification, there's a gesture recognizer is created that appears to work correctly. in the gesture recognizer:
_mplayer3.initialPlaybackTime=_mplayer3.endPlaybackTime;
_mplayer3.currentPlaybackTime=_mplayer3.endPlaybackTime;
_mplayer3.endPlaybackTime+=4.0;
if (_mplayer3.endPlaybackTime > _mplayer3.duration)
_mplayer3.endPlaybackTime = _mplayer3.duration;
[_mplayer3 play]
and the video plays from 0 to 4 instead of 4 to 8, even though NSLogs after the play suggest the times are what's desired
appreciate any help
MPMoviePlayerController does not adhere to the initialPlaybackTime if not used on a fresh instance. You will need to release and realloc/assign the player to get this working. All you need to do is to reuse the initial code shown in your question once the player aught to continue.
Update:
Since you seem to be keen on keeping the player view active and as you are not using the standard user interface, I would suggest you to use AVPlayer instead. It is much more flexible and for your job it seems to be the right choice then.
I'm not sure whats the problem, because it should work, the problem i think is that you are in IOS 6, IOS 6 doesn't let you make such a small change, but if in your swipe you change the initial playtime to 9 or higher it should work....
try it and then let me know ;)

Play Multiple Videos from one page

Ok, so I am creating a basic iPad app that needs to play 4 videos. Videos need to be accessed from the same page.
I have one page/landing screen with an image that I have placed 4 Round Rec Buttons on. The MediaPlayer/MediaPlayer.h framework works perfectly, exactly what I want. But right now all four buttons play the same video, mainly because there is only one set of code but that is my problem. I assumed that repeating the code would allow me to replace the pathForResource:#"Beginning_Bumper" ofType:#"m4v" section of code but I get re-implimentation errors and the build fails. I've tried looking for other apps or tutorials online with no results. Also thought this question was my answer, but nothing there.
Here is the code I have, without duplication. So this code just plays one of the videos. Hopefully all of that makes sense, but feel free to ask more questions.
#import "Video_Presentation1ViewController.h"
#implementation Video_Presentation1ViewController
-(IBAction)playvideo {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"Beginning_Bumper" ofType:#"m4v"]];
MPMoviePlayerViewController * playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playerController];
playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[playerController.moviePlayer play];
[playerController release];playerController=nil;
}

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