The Best way To Add iframeVideo in Android? - android

I am new to android platform, and I want create simple
thats play videos from web via iframe
but the result is horrible ... very very bad
even the user can't watch in full screen
and the size of video is very big,, bigger then webView?
so, if any one know a good way to play video.. with iframe in android, please tell me..
i have tested the code on iOS it's works prefect... so the problem is android...
here's my Code
String hrmlCode = "<center>" +
"<iframe type=\"text/html\" frameborder=\"0\" scrolling=\"yes\" width=\"367\" height=\"320\" src=\"http://video.com/WqPOh.php?get=vid394g5\" allowFullScreen></iframe>" +
"</center>";
CWebView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
// Activities and WebViews measure progress with different scales.
// The progress meter will automatically disappear when we reach 100%
act.setProgress(progress * 1000);
}
});
CWebView.getSettings().setJavaScriptEnabled(true);
CWebView.getSettings().setPluginState(PluginState.ON);
CWebView.loadData(hrmlCode, "text/html", "UTF-8");
thanks in advance

This is a very famous issue in android. The iframe just doesnt work as expected and it is very buggy.
I would say you don't include but simply provide a thumbnail of the video which directly links to your video file
Look into the earlier solution below
https://github.com/droid28/VimeoVideo
Google Reader-esque optimizing of WebViews on Android

Related

Vimeo video stops playing on Android 6 devices

I'm trying to play video's from Vimeo in my app. The problem is that on Android 6 devices the video stops playing after a certain time. On devices with a lower API everything plays fine.
The time depends on the quality. For the video of the provided url's below plays a certain minutes (1 to 3). How lower the video quality how longer it keeps playing.
After 1 to 3 minutes the mediaplayer throws an ProtocolException. The app does not crash on this but the video freezes when the buffered video piece is played. [MediaHTTPConnection] readAt 25182208 / 32768 => java.net.ProtocolException: unexpected end of stream and shows this in de log
After the exception the video plays 30 seconds (buffered), then the application outputs this [MediaPlayer] error (1, -1004)
We're emailing for weeks now with Vimeo Support but they can't provide a solution or a possible cause. Now after weeks of mailing the support desk says that they're not supporting Android, but we've tried their suggestions:
Use the redirected and unredirected url's
http://player.vimeo.com/external/185069251.hd.mp4?s=fd7b4178a59166b3f636f2e48f1d49b99db66ed2&profile_id=174 [Redirected URL]
https://fpdl.vimeocdn.com/vimeo-prod-skyfire-std-us/01/2013/7/185069251/610514667.mp4?token=586a9287_0xbb25f73405c612b30e0c64dc4c3a169e30137f84 [Not redirected URL]
Use a video view instead of a mediaplayer
We've tried a native Android and a Xamarin Android implementation
Try to download the file => this works but we want to stream because some video's are longer then 30 minutes (>100mb). Uncomment the code in the onCreate in the DownLoadActivity to test downloading.
In the browser everything works fine.
I've placed a testproject on We-Transfer where you can see the problem https://bazookas.wetransfer.com/downloads/40dadcc8a01f7ebf025345cdf88b731220170102160508/21970a
HI in my app I'm also using Vimeo but in another way.
And it' working fine without issue in any OS. (For Native Android)
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.i("", "Processing webview url click...");
view.loadUrl(url);
return true;
}
public void onPageFinished(WebView view, String url) {
Log.i("", "Finished loading URL: " + url);
Const.disMisProgressdialog();
}
#Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
}
});
if(windowwidth < 480) {
webView.loadUrl("https://player.vimeo.com/video/<YOUR VEMIO ID>?player_id=player&autoplay=1&title=0&byline=0&portrait=0&api=1&maxheight=320&maxwidth=480");
}else{
webView.loadUrl("https://player.vimeo.com/video/<YOUR VEMIO ID>?player_id=player&autoplay=1&title=0&byline=0&portrait=0&api=1&maxheight=480&maxwidth=800");
}
for
windowwidth :-
int windowwidth = getWindowManager().getDefaultDisplay().getWidth();
int windowheight = getWindowManager().getDefaultDisplay().getHeight();
Looks like the issue with the url you use.
You use url from vimeo api for HD file. And for some reason android system don't allow to cache more then some amount of KB.
If you change the url from HD to vimeoHLS - link for streaming, everything works fine.
It fixed the issue for my 7 android, but i haven't tested this for another version yet tho.
Can't find a reason why this doesn't work on Android 6+, but works fine for lower versions.

