Playing subsequent movies in one MPMoviePlayerViewController - iphone

I am having a difficulty with the MPMoviePlayViewController.
I insatiate the controller, assign the url and show the player using:
[self presentMoviePlayerViewControllerAnimated:[appDelegate movieController]];
Then when the movie finished I dismiss it:
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[self dismissMoviePlayerViewControllerAnimated];
The movie player is alloc in my AppDelegate.
There are some other listeners on MPMoviePlayerPlaybackDidFinishNotification. This is for the case where there might e.g. only be audio and it shows a play/pause button and counters in table cells.
The problem is that when I load a second movie in the same MPMovieViewController, it appears fine but the controls are not working correctly. They are work as long as they are visible, but as soon as they disappear there is no may of getting them back and therefore to dismiss the movie player.Sometimes closing and opening the App works, but sometimes it doesn't and I need to 'kill' the App in order to be able to start again.
Is there a way to play subsequent video's in the MoviePlayer while the controls still work?
Any suggestions how to 'reset' the Player in a way that I can prevent the other listeners from given a DEALLOC as they are listening for the action?

you dont need to dismiss the player you just need to set the new url... or maybe I missunderstood your problem...
Try adding this to your setup movie player controller
moviePlayerController.view.userInteractionEnabled = YES;

Related

Status Bar keeps showing up when dismissing MPMoviePlayerViewController

I'm making an app where I need to play a movie from my camera roll. I'm using MPMoviePlayerViewController to do is, and displaying it with:
[self presentMoviePlayerViewControllerAnimated:theMovie];
I want it to run in fullscreen mode:
[theMovie.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
This is where the issue comes up. I don't want the Options to be displayed upon launch, so I decided to set the control style to MPMovieControlStyleNone initially. But I still want the options to be available, so after searching around I found this option:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(enterFullScreenMode)
name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
And in this method I change the control state to MPMovieControlStyleFullscreen. This causes the status bar to be displayed in my app AFTER I dismiss the movie and return to my parent view controller. My application doesn't use the status bar at all. I've tried this:
[[UIApplication sharedApplication] setStatusBarHidden:YES];
And it didn't work. I should point out this issue only shows up if I start with control state None and then switch to Fullscreen while the movie is playing, but I need to do this because I don't want the options to show up upon launch. I'm open to any ideas. Please help me eliminate the status bar once and for all.
Thanks guys :)

iOS presentMoviePlayerViewControllerAnimated can't be called twice using the same viewController

So I'm trying to present a MPMoviePlayerViewController using the method presentMoviePlayerViewControllerAnimated in my own view controller.
However, once I clicked the blue Done button on the top left, when I present the same viewController again (so that I can resume a video without having to create another instance of MPMoviePlayerViewController), the controls will no longer work if you let them disappear on their own after a few seconds. The controls will still function if you interact with them before they disappear, but once they fade away on their own, you can no longer bring them back up when tapping the video. This happens on both the device and the simulator.
Simplified code:
- (void) startPlayback
{
if (self.videoViewController == nil)
{
self.videoViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:self.videoUrl]];
}
// present the video player
[self presentMoviePlayerViewControllerAnimated:self.videoViewController];
}
assume that startPlayback is a delegate method or something in a view controller, and it's being triggered by a button. Self would refer to the view controller in this case.
So with this, it will bring up the video player which works perfectly. Then, once I wait a bit, the controls will disappear and I can bring them back by tapping the video. I can then dismiss this video player using the Done button on the top left. Once I dismiss it, and I can then bring back the video view controller. The video will still be playing, but now, when I wait a bit and the controls disappear, I can no longer bring up the controls by tapping the screen, effectively trapping myself in the video player.
I have found various solutions into hooking into the Done button, but it hasn't really allowed me to reuse the video player. For example:
// Remove the observer so that the blue button doesn't close the viewController
[[NSNotificationCenter defaultCenter] removeObserver:self.videoViewController name:MPMoviePlayerPlaybackDidFinishNotification object:self.videoViewController.moviePlayer];
// Add itself as an observer
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(movieEnded:) name:MPMoviePlayerPlaybackDidFinishNotification
object:self.videoViewController.moviePlayer];
In my movieEnded:, I can then dismiss the movie view controller via:
[self dismissMoviePlayerViewControllerAnimated];
But when I try to present the viewController again, the video player just gets stuck Loading... forever.
Any ideas?

