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 :-)
Related
I am using Ant Media Server for ultra-low latency WebRTC streaming. But video stream is freezing when I play it from the iPhone Safari browser. How can I solve this?
Yeah it's about safari autoplay scenario in WebRTC. In documentation, It says that
However, for a one-way video conferencing scenario, such as a webinar, the user does not give explicit permission to the camera. Without a user gesture to indicate playback, the video cannot start. Add a play button to your media controls for one-way WebRTC experiences, so the user can start the video.
Another place in documentation also says that
By default, autoplay executes only if the video doesn’t contain an audio track, or if the video element includes the muted attribute.
So solution is that, you either play content explicitly or you can mute the player and let the safari autoplay work for you. For some cases, it does not even auto play if it's muted so that you need some failover scenario again.
From our experience, if it freezes in the first frame with unmuted content, just click the play button on the screen as shown below works every time.
Browser will autoplay VIDEO element only if muted.
Solution is to add a Tap for Audio and start it muted or a Tap to Play button if important to start with sound. As in this HTML5 Videocall App.
use
setTimeOut(()=>{
video.play();
});
The Safari browser wants the user intervention to start/stop video stream. The above code snippet mimics that behaviour and starts the video stream in the video element.
If you are drawing the video element on canvas then you have to set the opacity=0.001 and width and height of the video element to 1px at least.
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?
When playing a movie through a UIWebView, and then outputting to AppleTV via Airplay, turning off iPhone screen stops playback. Why?
Anyone know how to solve this so AirPlay continues when the screen is off with my app?
Doing these two things solved it for me:
Airplay of audio using AVPlayer does not work in the background (Put the key "audio" as the key in the XML of the property list)
UIWebView: HTML5 audio pauses in iOS 6 when app enters background
Looks like it works for video too!
I'm building an App that plays a mp3 file (hosted on http://<somewhere>/<audio>.mp3) while the user is watching some changing labels (think about a lyrics app, which write the lyrics synchronised with the song).
In the bottom side of the screen I'd like to show the audio controls (play/pause, ff, rew), and a bar for indicating the downloaded part of the file and the playing point.
How is the easiest way to do it? I've already tried with AVAudioPlayer, AVplayer and MPMoviePlayerController, but none of them solved my problem.
You can use MPVolumeView Class.Read the documentation here http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPVolumeView_Class/Reference/Reference.html
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!