我正在开发一个应用程序,我需要在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>
谢谢
发布于 2013-04-01 21:25:26
这条线上的问题
mVideoView = new WebView(getBaseContext());在onDestroy方法中,我必须将mVideoView对象设为空。
https://stackoverflow.com/questions/15612731
复制相似问题