Google/Android TV WebView vs FireTV WebView output - android

I am trying to play a video on WebView. The URL for the video is https://presenter.displaynow.io/video?url=https://dnmediaservice-usea.streaming.media.azure.net/eba08e4d-3f77-4343-8206-360541683fc5/21bf46b6-c6ec-925c-d5d2-7b6b61b2.ism/manifest
On Google and Android TV it is working as expected but on Amazon FireTV, the video is hiding behind some black container. On the Silk browser which was preinstalled on FireTV, the video is working as expected.
I tried to find the issue but I am not able to find any issue with my code. The HTML generated from the silk browser and my application WebView is also similar except for some minor changes.
Below is my code.
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webView = new WebView(this);
webView.setWebChromeClient(new WebChromeClient());
webView.setWebViewClient(new WebViewClient());
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.loadUrl("https://presenter.displaynow.io/video?url=https://dnmediaservice-usea.streaming.media.azure.net/eba08e4d-3f77-4343-8206-360541683fc5/21bf46b6-c6ec-925c-d5d2-7b6b61b2.ism/manifest");
this.setContentView(webView);
}
}
Google/Android/Silk WebView output
FireTV WebView output

Related

Load Content in Application using inbuilt chrome web browser than Default System Webview

I am currently implementing certain features in my application as it turned out that the default web view doesn't support such features.
SO, is there any possibility that i can render my application content in inbuilt chrome web view inside my application rather than android default web view or redirecting it open chrome browser.
I am currently on marshmallow. i came to know about this feature implemented in the NOUGAT version. However, i need it on API<23.
Below is my code:
webView = (WebView) findViewById(R.id.fullscreen_content);
// webView.setWebViewClient();
//you can also link to a website. Example:
//webView.loadUrl("www.google.com");
//I have included web permissions in the AndroidManifest.xml
//
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
//loads the WebView completely zoomed out
webView.getSettings().setLoadWithOverviewMode(true);
//true makes the Webview have a normal viewport such as a normal desktop browser
//when false the webview will have a viewport constrained to it's own dimensions
webView.getSettings().setUseWideViewPort(true);
//override the web client to open all links in the same webview
webView.setWebViewClient(new MyWebViewClient());
webView.setWebChromeClient(new MyWebChromeClient());
webView.loadUrl(URL);
Try this sample code I derived from Building Web Apps in WebView but using WebChromeClient:
public class MainActivity extends AppCompatActivity {
WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView=(WebView)findViewById(R.id.webview);
webView.setWebChromeClient(new WebChromeClient());
String urlString="https://www.youtube.com/watch?v=miomuSGoPzIe";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlString));
intent.setPackage("com.android.chrome");
try {
startActivity(intent);
} catch (ActivityNotFoundException ex) {
Log.v("MainActivity", "NO CHROME APP INSTALLED");
intent.setPackage(null);
startActivity(intent);
}
}
}
Here's the WebView in activity_main.xml
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
I have Firefox and Chrome in the Nexus phone and it opened the WebView in Chrome so I think it works.

How to play youtube video inside a floating popup window in android

I can create a floating popup window using standout library https://github.com/pingpongboss/StandOut . As I understand this library creates a service which creates a popup window.
Youtube API for Android provides YouTubePlayerView, which can be only used with YoutubeBaseActivity, and which I cannot use because the floating popup window belongs to a service.
Youtube API also provides YoutubePlayerFragment, which also cannot be used because services cannot work with fragments.
There is also WebView, which can be used here, which is not as nice as Youtube API for Android, but better than nothing. It almost works for me. The WebView is displayed inside a floating popup window, and the video is being played, but the video is just black.
Here is WebView code
private static final String FRAME_VIDEO = "<html><body>Video From YouTube<br><iframe width=\"320\" height=\"280\" src=\"https://www.youtube.com/embed/_oEA18Y8gM0\" frameborder=\"0\"></iframe></body></html>";
WebView webView = (WebView) findViewById(R.id.webView);
webView.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setPluginState(WebSettings.PluginState.ON);
webView.setWebChromeClient(new WebChromeClient());
webView.loadData(FRAME_VIDEO, "text/html", "utf-8");
Maybe one of these options is possible:
Somehow use YoutubePlayerView without YouTubeBaseActivity
Use fragments without activity
Fix the WebView code
Maybe there is some other way to play youtube videos inside a floating popup window

Android Webview - Webpage must fit the screen

