I am using following code to display Vimeo player in UIWebView:
_webView.delegate = self;
_webView.allowsInlineMediaPlayback = YES;
[_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://player.vimeo.com/video/12536488"]]];
Now when I'm clicking play button, native iPhone movie player appears.
How to enable inline playback?
What I already was trying to do is to get acces to video element after page is loaded to set webkit-playsinline attribute. I wrote:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[_webView stringByEvaluatingJavaScriptFromString:#"var video = document.getElementsByTagName('video')[0];"];
}
But video variable appears to be undefined.
Any ideas would be appreciated.
After all we decided to use paid account. Vimeo provides direct links for videos stored on "Pro" accounts.
Related
WKWebView *wb = [WKWebView new];
[wb loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://file8a445fb7811e.iamh5.cn/v3/idea/u5UfsotV?suid=ohAJ7wa8J4S-rj0SFOVmrDhOBotM&from=singlemessage"]]];
This urlStr is a flash URL. It stops after load 99%. How do I fix it?
I tried to use UIWebview, it worked perfectly, but WKWebView not.
I use AVPlayer by default, not custom control.
AVPlayer *player = [AVPlayer playerWithURL:[NSURL URLWithString:#"https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"]];
AVPlayerViewController *avPlayerVC = [[AVPlayerViewController alloc] init];
avPlayerVC.player = player;
avPlayerVC.view.translatesAutoresizingMaskIntoConstraints = NO;
[self addChildViewController:avPlayerVC];
[self.view addSubview:avPlayerVC.view];
[player play];
... (auto layout here)
AVPlayer works normally but I can't handle any event from it.
When a user clicks on the previous or next button, I want to be able to detect or receive events to update other URLs. When I try it myself, it does not work.
I tried to use AVQueuePlayer with 3 URLs, but the video only changes the URL when it finishes the current item, the 2 buttons next/previous doesn't work.
I want to receive event on control avplayer, How do I do this? Thank so much! Sorry for my bad English.
If I have a UIWebView with mediaPlaybackRequiresUserAction = YES, then later in my app create a new UIWebView and set mediaPlaybackRequiresUserAction = NO on it, it also changes the value of that property on the first instance.
e.g. I have a UIWebView and then present a second UIWebView modally (for an ad), changing mediaPlaybackRequiresUserAction on the modal webView affects the presenting UIWebView.
Any ideas why this is? Are UIWebViews all backed by a single instance?
Link to sample project here.
not sure your app purpose, just try this way:
- (IBAction)unwind:(UIStoryboardSegue *)unwindSegue
{
[self TS_updateLabel];
[[self webView] setMediaPlaybackRequiresUserAction:YES];
[self TS_reloadWebView];
}
....
in method TS_reloadWebView
if (self.webView.isLoading) {
[self.webView stopLoading];
}
[self.webView loadHTMLString:htmlString baseURL:baseURL];
I guess it also is UIWebView bug .... but now this way maybe can solve your problem.
Is there a way to play video without it launching fullscreen? Trigger.IO API does not have an option to set it up apparently, and adding 'webkit-playsinline' inside HTML5 video tag is not enough on iPhone as well, as it needs property 'allowsInlineMediaPlayback' of 'UIWebView' to be set as 'YES'.
I would expect Trigger.IO to have some kind of option to trigger this property on or off...
P.S. It looks like Phone Gap supports it already...
You could easily write your own native module to change WebView properties in a Trigger.io app. The function would probably look a lot like this:
+ (void)enableInlineMediaPlayback:(ForgeTask*)task {
if (NSClassFromString(#"WKWebView") && [[ForgeApp sharedApp] useWKWebView]) {
// Handle new WebView
WKWebView *webView = (WKWebView*)[[ForgeApp sharedApp] webView];
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
configuration.allowsInlineMediaPlayback = YES;
webView.configuration = configuration;
} else {
// Handle old WebView
UIWebView *webView = (UIWebView*)[[ForgeApp sharedApp] webView];
webView.allowsInlineMediaPlayback = YES;
}
[task success:nil];
}
Additionally, you need to add the webkit-playsinline attribute to the video HTML tag.
EDIT: I've adjusted the code to include relevant code for iOS8 and WKWebView.
I have loaded an HTML file from server and displayed that in UIWebview, where it contains an OnClick Function in that file, when the user OnClicks, i will get one Video URL. I want to open that video url in iOS videoplayer. how can i do this? Please help me.
If you have a javascript function which returns the URL when the "Get Video URL" button is clicked like this:
function getVideoURL() {
// do processing to fetch the actual video URL here
window.location = "http://www.domain.com/videos/1";
}
and button handler is set as something like this:
<a target="_blank" href="javascript:getVideoURL();" class="btn-image GetVideo"> </a>
then you will have to provide implementation for UIWebView's following delegate method in your view controller class:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
After this you can use the relative path from the java script request
request.mainDocumentURL.relativePath
inside the delegate to refer to the URL returned from the Java script method. You can use the fetched URL to open iOS video player and play the video as follows:
MPMoviePlayerController* moviePlayer=[[MPMoviePlayerController alloc]initWithContentURL:[NSURL URLWithString: strurl]];
moviePlayer.fullscreen = YES;
[moviePlayer play];
You can use stringByEvaluatingJavaScriptFromString.
But we need to know what onClick function does exactly?
Does it return video URL directly?
Or it modifies HMTL to display that video URL?
If it returns videoURL directly:
NSString *videoURL = [webView stringByEvaluatingJavaScriptFromString:#"document.getElementById("yourElementID").click();"];
If it doesn't, you need to parse the HTML for videoURL after calling onClick function.