0

i am developing an application where i need to play video in webview android.

video is playing perfectly until i touch on webview. when i touch on it application freeze for some time and after that only white screen for next every time i play my app.i dont know why it is causing. here is my code of my application for review please let me know what i am doing wrong with code

i use this code

my activity

  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);

}
}

my xml layout file

<?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>

and manifest file

 <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>

Thanks

3
  • see you didnt create webview in xml. In runtime only u r creating webview and then in loadurl you set dimension size for that video. please create webview in xml file and try new other video url and test whether it works or not. Mar 25, 2013 at 11:33
  • @AndroidEnthusiastic ok i will try..
    – user2118554
    Mar 25, 2013 at 12:43
  • @AndroidEnthusiastic its also not working
    – user2118554
    Mar 25, 2013 at 12:49

1 Answer 1

0

the problem on this line

mVideoView = new WebView(getBaseContext());

in onDestroy method i have to null mVideoView object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.