我正在开发一个应用程序,我需要在 webview android 中播放视频。
视频播放完美,直到我触摸 webview。当我触摸它时,应用程序冻结了一段时间,之后每次我玩我的应用程序时只有白屏。我不知道它为什么会导致。这是我的申请代码以供审核,请让我知道我在代码上做错了什么
我用这个代码
我的活动
public class VideoViewActivity extends Activity {
FrameLayout frame;
WebView mVideoView;
String viewSource;
@Override
public void onCreate(Bundle savedInstanceState) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
super.onCreate(savedInstanceState);
setContentView(R.layout.video);
frame = (FrameLayout) findViewById(R.id.videoview);
mVideoView = new WebView(getBaseContext());
boolean flashInstalled = false;
try {
PackageManager pm = getPackageManager();
ApplicationInfo ai = pm.getApplicationInfo("com.adobe.flashplayer",
0);
if (ai != null)
flashInstalled = true;
} catch (NameNotFoundException e) {
flashInstalled = false;
Toast.makeText(getBaseContext(), "Flash Player Not Installed!!",
Toast.LENGTH_SHORT).show();
}
mVideoView.setWebViewClient(new WebViewClient());
mVideoView.setWebChromeClient(new WebChromeClient());
mVideoView.getSettings().setJavaScriptEnabled(true);
mVideoView.getSettings().setAppCacheEnabled(true);
mVideoView.getSettings().setDomStorageEnabled(true);
mVideoView.getTouchables();
// how plugin is enabled change in API 8
if (Build.VERSION.SDK_INT < 8) {
mVideoView.getSettings().setPluginsEnabled(true);
} else {
mVideoView.getSettings().setPluginState(PluginState.ON);
}
mVideoView
.loadUrl("http://player.vimeo.com/video/24577973?player_id=player&autoplay=1&title=0&byline=0&portrait=0&api=1&maxheight=480&maxwidth=800");
frame.addView(mVideoView);
}
}
我的 xml 布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
>
<FrameLayout
android:layout_width="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:id="@+id/videoview"
/>
</LinearLayout>
和清单文件
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.com"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" android:hardwareAccelerated="true"
android:theme="@style/AppTheme" >
<activity
android:name=".VideoViewActivity"
android:label="Demo"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.Black.NoTitleBar"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
谢谢