WebView在播放视频和触摸时执行崩溃

时间:2013-03-25 10:31:10

标签: android webview video-streaming vimeo

我正在开发一个应用程序,我需要在webview android中播放视频。

视频播放完美,直到我触摸webview。 当我触摸它应用程序冻结一段时间后,每次我只播放我的app.i不知道它为什么导致下一个白色屏幕。 这是我的审查申请代码,请告诉我我的代码错误

我使用此代码

我的活动

  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>

由于

1 个答案:

答案 0 :(得分:0)

这一行的问题

mVideoView = new WebView(getBaseContext());

在onDestroy方法中我必须使mVideoView对象为空。