内部滚动视图 (ScrollView / RecyclerView / ListView) 视频未播放。

Inside scroll views ( ScrollView / RecyclerView / ListView ) videos are not playing.

我正在尝试在我的应用程序中显示图片和视频。为此,我使用 RecyclerView。图片正在显示,但视频不显示。视频已完全下载,但未进入 VideoView 中的 OnPreparedListener。如果我只使用 VideoView 视频正在播放....请提出一些解决方案....谢谢。 (如果有人想看代码,我会 post )

我也使用了 TextureViewSurfaceView,我也遇到了同样的问题...

这是 scrollViewVideoView 的示例。

str = "http://files.parsetfss.com/13e1c98b-895f-401e-83f3-7bf9b944001d/tfss-e199dd99-2564-4092-9df8-4b279ca2e7d0-video.mp4";

Ion.with(context)
            .load(str)
            .progress(new ProgressCallback() {
                @Override
                public void onProgress(long downloaded, long total) {
                    System.out.println("" + downloaded + " / " + total);
                    Log.d("TAG", downloaded + " / " + total);
                }
            })
            .write(fileCache.getFile(str))
            .setCallback(new FutureCallback<File>() {
                @Override
                public void onCompleted(Exception e, File file) {
                    // download done...
                    Log.d("TAG", file.getAbsolutePath());
                    // do stuff with the File or error
                    videoUri = Uri.fromFile(file);

                    videoView2.setVideoURI(videoUri);
                    videoView2.requestFocus();
                    videoView2.setOnPreparedListener
                            (new MediaPlayer.OnPreparedListener() {
                                 @Override
                                 public void onPrepared(final MediaPlayer mp) {
                                     Log.d("TAG", " mp4 Done ready to play ");
                                     videoView2.start();
                                     mp.setLooping(true);
                                     mp.setVolume(0, 0);
                                     videoView2.setOnTouchListener(new View.OnTouchListener() {
                                         @Override
                                         public boolean onTouch(View v, MotionEvent event) {
                                             Log.d("TAG", " Volume ");
                                             if (abc) {
                                                 mp.setVolume(0, 0);
                                                 Log.d("TAG", " Volume 0 ");
                                                 abc = false;
                                             } else {
                                                 mp.setVolume(1, 1);
                                                 Log.d("TAG", " Volume 1 ");
                                                 abc = true;
                                             }
                                             return false;
                                         }
                                     });

                                 }
                             }

                            );
                }
            });


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context="blpacademy.videotestwithscrollandwithout.VideoView_with_scroll">

<LinearLayout
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >

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


   </LinearLayout>
       </ScrollView>

更新:

我也用 ListViewVideoView 试过....它也不起作用....

滚动视图中我在想什么 (ListView / RecyclerView / ScrollView) 视频 (VideoView) 没有播放....如果播放 ( TextureView / SurfaceView ) 视图不滚动...

在我所有的实验之后,我知道在任何滚动视图中(ListView/RecyclerView/ScrollView)如果你想播放视频(videoView/ TextureView / SurfaceView ) 那么你不能使用 wrap_contentmatch_parent 作为宽度和高度。您必须为视频分配静态或动态值。然后视频将在滚动视图上工作。

<VideoView
    android:id="@+id/videoView2"
    android:layout_width="250dp"
    android:layout_height="300dp"
 />

VideoView inside ScrollView with height/width wrap-content or match-content 会给你意想不到的结果。它不会正确获取高度和宽度。

解法:
要么在布局 XML 中为高度和宽度提供一个固定数字,如下所示:

<VideoView
    android:id="@+id/videoView"
    android:layout_width="256dp"
    android:layout_height="256dp"
 />

或者在运行时将高度和宽度设置为 videoView,如下所示:

videoView.setDimension(256,256);