how to perform different actions for the done button and the video player finish method of embedded youtube webview in iPhone

I am new to iPhone. Please help me in solving this issue:
I have embedded YouTube webview in Iphone. My problem is when clicking the done button of YouTube I want to call a class and when the video finishes playing an different class should be called. Can anybody help me on identifying what are the methods called on click of done button and finish of YouTube player in iPhone?
Thanks
If the video is played in UIWebView then you can access when the video is played and when Done button is pressed using the following code along with the code you have used to load url in webview
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(videoPlayStarted:) name:#"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
//For Done Button
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(videoPlayFinished:) name:#"UIMoviePlayerControllerDidExitFullscreenNotification" object:nil];
And it can be accessed through
BOOL isVideoInFullScreenMode;//Temperory added here.. must be in .h file or at teh top if required
-(void)videoPlayStarted:(NSNotification *)notification{
//Your stuff here
isVideoInFullScreenMode = YES;
}
-(void)videoPlayFinished:(NSNotification *)notification{
//Your stuffs here
isVideoInFullScreenMode = NO;
}
You are in a UIWebView, so the done button isn't related to your application: pressing the button will never call your application.
The only method you have are from UIWebViewDelegate and they are:
webView:shouldStartLoadWithRequest:navigationType:
webViewDidStartLoad:
webViewDidFinishLoad:
webView:didFailLoadWithError:
If you have to know when player finish, I suggest you to try this class: LBYouTubeView, it will play youtube video on your player component, so you can use Player delegate's method to to do what you asked for.

Control done button

I have a view with some objects, one of them is a webview where I play a video, this view change the size and the position of the object when the device rotates. The problem occurs when I am playing the video in full screen, if I start watching the video in landscape and while I am watching the video (full screen) I rotate the device and then I hit the done button when I return to the view the objects are not in the position that they should be in that orientation.
I set the position in a function, I call that function in viewdidload and also in willAnimateRotationToInterfaceOrientation but how can I control the rotation while I am watching the video?
You could do something like this:
-(void) viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(playerPlaybackDidFinish:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
}
- (void) playerPlaybackDidFinish:(NSNotification*)notification
{
[self resizeSubviews];
}
So, when the playback finishes, you call your method to resize your subviews, and by the time the player closes, your view should look correct for the orientation.
You could also register for MPMoviePlayerWillExitFullscreenNotification instead, if that more properly fits your needs.

How to play video in iphone landscape mode?

I have one application in which list of videos that are coming through xml parsing are displayed in tableview. When I click particular video it should be played in landscape mode.
For that I followed tutorial:
http://iosdevelopertips.com/video/how-to-play-movies-from-application-bundle-or-from-a-remote-server-url.html
It works perfectly but it uses separate modalcontroller so when I press done button on the video or completed video is completed it returns to the that modal view and on which
back button appears and when I press that back button after that I can go back to list of videos screen.but I want to go directly back to the screen which displays list of videos.
for that if i write code using pushviewcontroller than application crashes.How can i solve this problem.any tutorial or sample code?
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
// Remove observer
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[self dismissModalViewControllerAnimated:YES];
DonationVideoViewController *dvvc=[[DonationVideoViewController alloc] initWithNibName:"DonationVideoViewController" bundle:nil];
[self.navigationController pushViewController:dvvc animated:YES];
}
UPDATE:I have solved the issue by using the code for calling custommovieplayercontroller in the same class where I have displayed the list of videos. So now video ends it remains to the page I want and I need to go to other page using pushviewcontroller
You should probably push dvvc in viewDidDisappear. But like Till says, we need to see the error message you are getting.