How to allow iPhone auto-lock while playing a video - iphone

How can I allow iOS device to dim screen and auto-lock the device while playing a video with AVFoundation. Playing a video with AVPlayer disable screen auto-lock by default. Is there anyway to re-enable it without pausing the video play.

why you want screen to go idle while playing video? The real answer is it can't be done. Following are just work arounds with serious downsides.
The only method apple allows us to use is
[UIApplication sharedApplication].idleTimerDisabled
You can dim screen programmatically by using a UIView with color black and slowly changing it alpha property to create the illusion of screen going idle.

I worked on the application where we used AVPlayer to display video backgrounds in application. Our solution was to stop video after some idle time. I mean implementing idle timer on our side. And then send message to all background players to stop them. It's the only good workaround I know.

Related

Hide Recording Indicator

Anyone knows how to hide Recording Indicator in ios14?
I’m writing a camera app, so is very clear that when the app is in use both camera and microphone are in use!
You can't. That's the whole purpose of the indicators: that the developer can't hide that their app is recording audio or video. Even the stock Camera app doesn't do that.

How to get AirPlay from UIWebView to continue playback when app is backgrounded *without* setting AVAudioSession category to Playback?

I've been attempting to make this work for quite a while now:
My app has the potential to play videos of Youtube from within UIWebView. The user could want to use AirPlay for this. When AirPlay is on, the device could go to sleep and normally video stops playing moments after that happens. As advised in other posts, I set the AVAudioSession category to the Playback one and it works - AirPlay continues even when the device display goes to sleep.
However, this has a side-effect; if the user has activated the app while music playback is on in the background, setting the app's audio session category to Playback causes the playing music to stop and this is definitely annoying.
Ideally, I want to set the AVAudioSession category when playback of Video starts, not when my App is activated - but I've not seen any central or UIWebview notification / delegate method to determine this.
I've got a hackish workaround for iPhone where the UIWebview hosted video player always loads full screen modal and thus can be determined. But my app is Universal and on iPad the video starts inline; I can't figure out a way to know when Video playback is going to happen. This is exactly the point when the audio category should be switched to Playback - it will actually help users who want background music playing only until video starts up.
I don't want to fool around with adding Javascript events on to Video tags inside the UIWebView - that seems too fragile to me.
Is it possible to observe any AVFoundation notifications that trigger for the UIWebView video playback? Or anyone know of any other way to determine if video playback will start / has started?

Background music closes on taking picture from camera UIImagePicker

When I take picture from camera using UIImagePicker, background music (from ipod app, pandora app) stops. It's not happening for facebook app. Is there a separate delegate for this? Please help
This might be due to your Audio Session policy. Taking a picture makes a "click" noise. Perhaps this is causing all other sound to be stopped because of your Audio Session.

MPMoviePlayerViewController and background audio

I am having trouble playing audio inside a MPMoviePlayerViewController in the background. I can point it to mp3's just fine and listen to the audio, but when I go into the background, I don't hear audio anymore.
I set the plist entry to keep playing audio and set the audio session toAVAudioSessionCategoryPlayback. When I hit the home button, wait a few seconds, and go back to the app, the audio advanced as if it had kept playing, I just can't hear a thing when the app is in the background.
Any idea what causes this?
Thanks!
I just tested in the simulator, and it fails there. It does work fine on the device though. Must be a bug in the simulator.

How to take control if we are playing a video /mp4 file in iphone /ipod?

What I have to do is play a video file in mp4 format. If the device is in portrait mode then it should display the video, but when the user changes the device to landscape mode it should just show an image.
But currently when I play a video, it takes control of the whole app; I can't send a notification to any event, and control only returns to my code after playing the full length video.
How can we can access another things while we are playing the video on the device?
Thanks for the help
Balraj Verma
Try spawning a new thread and then call the code to play the video from the new thread. This should leave the rest of your code free to do what it needs, unless I am misunderstanding your question.
You can use the shouldAutorotateToInterfaceOrientation: to check what orientation the device is in, and then do the logic in there.
Eg, if the orientation is portrait, start the MPMoviePlayerController playing the movie, then when the orientation changes to landscape, dismiss the moviePlayer.