4

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!

Community
  • 1
  • 1
kapil thadani
  • 1,425
  • 14
  • 26
  • You're describing the problem and you're also mentioning that this is a technical constraint that we all are aware of. So don't put the ViewView in the ScrollView ... – gunar Nov 29 '13 at 10:16
  • I expect any alternatives for the problem. I have a requirement to show a video view at the bottom of scrollview. – kapil thadani Nov 29 '13 at 10:19
  • 1
    Try to use the `TextureView` (API level 14 upwards). Haven't used it before, but Romain Guy says it's a valid alternative. – gunar Nov 29 '13 at 10:21

4 Answers4

5

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

Hope this helps.

Siddharth_Vyas
  • 9,972
  • 10
  • 39
  • 69
2

By changing VideoView attributes android:layout_width and android:layout_height to fixed dp size (100dp) VideoView shown up.

Winzipas
  • 176
  • 2
  • 6
0

Try Adding :

 android:background="#0000"

to the videoView

Max Droid
  • 924
  • 9
  • 10
0

I didn't managed to get the VideoView working inside a ScrollView, but instead in some cases it is possible to scale the VideoView depending on the available vertical space by setting the VideoView's size attributes to:

<VideoView
            android:id="@+id/myVideoView"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"/>

This will scale the VideoView and keep the aspect ratio of the video.

Harry
  • 907
  • 10
  • 11