I have created my own MoviePlayerViewController derived from MPMoviePlayerViewController, I present it using the standard presentMoviePlayerViewController method - all works fine. On top of the movie player controller, I present another ShareThisMovie view controller when the user clicks some button (after I pause the movie). I do this using presentViewController.
I don't know why but as soon as the new VC comes up, the underlying MoviePlayerViewController immediately fires MPMoviePlayerPlaybackDidFinishNotification, which I respond to by dismissing the entire VC hierarchy, so the user does not have a chance to interact with the ShareThisMovie controller.
Even if I ignore the notification, still the fact that the movie player fires it means that once the ShareThisMovie controller closes, the movie STARTS OVER FROM THE BEGINNING. This is clearly not what I want...
Why is the MoviePlayerController firing this event? How do I ensure it doesn't, or how to I workaround this? I tried storing the last playback location before showing the ShareThisVideo controller, and setting it back afterwards, but it still plays from the beginning...
tnx
This is happening because when you moving from MoviePlayerViewController to another view controller the MPMoviePlayer stops it playing...so your MPMoviePlayerPlaybackDidFinishNotification Delegate is calling.
you can not continue playing MPMoviePlayer when you are on another ViewController.
one solution is insted of presenting ShareThisMovieviewcontroller, you can simply add UIView for sharing on top of MPMoviePlayer in same controller. this will prevents the MPMoviePlayer to stop.
Not exactly an answer rather than a workaround, but I ended up changing the design: instead of deriving from MPMoviePlayerViewController, I derived from the standard UIViewController, and embedded an MPMoviePlayerController inside it. For some reason, when doing this, the player did not raise a didFinish event when I presented some other VC on top of my player view controller...
Guess my conclusion for now is not to derive a VC from MPMoviePlayerViewController...
Related
I am working on ARKit where I save a video during an ARSession. I present another view controller where I can watch my video. When I come back to my first view controller, the camera seems to be frozen although session delegates are called. I cannot add nodes either.
I have a button that allows the user to toggle whether the app plays music or not. When the button is toggled, the code modifies the value of a key in NSUserDefaults.standardUserDefaults() to indicate the new state of the switch.
The obvious solution would to to check the value of the key when the view appears (in viewDidAppear, for instance), and play music if the key indicates to do so. However, the music setting is toggled from within a popover view, so the music needs to be able to be turned on or off after the underling view (the view the popover view appears over) has already appeared.
In other words, I need music in a view that has already appeared to turn on or off whenever the associated value in NSUserDefaults.standardUserDefaults() changes.
You could use Key-Value Observing to do something whenever the key in the user defaults changes. However, KVO is a sometimes little bit messy to implement and some people dislike it.
An alternative might be to make a delegate protocol and make the view controller presenting the popover the delegate of the whatever controller responds to toggling the switch in the popover view. This way, you can notify view controller presenting the popover whenever the user toggles the switch in the popover.
I have 2 viewControllers. One of them is for the game screen and it has lots of different variables like labels,buttons,images. The other one is for the pause menu. When i pause the game and tap the resume button, it calls the viewDidLoad of the first viewController naturally.
I want to save the last state of the game when user tap the pause button. Or i want to see the last state of the game when user tap the resume button. I don't want to use nsuserdefault for this,if there is a different solution. Hope i can explain my problem.
Best Regards,
Taha
When i pause the game and tap the resume button, it calls the viewDidLoad of the first viewController naturally
Then you're doing this wrong. There is no reason why the first view controller (with the game screen) should be torn down merely because you are showing the pause menu view controller. You need to rethink your architecture here.
For example, if the first view controller presents the second view controller, then the second view controller's view appears, but the first view controller is not torn down. When the second view controller vanishes again (resume), the first view controller's viewWillAppear: and viewDidAppear: will be called, but not viewDidLoad. Your job is to organize your tasks so that the game pauses on viewWillDisappear: and resumes on viewDidAppear: but the data displayed is not torn down or reset.
I am approaching mental trying to solve this issue:
The situation:
I have a pretty basic application, an an MMDrawerController with a tableview inside, which links to a uitabbarcontroller when an item is pressed. Inside the first page of that is an embedded youtube UIWebView which when pressed played a youtube video fullscreen.
Here is what is happening.
Press video, opens in fullscreen and starts playing
UITabBar viewWillDisappear fires
Root MMDrawerController viewWillAppear fires
Video Ends
User back to UITabBar they started and everything seems fine even though it 'disappeared' earlier
Now I put booleans in the ViewWillAppears / Disappears of the two views to check what the current state of the app is like. Usually it's 0,1 indicating either the table is open or the uitabbarcontroller is open. After the video, they show 0,0. If I press back on the navigation I get "Unbalanced calls to begin/end appearance transitions" when navigating from wherever I am.
Right now If I listen for the start of the youtube video and then fire:
[self.navigationController popToRootViewControllerAnimated:NO];
I can prevent the unbalanced calls, from occurring and the user can continue to navigate the app. However they don't get to watch the video and they just get thrown back a view.
As well in 3. I can check for 0, 0 on the two controllers and then pretty much reboot the whole app. But thats not a good solution.
Intended outcome:
The user can press the uiwebview, watch the video, and afterwards they are returned to where they left off. If they hit back on the navigation controller, no unbalanced appearance transitions.
I've tried a bunch of stuff, like
[self.navigationController poptoViewController:...]
From what I gather at this point, it has something to do with fullscreen videos loading in the root controller (hence its viewWillAppear firing at 3.) but I'm not getting 'placed' back correctly afterwards. Something like
[self.navigationController heyTheUserIsPresentlyIn:self]
That I can call after the video goes away would be crazy good.
Any assistance is much appreciated, although I've been on this for hours and hours, If I'm a moron any links to docs or sections in books would help a lot. Thanks.
It sounds like ViewController life-cycle issue.
Are you sure you want to navigate from a UITableView to a UITabBarController? Try remove the latter because it's normally the root ViewController and calls to viewWillDisappear and viewWillAppear could be made based on this assumption.
If you need a tabbed like control which is not the root ViewController maybe consider rolling your own?
Well this happens when a sequence of navigation animation or animation started without properly ending first animation, so i can guess the same is with your animation, take care of your animation even if it is not due to Navigation controller.
Hope it helps you
I'm creating an app that plays music and has a nice UI for the album art and progress bar. The problem is when the user leaves the player view and goes back, the player UI has to be reloaded and you see a flash while the progress bar is resized and the album art is loaded.
Is there any way to keep items in memory when you leave a controller? Similar to how you go between playlists and player view on the iPhone music app, there is no lag or delay in seeing the artwork or song progress, it's there from the beginning.
Or am I thinking about this the wrong way?
I am assuming you are going back and forth using a UINavigationController, if so the default behavior is that the view controller will be released when you go back, as the only strong reference to it is in the UINavigationController stack, when it is popped the reference is lost, and therefore your controller is deallocated.
If you want to avoid this, all you need to do is have any other object have a strong reference to your view controller. An easy way to do it would be whenever you initialize your controller, in that class have a strong property that holds a reference to the view controller you do not want to lose.
Hope that helps.