Change font WebView for an already loaded site with Android

I have been searching for days but could not find solution for my problem. Please kindly take a look:
Input: a WebView with an already loaded web.
Output: change the font of that loaded web inside the WebView.
What I have done so far is this:
#SuppressLint("SetJavaScriptEnabled")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient());
mWebView.loadUrl("http://www.bbc.co.uk/");
and then, this is how I change the font inside webview:
1/ way 1:
mWebView.loadUrl("javascript:(function() { var s=document.createElement('style');s.innerHTML ="
+ " '#font-face{font-family:ZawGyi-One;src:url(\"http://db.tt/OQ1RZoWc\");}"
+ "body,div,h1,h2,h3,input,textarea{font-family:ZawGyi-One! important;}';"
+ "document.getElementsByTagName('head')[0].appendChild(s);document.getElementsByTagName('body')[0].style.fontFamily = \"ZawGyi-One\"})()");
2/ way 2:
mWebView.loadDataWithBaseURL(
null,
"<script>javascript:(function() { var s=document.createElement('style');s.innerHTML ="
+ " '#font-face{font-family:ZawGyi-One;src:url(\"http://db.tt/OQ1RZoWc\");}"
+ "body,div,h1,h2,h3,input,textarea{font-family:ZawGyi-One! important;}';"
+ "document.getElementsByTagName('head')[0].appendChild(s);document.getElementsByTagName('body')[0].style.fontFamily = \"ZawGyi-One\"})() </script>",
"text/html", "UTF-8", null);
3/ way 3:
mWebView.setWebViewClient(new WebViewClient() {
#Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
mWebView.loadUrl("javascript:(function() { var s=document.createElement('style');s.innerHTML ="
+ " '#font-face{font-family:ZawGyi-One;src:url('file:///android_asset/fonts/BLKCHCRY.TTF');}"
+ "body,div,h1,h2,h3,input,textarea{font-family:ZawGyi-One! important;}';"
+ "document.getElementsByTagName('head')[0].appendChild(s);document.getElementsByTagName('body')[0].style.fontFamily = \"ZawGyi-One\"})()");
}
});
But unfortunately, none of my solutions works. Even though I have tried to change html file insdie /assets/ folder and also the fonts are stored at /assets/fonts/ folder, I cannot walk through this.
**One more question: is it really possible to change font style inside an already loaded site of webview ? Someone, please kindly guide me.
I am appreciated your great help.
look into this answer..How to change font face of Webview in Android?..
Or try this demo project..https://github.com/mayooresan/Japs-Attack-Ceylon--Android-App
Hope it will helps you.
At last, I have figured it out:
1/ Without making change in the content of webpage you cant change the font.
WebView is basically a view to display web pages That web pages may be static(eg html) or dynamic. But it doesn't change the look and feel of web page. so It wil display the text exactly same as that of webpage. If you need to change the font then you have to change it in webpage (may be in html).
(from Webview change font ? _android)
2/ one more solution for this is about changing font from the rendering engine of webview, for Chrome app, it should be now is Blink, or Internet app, it would be Webkit.
So, if anyone is facing the same problem as I was, my little piece of advice is find the way around, you normally do not have enough time or authorize to make the change at rendering engine of webview. :)
Have a nice day.

Android WebView window.onload event issue

