Android的web视图的应用程序将不会让视频播放去全屏幕 [英] Android Webview app won't let video player go full screen
问题描述
您好我创建了一个web视图的应用程序为我的视频网站。网站的设计是一个混合加载为移动用户。与移动设备兼容仅视频被加载到所述混合。球员们从VK,土豆网,YouTube上的QuickTime。该影片只玩SDK 11或更高,但是当我点击播放按钮即可进入全屏模式,只从播放,而从来没有发射进入全屏模式,停止录像。我包括多达code,我可以,希望有人能帮助我。我GOOGLE了这死,没有取得进展。任何帮助将大大AP preciated。
(Webviewactivity.java)
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
。getWindow()requestFeature(Window.FEATURE_PROGRESS);
的setContentView(R.layout.main);
parentView =(RelativeLayout的)findViewById(R.id.parent_rl);
webviewProgress =(进度)findViewById(R.id.webview_progress);
的WebView =(web视图)findViewById(R.id.webview);
webview.getSettings()setJavaScriptEnabled(真)。
。webview.getSettings()setBuiltInZoomControls(真正的);
。webview.getSettings()setAllowFileAccess(真正的);
webview.setWebViewClient(新MyWebViewClient());
。webview.getSettings()setPluginState(WebSettings.PluginState.ON);
webview.loadUrl(URL);
webviewProgress.setProgress(0);
webview.setWebChromeClient(新MyWebChromeClient());
webview.setDownloadListener(新DownloadListener(){
公共无效onDownloadStart(URL字符串,字符串的userAgent,
字符串contentDisposition,字符串MIMETYPE,
长CONTENTLENGTH){
mProgressDialog =新ProgressDialog(WebViewActivity.this);
mProgressDialog.setMessage(下载...);
mProgressDialog.setIndeterminate(假);
mProgressDialog.setMax(100);
mProgressDialog
.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
DownloadFile downloadFile =新DownloadFile();
downloadFile.execute(URL);
}
});
initSlider();
initAdmob();
}
/ **
*当被选择的文件时,
* /
@覆盖
保护无效onActivityResult(INT申请code,INT结果code,
意向意图){
如果(要求code == FILECHOOSER_RESULT code){
如果(空== mUploadMessage)
返回;
开放的结果=意图== NULL ||因此code!= RESULT_OK?空值
:intent.getData();
mUploadMessage.onReceiveValue(结果);
mUploadMessage = NULL;
(main.xml中)
机器人:ID =@ + ID / parent_rl
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:keepScreenOn =真正的>
<进度
机器人:ID =@ + ID / webview_progress
风格=机器人:ATTR / progressBarStyleHorizontal
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentTop =真
机器人:=了maxHeight5dip
机器人:=了minHeight5dip
机器人:progressDrawable =@可绘制/ blueprogress/>
<的FrameLayout
机器人:ID =@ + ID /的FrameLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ ID / webview_progress
机器人:方向=垂直>
<的WebView
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / web视图
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT/>
(的Manifest.xml)
包=com.wCHfree
安卓版code =7
机器人:VERSIONNAME =1.1>
<用途-SDK
安卓的minSdkVersion =11
机器人:targetSdkVersion =17/>
<使用-权限的Android:名称=android.permission.ACCESS_NETWORK_STATE/>
<使用-权限的Android:名称=android.permission.INTERNET对/>
<应用
机器人:图标=@可绘制/ ic_launcher_red
机器人:标签=@字符串/ APP_NAME
机器人:主题=@安卓风格/ Theme.Black>
<活动
机器人:名称=com.webview.splashScreen.SplashScreenActivity
机器人:标签=@字符串/ APP_NAME
机器人:主题=@安卓风格/ Theme.NoTitleBar.Fullscreen>
<意向滤光器>
<作用机器人:名称=android.intent.action.MAIN/>
<类机器人:名称=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
<活动
机器人:名称=com.webview.splashScreen.WebViewActivity
机器人:configChanges =定位|屏幕尺寸|屏幕布置
机器人:标签=@字符串/ APP_NAME
机器人:主题=@安卓风格/ Theme.NoTitleBar.Fullscreen>
< /活性GT;
<活动
机器人:名称=com.google.ads.AdActivity
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
您需要执行 showCustomView
&放大器; WebChromeClient的 hideCustomView
的方法,还需要安卓hardwareAccelerated =你AndroidManifest文件真正的
。
我在这里发布我的样本项目。
我做了什么保持1的FrameLayout(customContainer)在我的main.xml中,并获得了showCustomView这里添加视图,并在onHide删除。同时隐藏/显示相应的WebView。下面code完美的作品上的设备。
AndroidManifest.xml中
< XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.example.webview
安卓版code =1
机器人:VERSIONNAME =1.0>
<使用-SDK安卓的minSdkVersion =8/>
<使用-权限的Android:名称=android.permission.INTERNET对/>
<应用机器人:标签=@字符串/ APP_NAME机器人:图标=@可绘制/ ic_launcher
机器人:hardwareAccelerated =真正的>
<活动机器人:名称=MyActivity
机器人:configChanges =方向| keyboardHidden
机器人:hardwareAccelerated =真
机器人:标签=@字符串/ APP_NAME>
<意向滤光器>
<作用机器人:名称=android.intent.action.MAIN/>
<类机器人:名称=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
< /用途>
< /舱单>
main.xml中
< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
>
<的WebView
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:ID =@ + ID / web视图
机器人:layout_gravity =中心
/>
<的FrameLayout
机器人:ID =@ + ID / customViewContainer
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:能见度=水涨船高
/>
< / LinearLayout中>
video_progress.xml
< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / progress_indicator
机器人:方向=垂直
机器人:layout_centerInParent =真
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
<进度机器人:ID =@机器人:ID /进步
风格=机器人:ATTR / progressBarStyleLarge
机器人:layout_gravity =中心
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT/>
< TextView的Android版本:paddingTop =5dip
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =中心
机器人:文本=加载
机器人:TEXTSIZE =14sp
机器人:文字颜色=机器人:ATTR / textColorPrimary/>
< / LinearLayout中>
MyActivity.java
包com.example.webview;
进口android.app.Activity;
进口android.graphics.Bitmap;
进口android.os.Bundle;
进口android.view.KeyEvent;
进口android.view.LayoutInflater;
进口android.view.View;
进口android.webkit.WebChromeClient;
进口android.webkit.WebView;
进口android.webkit.WebViewClient;
进口android.widget.FrameLayout;
公共类MyActivity延伸活动{
私人的WebView web视图;
私人的FrameLayout customViewContainer;
私人WebChromeClient.CustomViewCallback customViewCallback;
私人查看mCustomView;
私人myWebChromeClient mWebChromeClient;
私人myWebViewClient mWebViewClient;
/ **
*第一次创建活动时调用。
* /
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
customViewContainer =(的FrameLayout)findViewById(R.id.customViewContainer);
web视图=(web视图)findViewById(R.id.webView);
mWebViewClient =新myWebViewClient();
webView.setWebViewClient(mWebViewClient);
mWebChromeClient =新myWebChromeClient();
webView.setWebChromeClient(mWebChromeClient);
webView.getSettings()setJavaScriptEnabled(真)。
webView.getSettings()setAppCacheEnabled(真)。
。webView.getSettings()setBuiltInZoomControls(真正的);
。webView.getSettings()setSaveFormData(真正的);
webView.loadUrl(http://m.youtube.com);
}
公共布尔inCustomView(){
返回(mCustomView!= NULL);
}
公共无效hideCustomView(){
mWebChromeClient.onHideCustomView();
}
@覆盖
保护无效的onPause(){
super.onPause(); //要改变的重载方法体使用文件|设置|文件模板。
webView.onPause();
}
@覆盖
保护无效onResume(){
super.onResume(); //要改变的重载方法体使用文件|设置|文件模板。
webView.onResume();
}
@覆盖
保护无效的onStop(){
super.onStop(); //要改变的重载方法体使用文件|设置|文件模板。
如果(inCustomView()){
hideCustomView();
}
}
@覆盖
公共布尔的onkeydown(INT键code,KeyEvent的事件){
如果(键code == KeyEvent.KEY code_BACK){
如果(inCustomView()){
hideCustomView();
返回true;
}
如果((mCustomView == NULL)及和放大器; webView.canGoBack()){
webView.goBack();
返回true;
}
}
返回super.onKeyDown(键code,事件);
}
类myWebChromeClient扩展WebChromeClient {
私人位图mDefaultVideoPoster;
私人查看mVideoProgressView;
@覆盖
公共无效onShowCustomView(查看视图,INT requestedOrientation,CustomViewCallback回调){
onShowCustomView(查看,回调); //要改变的重载方法体使用文件|设置|文件模板。
}
@覆盖
公共无效onShowCustomView(查看视图,CustomViewCallback回调){
//如果一个视图已经存在,则立即终止新
如果(mCustomView!= NULL){
callback.onCustomViewHidden();
返回;
}
mCustomView =图。
webView.setVisibility(View.GONE);
customViewContainer.setVisibility(View.VISIBLE);
customViewContainer.addView(视图);
customViewCallback =回调;
}
@覆盖
公共查看getVideoLoadingProgressView(){
如果(mVideoProgressView == NULL){
LayoutInflater充气= LayoutInflater.from(MyActivity.this);
mVideoProgressView = inflater.inflate(R.layout.video_progress,NULL);
}
返回mVideoProgressView;
}
@覆盖
公共无效onHideCustomView(){
super.onHideCustomView(); //要改变的重载方法体使用文件|设置|文件模板。
如果(mCustomView == NULL)
返回;
webView.setVisibility(View.VISIBLE);
customViewContainer.setVisibility(View.GONE);
//隐藏的自定义视图。
mCustomView.setVisibility(View.GONE);
//将其从容器中的自定义视图。
customViewContainer.removeView(mCustomView);
customViewCallback.onCustomViewHidden();
mCustomView = NULL;
}
}
类myWebViewClient扩展WebViewClient {
@覆盖
公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL){
返回super.shouldOverrideUrlLoading(查看,网址); //要改变的重载方法体使用文件|设置|文件模板。
}
}
}
Hi I created a webview app for my video site. The design of the site is a hybrid that loads for mobile users. Only videos compatible with mobile devices are loaded onto the hybrid. The players are from Vk, dailymotion, youtube, quicktime. The videos only play on sdk 11 and higher but when I click on the player button to go full screen it only stops the video from playing while never launching into full screen mode. I'm including as much code as I can in hopes someone can help me. I've googled this to death with no progress made. Any help would be greatly appreciated.
(Webviewactivity.java)
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main);
parentView = (RelativeLayout) findViewById(R.id.parent_rl);
webviewProgress = (ProgressBar) findViewById(R.id.webview_progress);
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setBuiltInZoomControls(true);
webview.getSettings().setAllowFileAccess(true);
webview.setWebViewClient(new MyWebViewClient());
webview.getSettings().setPluginState(WebSettings.PluginState.ON);
webview.loadUrl(URL);
webviewProgress.setProgress(0);
webview.setWebChromeClient(new MyWebChromeClient());
webview.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
mProgressDialog = new ProgressDialog(WebViewActivity.this);
mProgressDialog.setMessage("Downloading...");
mProgressDialog.setIndeterminate(false);
mProgressDialog.setMax(100);
mProgressDialog
.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
DownloadFile downloadFile = new DownloadFile();
downloadFile.execute(url);
}
});
initSlider();
initAdmob();
}
/**
* When when file was chosen
*/
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
if (requestCode == FILECHOOSER_RESULTCODE) {
if (null == mUploadMessage)
return;
Uri result = intent == null || resultCode != RESULT_OK ? null
: intent.getData();
mUploadMessage.onReceiveValue(result);
mUploadMessage = null;
(Main.xml)
android:id="@+id/parent_rl"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:keepScreenOn="true" >
<ProgressBar
android:id="@+id/webview_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:maxHeight="5dip"
android:minHeight="5dip"
android:progressDrawable="@drawable/blueprogress" />
<FrameLayout
android:id="@+id/framelayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/webview_progress"
android:orientation="vertical" >
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
(Manifest.xml)
package="com.wCHfree"
android:versionCode="7"
android:versionName="1.1" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher_red"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black" >
<activity
android:name="com.webview.splashScreen.SplashScreenActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.webview.splashScreen.WebViewActivity"
android:configChanges="orientation|screenSize|screenLayout"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
</activity>
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
You need to implement showCustomView
& hideCustomView
method of WebChromeClient, also You need android:hardwareAccelerated="true"
in your AndroidManifest File.
I am posting my sample project here.
What i have done is kept one Framelayout(customContainer) in my main.xml, and adding view received in showCustomView here, and removing it in onHide. Also hiding/showing webview accordingly. Below code works perfectly on device.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.webview"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher"
android:hardwareAccelerated="true">
<activity android:name="MyActivity"
android:configChanges="orientation|keyboardHidden"
android:hardwareAccelerated="true"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/webView"
android:layout_gravity="center"
/>
<FrameLayout
android:id="@+id/customViewContainer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone"
/>
</LinearLayout>
video_progress.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/progress_indicator"
android:orientation="vertical"
android:layout_centerInParent="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ProgressBar android:id="@android:id/progress"
style="?android:attr/progressBarStyleLarge"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:paddingTop="5dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="loading"
android:textSize="14sp"
android:textColor="?android:attr/textColorPrimary"/>
</LinearLayout>
MyActivity.java
package com.example.webview;
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
public class MyActivity extends Activity {
private WebView webView;
private FrameLayout customViewContainer;
private WebChromeClient.CustomViewCallback customViewCallback;
private View mCustomView;
private myWebChromeClient mWebChromeClient;
private myWebViewClient mWebViewClient;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
customViewContainer = (FrameLayout) findViewById(R.id.customViewContainer);
webView = (WebView) findViewById(R.id.webView);
mWebViewClient = new myWebViewClient();
webView.setWebViewClient(mWebViewClient);
mWebChromeClient = new myWebChromeClient();
webView.setWebChromeClient(mWebChromeClient);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setSaveFormData(true);
webView.loadUrl("http://m.youtube.com");
}
public boolean inCustomView() {
return (mCustomView != null);
}
public void hideCustomView() {
mWebChromeClient.onHideCustomView();
}
@Override
protected void onPause() {
super.onPause(); //To change body of overridden methods use File | Settings | File Templates.
webView.onPause();
}
@Override
protected void onResume() {
super.onResume(); //To change body of overridden methods use File | Settings | File Templates.
webView.onResume();
}
@Override
protected void onStop() {
super.onStop(); //To change body of overridden methods use File | Settings | File Templates.
if (inCustomView()) {
hideCustomView();
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (inCustomView()) {
hideCustomView();
return true;
}
if ((mCustomView == null) && webView.canGoBack()) {
webView.goBack();
return true;
}
}
return super.onKeyDown(keyCode, event);
}
class myWebChromeClient extends WebChromeClient {
private Bitmap mDefaultVideoPoster;
private View mVideoProgressView;
@Override
public void onShowCustomView(View view, int requestedOrientation, CustomViewCallback callback) {
onShowCustomView(view, callback); //To change body of overridden methods use File | Settings | File Templates.
}
@Override
public void onShowCustomView(View view,CustomViewCallback callback) {
// if a view already exists then immediately terminate the new one
if (mCustomView != null) {
callback.onCustomViewHidden();
return;
}
mCustomView = view;
webView.setVisibility(View.GONE);
customViewContainer.setVisibility(View.VISIBLE);
customViewContainer.addView(view);
customViewCallback = callback;
}
@Override
public View getVideoLoadingProgressView() {
if (mVideoProgressView == null) {
LayoutInflater inflater = LayoutInflater.from(MyActivity.this);
mVideoProgressView = inflater.inflate(R.layout.video_progress, null);
}
return mVideoProgressView;
}
@Override
public void onHideCustomView() {
super.onHideCustomView(); //To change body of overridden methods use File | Settings | File Templates.
if (mCustomView == null)
return;
webView.setVisibility(View.VISIBLE);
customViewContainer.setVisibility(View.GONE);
// Hide the custom view.
mCustomView.setVisibility(View.GONE);
// Remove the custom view from its container.
customViewContainer.removeView(mCustomView);
customViewCallback.onCustomViewHidden();
mCustomView = null;
}
}
class myWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return super.shouldOverrideUrlLoading(view, url); //To change body of overridden methods use File | Settings | File Templates.
}
}
}
You can clone sample project from here..
这篇关于Android的web视图的应用程序将不会让视频播放去全屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!