view controller state after mpmovieplayercontroller full screen mode iOS - ios

i have taken a .Storyboard Project and for video playing i am using separate .XIB file.
When i add a view player xib on my storyboard content view, it played video well
But, when i enter to fullscreen mode and come back, content of the previous view is getting clear/nil.
Can anybody help!
Thanks

it seems like you are loosing strong references to you view controller contents . make them strong to keep the reference.
example-
property(nonatomic, strong) UIImageView *imageView;// for example only
by this you will not loose this object(imageView) until the controller is present in memory.

i don't know without your code. so what you have mistaken. here is my guessing answer for you
fullscreen
A Boolean that indicates whether the movie player is in full-screen mode.
#property (nonatomic, getter=isFullscreen) BOOL fullscreen
Discussion
The default value of this property is NO. Changing the value of this property causes the movie player to enter or exit full-screen mode immediately. If you want to animate the transition to full-screen mode, use the setFullscreen:animated: method instead.
Whenever the movie player enters or exits full-screen mode, it posts appropriate notifications to reflect the change. For example, upon entering full-screen mode, it posts MPMoviePlayerWillEnterFullscreenNotification and MPMoviePlayerDidEnterFullscreenNotification notifications. Upon exiting from full-screen mode, it posts MPMoviePlayerWillExitFullscreenNotification and MPMoviePlayerDidExitFullscreenNotification notifications.
The value of this property may also change as a result of the user interacting with the movie player controls.
reference by apple doc

Related

How do I disassociate an instance of AVAudioPlayer from a View in SwiftUI

(Preface with I am very new to programming and Swift)
I am making an alarm app and so I have an AudioPlayer class based mostly on the one outlined in this instructional but with some modifications for looping that I needed:
https://blckbirds.com/post/voice-recorder-app-in-swiftui-1/
I have a timer and an .onRecieve associated with a view that creates my onscreen clock. Timer goes off, sound plays through an #ObservedObject created from my class, tap a button and it triggers the .stop() function. That all works for the most part as long as I stay on the main view.
The issue I am running into is that under certain circumstances it appears that view changes crash the app. Specifically:
"Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value"
On the line in my class related to .stop(). I interpret this to be that there is no audioplayer found to stop and my guess is that it's because it was created in a different view that is no longer present?
A typical situation is I have a landscape view that is a large version of just the clock whereas the portrait view has controls. If in landscape when the alarm goes off and the sound triggers, switching to portrait either crashes right away or when I tap the button to stop.
My thinking was to move the audio instance outside of the views or into a background process of some sort that is independent of the view status, but I can't figure out how to do that or even if my analysis of the issue is correct.
Another approach I attempted to take was to force the screen back to the original portrait view before triggering the audio so that I was only dealing with the audio in the one view (a user interface behavior that wasn't ideal but acceptable to me). This appears to now not play the sound at all, and then still crash when stop is tapped.
Could anyone help me understand what is going on with my audioplayer object and how I might approach this problem? Thanks,
Dan

UIWindow + lockscreen issue

straight to the point: Our app has UITableView with UITableViewCell that has AVPlayerViewController inside (its view) + custom video controls. One of the controls is fullscreen mode. Note that everything works perfectly - loading video, reusing, even the fullscreen.
Fullscreen functionality is based on creating new UIWindow, setting its rootViewController to the videoplayer and making it keyAndVisible - basically showing fullscreen AVPlayerViewController from cell subview on tap
The issue comes when user locks his device - after unlocking, the fullscreen window "disappears" and app is frozen / stuck on previous screen (the list with video cell, text cells.. - the one that made the new UIWindow)
The UIWindow (video window) is there, but without content (no subviews, VCs..) on top of the main (app, tableview list..) UIWindow - refer to pictures.
This issue is not happening on Simulator - only real devices.
View hierarchy debug before locking the device and showing the video on fullscreen (with new UIWindow):
View hierarchy debug after unlocking the device and app freezing on previous UIWindow:
Is there any possible fix? Or a better way of presenting AVPlayerViewController from UITableViewCell (while playing and without stopping the video)?
Note: the bug happens even if we remove landscape / portrait orientation changing, the issue seems to be related to UIWindow
PS: sorry for hiding the names in the pictures - NDA...

Delegate fullscreen event AVPlayer objective-c

After several sleepless nights, I don't have any more ideas how to do what I am trying to do.
In short words, I am trying to allow my fullscreen video to be accessible in all orientations (landscape and portrait). This is the only place in the app where I want to allow that. All other views are locked to portrait.
My idea was to delegate fullscreen enter / exit event and in that place, programmatically set orientation allowance, so on fullscreen enter, unlock landscape additionally and on fullscreen exit, lock back only to portrait. Everything works fine apart from the one crucial part...I can not delegate fullscreen enter/exit event (delegating those events was my idea but I might be completely wrong and that should be managed in completely different way)
I am using this library: https://github.com/brentvatne/react-native-video
Thanks in advance for any help!

How do I make sure when I change to different views each is set as the First Responder?

I have an app that uses a tab bar controller with 5 different tabs using one viewcontroller (UIViewController). On the primary viewcontroller there is an audio function to play audio and when I switch to other views, I am no longer able to use the headset buttons to make adjustments to audio playback (play/stop). I am told that I need to make each view act as a First Responder so it can receive the notification to adjust audio playback. How do I do this?
I am only using one UIViewController for the entire app, should I setup different view controllers for each tab of the application instead?
I'm using xCode 4.6.4
iOS SDK 6.1
Thanks.

MPMoviePlayerController done button, Landscape orientation

I'm using simple MPMoviePlayerController. In portrait mode it is emmbedded into my layout. When I rotate my device I want it to go full screen. In full screen mode there is a done button but only thing it does is pausing the video. I want to dismiss modal view controller when the done button is tapped. How can I do this?
I've tried:
Putting a [UIColor clearColor] on a background of a button and place a button over Done button thus intercept touch event into my own selector. It failed because my custom button isn't displayed when MPMoviePlayerController is in fullscreen mode.
Going to notification center and trying to catch "willExitFullscreen" but it won't occur (pressing done button when in landscape fullscreen mode isn't goint out from the fullscreen mode).
Finding done button in the MPMoviePlayerController... but I was unable to find it.
Using MPMoviePlayerViewController isn't an option as I want to be able to use embedded player in my controller when i Portrait mode, and be able to rotate movie without loading it from scratch (so pushing new controller when user changes device orientation isn't right solution for me).
I've read a few topics on this issue and question can be the same or similar but anserws require either things I've checked (i.e. notifications) or things I can't use (MPMoviePlayerViewController).
ANSWER (as I am unable to post it in 7h)
Heh ok..
The culprit of this whole mess was this line of code
[self.mpPlayer setControlStyle:MPMovieControlStyleFullscreen];
So it seems that setting Fullscreen control style when going into fullscreen mode will break done button....
Makes no sense to me. But when I commented out this line I am able to recive willExitFullscreen notification and I can work with that.
The culprit of this whole mess was this line of code
[self.mpPlayer setControlStyle:MPMovieControlStyleFullscreen];
So it seems that setting Fullscreen control style when going into fullscreen mode will break done button....
Makes no sense to me. But when I commented out this line I am able to recive willExitFullscreen notification and I can work with that.

Resources