I am working on one Android App where I am loading local file contents into webview using following syntax.
url = "file://" + mLocalFilePath + java.io.File.separator + CURRENT_FILE;
webView.loadUrl(url);
The issue is the webview loads file contents and also loads the various images from url present in webpage ( webpage has many images ).
The challenge I am facing is I want to get notified when webview finish rendering entire html page.I want to get notified when webpage is 100% loaded.
I reffered various forums and also tried using
window.onload function
as well as
public void onPageFinished(WebView view, String url)
But I did not get desire output,I get callback before html page is completely loaded.I am looking for way so that I will get notified only when webpage has finished rendering all the images present in web page.( i.e Webpage is 100% loaded.)
I am not looking for complete answer even hints will be appreciated.
Thanks
Try this way
webView.setWebChromeClient(new WebChromeClient(){
#Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
if(newProgress==100){
// page loading completes
}
}
});
I used deprecated PictureListener that start when all images on the pages are loaded. It deprecated and you need at least one image in the html but if you can manage this (you could place transparent 1px*1px image) it's a good solution.
wv.setPictureListener(new PictureListener() {
#Override
public void onNewPicture(WebView view, Picture picture) {
// some code here
}
}
});

Images not displaying in Android WebView

I have a situation where I am trying to display user-generated HTML in a webview using loadData. My code is something like this:
String content = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
"<html><head>" +
"<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />" +
"</head><body>";
content += htmlStr + "</body></html>";
wv.loadData(content, "text/html", "UTF-8");
It works pretty well in most cases, but I am having trouble getting certain types of images to display. In most of my testing, inserting <img src="..."/> tags worked fine, but I found that links to images on Photobucket would not display at all; I get a little box with question mark in it instead of the image.
Clicking on a link to an image on Photobucket tends to take you to the page on which that image is viewable on their website, rather than just the raw image itself. I have a feeling that the issue is related to this. I suspect that it may be a "Referer" issue, or perhaps user-agent, or something of that nature, but I cannot for the life of me get this to display properly.
I have tried switching to loadDataWithBaseURL and providing a BaseURL (as I believe this will be used as the referer url) but that made no difference. I have also tried using loadUrl("http://photobucket..." instead and providing a HashMap with the Referer header manually set, but that did not work either. Actually, switching to loadUrl made it immediately redirect to the device's browser to load the Photobucket page. I attempted to provide a custom WebViewClient and override shouldOverrideUrlLoading, but the best I got it to do was to display the full Photobucket page inside the WebView.
I am sure this is not a specific issue with Photobucket, that just happens to be the site that I discovered this problem with while I was testing.
I would really like to figure some way to deal with this situation so that this can work correctly, but I have been as yet unable to find any helpful direction on SO or the internet at large. Does anyone have any ideas?
I would wait until Photobucket finishes their recent updates before further testing...while you stated you are sure it is not a specific issue with Photobucket the internet is now awash with posters not able to view Photobucket linked to images with android based devices. If your code works with all other images not hosted on photobucket your code is good.

Android: playing a youtube video INSIDE of my application

I'm hoping someone can set the record straight for me. I know there are several posts about this issue, but I'm still unclear about this.
I want my application to show an image of a page out of a book, and inside that image I want to play a youtube video. Apparently, I"m supposed to use a WebView for this.
WebView mWebView = new WebView(this);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.setWebViewClient(new HelloWebViewClient());
setContentView(mWebView);
String Play = "<iframe width=\"600\" height=\"400\" src=\"http://www.youtube.com /embed/VCDOjdYhj1Y\" frameborder=\"10\"</iframe>";
mWebView.loadData(Play, "text/html", "utf-8");
}
private class HelloWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
When I do this, the video looks okay but the sound is lagging. It's very noticeable if someone is talking because the words don't match their lips. From what I understand, WebView really isn't meant for showing video even though it's supported. It's simply a way of showing a web page inside of the app with preferably no user interaction. If you want video and web pages, you're supposed to launch the browser with an Intent. I don't want to do this. I can't use a VideoView because I'm not pointing directly to a video file.
So is that it? Am I out of options? You'd think Youtube and Android would be very compatible since their both Google. Embedding a youtube video in an HTML View works really well in iPhone apps. I hope someone can give me the final word on this. Thanks!
Can't it is something with how the url is loaded like parents, etc.

Categories

Resources