After the release of iOS 13, there was some exception in one of our video playback interfaces.
This interface is to play video using MPMoviePlayerController.
In some cases, videos that would only be played once will now automatically loop.
At the same time, the MPMoviePlayerPlaybackDidFinishNotification notification is also not received.
From the feedback of users, this problem will only appear on iOS13 devices.
After testing, I found that only one iPhone11 in all iOS13 devices will have this problem, and other iOS13 devices (including another iPhone11) have no such problem.
When the problem occurred, I printed the value of the repeatMode property and found that it is still 0.
Later I tried to manually set the repeatMode to MPMovieRepeatModeNone and found that this problem still occurs.
Some additional information:
1) For some reason, I am still using Xcode10.3 (Base SDK: iOS12.4) to compile the project, so using MPMoviePlayerController does not crash directly.
2) The problematic device is the partner's test machine, so I can only remotely instruct them to test, there is no way to debug locally.
Here is the code I used to test:
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"test" ofType:#"mp4"];
NSURL *url = [NSURL fileURLWithPath:filePath];
self.playerController = [[MPMoviePlayerController alloc] init];
[self.playerController setScalingMode:MPMovieScalingModeAspectFit];
[self.playerController.backgroundView setBackgroundColor:[UIColor clearColor]];
self.playerController.movieSourceType = MPMovieSourceTypeFile;
[self.playerController setControlStyle:MPMovieControlStyleNone];
[self.playerController.view setFrame:self.view.bounds];
self.playerController.view.userInteractionEnabled = YES;
[self.view addSubview:self.playerController.view];
self.playerController.contentURL = url;
[self.playerController prepareToPlay];
[self.playerController play];
Related
Actually i am using MPMoviePlayerViewController in our app . And my code perfectly working in iOS 8.4 but when i upload my app into iPad (iOS 9 ) its not working ...
I am create ViewController to play two video one by one but when one video is completed or stop the controller going to my first page of app and behave unespected in iOS 9 .I am using custom MPMoviePlayerViewController to play video and put one button on first video to change other video but its not working...
NSURL *URL = [[NSBundle mainBundle] URLForResource:#"video" withExtension:#"mp4"];
self.indiaplayer = [[MPMoviePlayerController alloc] initWithContentURL:URL];
self.indiaplayer.view.frame = CGRectMake(0, 0,1024,718);
[self.indiavideoThumbnail addSubview: self.indiaplayer.view];
self.indiaplayer.controlStyle = MPMovieControlStyleNone;
self.indiaplayer.fullscreen = YES;
self.indiaplayer.repeatMode = YES;
[self.indiaplayer prepareToPlay];
self.indiaplayer.shouldAutoplay = NO;
self.indiaplaybackView = [[UIView alloc] initWithFrame:CGRectZero];
self.indiaplaybackView.backgroundColor = [UIColor colorWithRed:242.0/255 green:163.0/255 blue:10.0/255 alpha:1];
//self.playbackView.layer.cornerRadius = 2;
[indiaView addSubview:self.indiaplaybackView];
self.indiaslider.minimumValue = START;
self.indiaslider.maximumValue = END;
Thanks in advance
wait wait in iOS 9.x.x
IMPORTANT
The MPMoviePlayerViewController class is formally deprecated in iOS 9. (The MPMoviePlayerController class is also formally deprecated.) To play video content in iOS 9 and later, instead use the AVPictureInPictureController or AVPlayerViewController class from the AVKit framework, or the WKWebView class from WebKit.
For more detail
https://developer.apple.com/library/ios/documentation/MediaPlayer/Reference/MPMoviePlayerViewController_class/
I am little bit confused about the behaviour.
What I want to do is,
I am having two different application.
One is made by me and other is by a guy who left the company & now I have to complete his projects.
But the task to be done in both project is same.
I have to show 5 sec video when I open the app every time.
Like Some branding video. (Done in angry birds app)
I checked all the links on SO, but didn't helped any one.
My senior who left the company, he have used Main.storyboard for navigation each screen.
and I am not that much good in using storyboard.
In my app, I created navigation programatically.
When my splash screen disappears,
I show dashboard.
But before showing dashboard, I have to show the video every time.
So what I did,
I created a view controller only for Video named VideoViewController,
and call that view controller from ViewDidLoad of dashboardView.
and when my video finished,
then by using NSNotificationCenter I removed the VideoViewController.
When I Nslog the url path, its printing correct, but My app crashes after that.
I checked it by applying ExceptionalBreakpoints, but didn't helped.
Here is my code to launch video in ViewDidLoad of VideoViewController
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"video" ofType:#"mp4"]];
NSLog(#"video path :- %#",url);
playercontroller = [[MPMoviePlayerController alloc] init];
[playercontroller setContentURL:url];
[playercontroller.view setFrame:CGRectMake (0, 0, 320, 460)];
[self.view addSubview:playercontroller.view];
[playercontroller play];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:playercontroller];
and I am pushing VideoViewController from dashboard's
-(void)viewDidAppear:(BOOL)animated
method.
As I am doing any thing wrong.
As My url is getting Nslg well, so no doubt of loading video.
Please guide me for the same.
also guide me to achieve same task using storyboard.
Thanks in advance.
you shouldn't hardcode set the frame like that though..
Assuming 'self' is a ViewController (which has been properly addChildViewController'ed all the way from the RootViewController), try the next thing:
NSString *path = [[NSBundle mainBundle] pathForResource:videoFileName ofType:#"mp4"];
NSURL *url = [NSURL fileURLWithPath:path];
MPMoviePlayerViewController *videoController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:videoController];
[videoController.moviePlayer play];
I am trying to play a video file (m4v) from resource folder of my app (i.e local video). but I am not able to play the video. I referred apple's sample project for the MPMoviePlayer.
Also when i am giving background color to my movieplayercontroller object its appearing as its behind some black view and the black view ahead is showing that something is loading for few seconds but nothing get loaded and it results in black screen only.
Can someone help me out with it. please tell me what i am doing wrong.
Also, i have taken screenshot of the screen with problem so that you all can understand what i am trying to say but i dont know how to post it here. :(
NSString *urlString = [[NSBundle mainBundle] pathForResource:#"Movie" ofType:#"m4v"];
NSURL *urlObj = [NSURL fileURLWithPath:urlString];
UIGraphicsBeginImageContext(CGSizeMake(1,1));
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:urlObj];
UIGraphicsEndImageContext();
[player.view setBounds:self.view.bounds];
// when playing from server source type shoud be MPMovieSourceTypeStreaming
[player.moviePlayer setMovieSourceType:MPMovieSourceTypeStreaming]; // I was missing this line therefore video was not playing
[player.moviePlayer setScalingMode:MPMovieScalingModeAspectFill];
[self.view addSubview:player.view];
[player.moviePlayer play];
I just want to load a video file which is in the main bundle, this seems pretty simple but for some reason I keep getting an error of the MPMoviePlayerController, I have the following code.
- (void)viewDidLoad{
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:#"ipad2" ofType:#"mp4"];
self.myPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:path]];
[self.myPlayer prepareToPlay];
self.myPlayer.movieSourceType = MPMovieSourceTypeFile;
[self.myPlayer.view setFrame:self.view.bounds];
[self.view addSubview:self.myPlayer.view];
[self.myPlayer play];
}
I only get a black screen and the following output:
2013-01-09 13:38:15.686 myVideoApp[1789:907] [MPAVController] Autoplay: Likely to keep up or full buffer: 0
2013-01-09 13:38:15.690 myVideoApp[1789:907] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.
I also tried adding these notification for playing but is never sent:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(playVideo:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:self.myPlayer ];
And when I print self.myPlayer.loadState I get 0which is undefined loadState.
These is a simple viewController with any other method, and I have these declaration on the .h file:
#property (nonatomic, strong) MPMoviePlayerController *myPlayer;
I`m running on iOS 6, and these happens both in device and simulator
NSString *path = [[NSBundle mainBundle] pathForResource:#"ipad2" ofType:#"mp4"];
Have you checked in the debugger that path is not nil?
self.myPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:path]];
That's the wrong way to create a URL from a file path. Use +[NSURL fileURLWithPath:] instead.
I also using the MPMoviePlayerViewController to live video on my app and getting same above list errors.And I found MPMoviePlayer not support larger data to show video but if you used smaller data of video is working fine its not give any error. In fact is not problem of prepare to play and play property of movie player.
If you need to show larger data then used webview on your app.
I was very delighted to see that when "upgrading" to Xcode 4.5, now none of the videos in my app play at all.
Generally I do something like this:
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[self getBundleClip:#"theVideo"]];
self.moviePlayer.controlStyle = MPMovieControlStyleNone;
self.moviePlayer.shouldAutoplay = YES;
self.moviePlayer.repeatMode = MPMovieRepeatModeOne;
self.moviePlayer.view.frame = self.container.frame;
self.moviePlayer.view.userInteractionEnabled = NO;
[self.container addSubview:self.moviePlayer.view];
- (NSURL*)getBundleClip:(NSString*)clip
{
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:clip ofType:#"mp4"];
return [NSURL fileURLWithPath:moviePath];
}
Again, everything played perfectly before I updated Xcode to 4.5. Anyone else have this issue?
I also get this output:
[MPAVController] Autoplay: Disabling autoplay for pause
[MPAVController] Autoplay: Disabling autoplay
I suppose that you define it within function?
if you use ARC, you have to retain MPMoviePlayerController
Add it to interface file!
#property(nonatomic, strong) MPMoviePlayerController *moviePlayer;
I'm not sure why it is not playing specifically, but it looks like behavior is different depending on which version of iOS SDK you build against. Look at the MPMoviePlayerController documentation.
In particular, you may want to try calling the prepareToPlay method on the movie player.