When I press "DONE" while playing movie using MPMoviePlayerController which view will get displayed - iphone

I am playing movie using MPMoviePlayerController,
I am using TableView,what happening with my application is when I press accessory button it will display detailed view and when I press cell area it will play movie that I wanted,(the way youtube application does)
but when I press "DONE" while playin movie it'll navigate to a view which is not my detail view but some empty view.
Any idea what should I do to achieve it so that when user press "DONE" it will nevigate me to my detail view instead of some empty view.
I tried to push view when "movieFinishedCallback" is executed but it'll pushing one more view on that empty view.

Ideally if your code is correct, pressing the Done button on MPMoviePlayerController object would close the MPMOviePlayerController and return to the controller which invoked it (which in your case is the detail view)
You do not need to do anything in the movieDidFinishCallback except maybe release the movieplayer object.

-(void)myMovieFinishedCallback:(NSNotification*)aNotification {
MPMoviePlayerController* theMovie = [aNotification object];
theMovie.initialPlaybackTime = -1.0;
}

Related

Having a Movie as a transition between two View Controllers - where to put this code?

My whole goal is to have a button on the main view, when you press this button a video plays and when the video is done playing you're now at the second view. The quick video is like a transition between the two VCs. My question is where should I put the 'play movie' code. Here are the scenarios I've tried and the unsatisfying outcomes:
The button in Main VC plays the movie and opens second VC - The movie plays but the second view controller doesn't open, just goes back to the main VC.
The button in Main VC plays the movie and the NSNotification for moviePlayBackDidFinish opens the second VC - same result as above.
The button in Main VC switches to second VC and movie code is in second VC's viewDidLoad (also viewWillLoad, same result) - VC switches but movie doesn't play
The button in Main VC switches to second VC and movie code is in second VC's viewDidAppear - second VC appears then movie plays continuously (not what I want).
What is the best way to set up the code to get the transition effect I'm looking for? Should I make a third View Controller in between the two just to play the movie? Here is the code I'm using to play the movie:
//Sets up the movie file to play
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"TransitionMovie" ofType:#"mov"]];
_moviePlayer = [[MPMoviePlayerViewController alloc]
initWithContentURL:url];
//Creates notification observer so it knows when the movie is done playing
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayer];
//Plays the movie
[self presentMoviePlayerViewControllerAnimated:_moviePlayer];

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?

Playing subsequent movies in one MPMoviePlayerViewController

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;

Cannot get MPMoviePlayerController to return to my TableView

I have a table view that has a list videos. When I click on one it uses MPMoviePlayerController to play the corresponding video. I cannot figure out how to have the player return to the list-view when the video finishes or I click on the done button.
I read the documentation and they said there was a
MPMoviePlayerPlaybackDidFinishNotification.
I figure I could have code that would go off when the notification was sent to go back to my list-view, but:
I do not understand notifications. Are they like using a delegate for a call back?
After I detected the notification, how would I tell the player to go away?
If you use the MPMoviePlayerViewController then the approach is something like:
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentUrl:url];
[myViewController presentMoviePlayerViewControllerAnimated:player];
You don't need to worry about the notification then. Once the user clicks done the movie player will go away.

iPhone SDK - presentMoviePlayerViewControllerAnimated no video but audio

I'm trying to show a MPMoviePlayerViewController.
MPMoviePlayerViewController* theMoviePlayer = [[MPMoviePlayerViewController alloc]
initWithContentURL:[NSURL URLWithString:media_url]];
If I'm adding theMoviePlayer View to the current view via addSubview , everything is fine. But if I'm trying to show the player in a modal window, only the audio of the video is played back in the background. The view is not beeing displayed.
[self presentMoviePlayerViewControllerAnimated:theMoviePlayer];
I guessed you called presentMoviePlayerViewControllerAnimated in viewDidLoad and your view controller was not added to a navigation stack.
[self presentMoviePlayerViewControllerAnimated] will present MPMoviePlayerViewController as modal view and you can only present modal view controllers from controllers that have already been shown onscreen.
So to fix it you can either <1> push your view controller into a navigation stack and call [self presentMoviePlayerViewControllerAnimated] after viewDidLoad
<2> Without a navigation stack you need to call [self presentMoviePlayerViewControllerAnimated] in the next run loop after viewDidLoad, e.g. with a IBAction or using dispatch_after