I have tried the following to fit the web page based on the device screen size. But after code the text fields and drop down buttons are not working. Can anyone help me?
WebView myWebView;
#SuppressWarnings("deprecation")
#SuppressLint("SetJavaScriptEnabled")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
myWebView.getSettings().setPluginState(PluginState.ON);
myWebView.loadUrl("http://m.immigrer.com/potentiel");
myWebView.setWebViewClient(new myWebViewClient());
}
The page you linked to is designed to fit the screen by default. You should try setting setUseWideViewPort(true) as that makes the WebView pay attention to the site's viewport meta tag. Also, the LayoutAlgorithm setting might be messing things up: try using LayoutAlgorithm.NORMAL.
Use downloadListener or use onPageStarted() and check if your webview ends with '.pdf'.(Assuming your URL, which contains a PDF is ending with '.pdf'. Else check any qualifier you are using in all your URLs where you expect a PDF to download, and then pass on that URL to AsyncTask to download.
Tested the link with the following settings:
WebSettings s = getSettings();
s.setBuiltInZoomControls(true);
s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
s.setUseWideViewPort(true);
s.setLoadWithOverviewMode(true);
s.setSavePassword(true);
s.setSaveFormData(true);
s.setJavaScriptEnabled(true);
s.setRenderPriority(RenderPriority.HIGH);
s.setPluginState(android.webkit.WebSettings.PluginState.ON_DEMAND);
// enable navigator.geolocation
s.setGeolocationEnabled(true);
s.setGeolocationDatabasePath("");
// enable Web Storage: localStorage, sessionStorage
s.setDomStorageEnabled(true);
I was able to use text fields and drop down buttons. Some settings are irrelevant but hey it works

Android WebView - when playing a podcast in the webview, after leaving the screen the sound does not stop

I have the weirdest bug. I am running this exact code to play a popular business podcast:
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
WebView webview = new WebView(this);
webview.getSettings().setAppCacheEnabled(false);
webview.getSettings().setJavaScriptEnabled(true);
webview.setInitialScale(1);
webview.getSettings().setPluginState(PluginState.ON);
webview.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setAllowContentAccess(true);
webSettings.setEnableSmoothTransition(true);
webSettings.setLoadsImagesAutomatically(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setSupportZoom(true);
webSettings.setUseWideViewPort(true);
setContentView(webview);
webview.loadUrl("http://www.stitcher.com/podcast/entrepreneuronfirecom/entrepreneur-on-fire-tim-ferriss-other-incredible-entrepreneurs");
And it works just fine, and I am able to play the podcasts, but the problem is that when I leave the screen, the podcast keeps on playing.
Would anyone know what needs to be done to prevent that behavior?
Thanks,
Alex
Call myWebView.clearView() in the onStop() event of the activity.
The activity and therefore the webview is not necessarily destroyed when it is no longer visible. It is similar to just minimising a browser on the desktop.
Have a look at the activity lifecycle for more information.
Do something in onStop(), such as load a blank page into the WebView, or perhaps call clearView() on it.
The "bug" that you are seeing is no different than how desktop browsers behave. If you load that URL in a desktop browser, and you switch to a different tab in the browser, or minimize the browser window, the podcast keeps playing.

how to play video in android webview?

I want to put a web into webview.These is a video in the web.The video's format is wmv.I put the web in the android project "assets" file.Now I can scan the web,but the video can't play.This is the code on below.Who can help me?Thanks.
public class WebViewActivity extends Activity {
private WebView webview;
private WebSettings webSettings;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.webView);
webSettings = webview.getSettings();
webSettings.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
webSettings.setBuiltInZoomControls(true);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setPluginState(PluginState.ON);
webview.getSettings().setPluginsEnabled(true);
webview.loadUrl("file:///android_asset/demo/html/demo.html");
webview.setWebViewClient(new MyWebClient());
}
private class MyWebClient extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
WMV is a proprietary Microsoft video format. Chances are Android doesn't have a codec for it. You should convert it to something standard e.g H264.
Unfortunately video encoding is a minefield of proprietary tech. There are a few open source converters available. FFMPEG is probably the most extensive. There's a handy GUI for this called WinFF (if you're using windows).
You can test your HTML file by putting it and your video onto the SDcard and see if it works in it's simplest form. Try with different video formats as a sanity check.
WMV isn't widely supported on Android devices, but there are various tools to convert format.
https://gist.github.com/3718414 is a sample showing an Android webview and HTML5 player that works with the video codecs that Android supports (.mp4 is best for progressive video as it has by far the widest support)

Categories

Resources