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

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.

Related

How to disable autoplay for YouTube video in WKWebView?

I have simple ViewController with WKWebView configured as follows:
webView.configuration.allowsInlineMediaPlayback = true
webView.configuration.mediaTypesRequiringUserActionForPlayback = .video
But right after loading a web page with YouTube video it starts to play automatically (and switching to full screen at the same time) without any user interaction which is required. How to disable autoplay?
I also had same problem,YouTube vide was playing in full screen
webview.configuration.allowsInlineMediaPlayback = true
programmatically setting allowsInlineMediaPlayback value didn't work for me
You can avoid video switching fullscreen by enable inline playback for WKWebview.
Check the webView storyboard property Interaction for Audio Playback. Yes, I know, this is a question about video, but setting the Video Playback checkbox doesn't work, at least not on a target iOS 13 simulator!
Probably just check everything in that section - inline playback, interaction for Audio, interaction for Video. That's what I'm doing, although my test shows only Audio is necessary. I suspect this is a WKWebView bug and Apple will fix it so that Video properly works instead of Audio :-)

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?

How to allow iPhone auto-lock while playing a video

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.

iPhone : How to get the access to the default quicktime player that is launched?

I am loading a YouTube video link in UIWebView and when I click the play button, it launches the Quicktime player and plays the video in it. The issue here is that the default orientation of the Quicktime player is Portrait--I want it to be in Landscape mode.
Even though my base view and the webview are both in landscape mode, Quicktime player still gets launched in portrait mode.
I thought I could get the access to the default quicktime player and change its orientation to landscape.
May be this is not the case, but what about intercepting the click on the link and play the video using mpmovieplayercontroller?
That's only a suggestion and probably not a real answer to your problem.
Good luck!

Playing video in a Customview like iPad feature

When we call MPMoviePlayerController.play method, the movie player is opened and the video is played in a separate full screen. is it possible to play a video in a custom view, that is I have an image added on a view, when this image is clicked, the image has to be removed and the video has to play there itself as the feature in iPad.
Non-full screen playback of video is possible in iPhone OS 3.2 for iPad.
If you are porting an application that uses the MPMoviePlayerController class of the Media Player framework, you must change your code if you want it to run in iPhone OS 3.2. The old version of this class supports only full-screen playback using a simplified interface. The new version supports both full- and partial-screen playback and offers you more control over various aspects of the playback.
On the full-screen question, see this section of the iPad Programming Guide for further information, and this property of MPMoviePlayerController specifically.
Bear in mind that you can still only play one video at a time, and that this is only currently possible for iPad.
Not using MPMoviePlayerController, no.
You might be able to achieve this using a custom movie player, but I haven't seen one in the wild yet, and I don't know how it would be done.