Search code examples
androidandroid-videoviewandroid-scrollview

Videoview in scrollview issue


I have googled a lot to solve this issue but it doesn't works in any case. Have tried everything as mentioned in Android::VideoView inside a ScrollView and Android Scrollview having videoview is giving problem.

The problem is when i put the video view in scrollview it doesn't works, but when remove the scrollview it works absolutely fine.

Here is the example code :

// xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/btn_video"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="start" />

    <ScrollView
        android:id="@+id/scrl"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btn_video" >

        <VideoView
            android:id="@+id/videoView_1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </ScrollView>

</RelativeLayout>

And the Java code, MainActivity class

package com.practice.videoviewexample;


import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Button;
import android.widget.VideoView;

public class MainActivity extends Activity {

    private VideoView videoView_exhibit;
    private Button btnVideo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        videoView_exhibit = (VideoView) findViewById(R.id.videoView_1);
        btnVideo = (Button) findViewById(R.id.btn_video);


        Uri video = Uri.parse("android.resource://" + getPackageName() + "/"+ R.raw.abc);
        videoView_exhibit.setVideoURI(video);
        videoView_exhibit.start();

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

Can anyone help? Thanx in advance!


Solution

  • This is a known limitation of VideoView. Check this : VideoView inside ScrollView

    Hope this helps.