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.
Related
In iOS15, there is a new API to SFSafariViewController.Configuration that suggest one can add a custom button on the SafariViewController UI. This blogpost explains this in greater detail, under "Running custom extension".
I've been trying to implement this in a sample app without success. See the code snippet below:
- (void)openSfariViewController {
SFSafariViewControllerConfiguration *config = [[SFSafariViewControllerConfiguration alloc] init];
// Also tried the following extensionIdentifiers without success
// com.atomicbird.DemoNotes
// com.apple.share-services
SFSafariViewControllerActivityButton *button = [[SFSafariViewControllerActivityButton alloc] initWithTemplateImage:[UIImage systemImageNamed:#"heart.fill"] extensionIdentifier:#"com.atomicbird.DemoNotes.DemoNotes"];
config.activityButton = button;
SFSafariViewController *safariVC = [[SFSafariViewController alloc]initWithURL:[NSURL URLWithString:#"http://developer.apple.com"] configuration:config];
// safariVC.delegate = self;
[self presentViewController:safariVC animated:NO completion:nil];}
However I try to configure the new activityButton, it doesn't seem to have an effect on how SFSafariViewController appears when it is presented. It looks exactly like it does if I don't configure the activityButton. Here are some things I think I might got wrong:
I don't know what is the extensionIdentifier, perhaps I used a wrong value?
Perhaps I got the whole thing wrong, and an ActivityButton is not what I think it is?
Maybe the Share extension is not the configured properly?
I haven't been able to find any information on the web on how an activityButton is even supposed to look like. Thanks for reading this far, let me know if you have any pointers for me.
I have implemented MobileVLCKit in iOS by using MobileVLCKit framework. I have an issue,
When I declare the player #Interface the streaming and voice is working well.
#import <MobileVLCKit/MobileVLCKit.h>
#interface ViewController ()<VLCMediaPlayerDelegate>{
VLCMediaPlayer *vlcPlayer1
}
#end
But, declare the VLCMediaPlayer object at local function the video preview not displayed but, audio id playing.
- (void)viewDidLoad {
[super viewDidLoad];
VLCMediaPlayer *vlcPlayer1 = [[VLCMediaPlayer alloc] initWithOptions:nil];
vlcPlayer1.drawable = view;
media = [VLCMedia mediaWithURL:[NSURL URLWithString: UrlString]];
[vlcPlayer1 setMedia:media];
[vlcPlayer1 play];
}
How can I resolve the issue. Because, I need to create the view dynamically.
Try this:
[vlcplayer.media addOptions:#{ #"network-caching" : #300}];
If it doesn't work, replace 300 with a bigger value.
That may work.
So both of these questions/answers put me on the right path, but this is ultimately what worked for me.
NSURL* _uri = [NSURL URLWithString:uri];
NSArray* initOptions = [NSArray arrayWithObjects:#"--codec=avcodec", "--network-caching=10000", nil];
self.player = [[VLCMediaPlayer alloc] initWithOptions:initOptions];
self.player.media = [VLCMedia mediaWithURL:_uri];
It looks like the "addOptions" is valid, but my particular use case wasn't picking it up, and instead I had to actually initialize the VLCMediaPlayer with the options from the get go. Worked out nice because it actually fits much better with other JAVA/Android/CMD line VLC api's.
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.
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.
is it possible to load an external index.html (with included cordova.js) instead of the local one?
i found in the appdelegate.m this code:
self.viewController.wwwFolderName = #"www";
self.viewController.startPage = #"index.html";
i tried to reference an external url but without luck... anyone know a solution for this?
p.s.
with android it's easy:
super.loadUrl("http://192.168.1.135:3000/");
I have done this for my project (AppDelegate.m):
self.viewController = [[[MainViewController alloc] init] autorelease];
self.viewController.useSplashScreen = YES; // YES;
self.viewController.wwwFolderName = #""; // #"www";
self.viewController.startPage = #""; // #"index.html";
self.viewController.invokeString = invokeString;
self.viewController.view.frame = viewBounds;
// Load request with new root URL
NSURL *urlOverwrite = [NSURL URLWithString:#"http://kyryll.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:urlOverwrite];
[self.viewController.webView loadRequest:request];
As mentioned elsewhere, the site you are trying access has to be whitelisted.
It's working nicely. My external site is on local IIS and has the cordova.js as well as few plugins. Now just have to see if I get Apple to approve my app!
If you include the PhoneGap source as a subproject (I used 1.7 and the directions still worked, see my note at the end), you can add a few lines of code to allow PhoneGap to support external URLs as the startPage.
Around line 133, you'll want to add
if([self.startPage hasPrefix:#"http"]) {
appURL = [NSURL URLWithString:self.startPage];
}
else
right before if (startFilePath == nil) {
By default, PhoneGap doesn't seem to support external startPage URLs without a javascript 'hack' mentioned above. Other than this (and that), I know no other way!
Let me know if you have more questions.
Note: as I mentioned above, the walkthrough is missing one step. I commented on the article to let the author know, but it hasn't been approved yet. Below is my comment:
A step that was missing for me was adding $(CORDOVALIB)/Classes to the Header Search Path under Build Phases (also marking it to recursively search). Other than that, great write up!
For iOS it would be:
self.viewController.wwwFolderName = #""; // #"www"
self.viewController.startPage = #"http://192.168.2.107:9000/";
The names are confusing because the startPage is also the URL.
The simplest way I did is, include following script block in an index.html file and remove other code if not required:
<script type="text/javascript">
window.location.href="http://192.168.1.135:3000/";
</script>
And include the host in the ExternalHosts map in PhoneGap.plist file, also check OpenAllWhitelistURLsInWebView is set to YES in plist file
Setting the wwwFolderName to empty string did not work for me but nil worked.
self.viewController.wwwFolderName = nil;
self.viewController.startPage = #"http://192.168.2.107:9000/";
The simplest way I did is, xxxViewController: CDVViewController<...>
-(void) viewDidLoad{
self.wwwFolderName = #"dist";
self.startPage = #"test.html";
[super viewDidLoad];
}
so,that is all.