【问题标题】:Inside scroll views ( ScrollView / RecyclerView / ListView ) videos are not playing.内部滚动视图( ScrollView / RecyclerView / ListView )视频未播放。
【发布时间】:2015-12-04 05:51:47
【问题描述】:

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

我也使用了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) 视图没有滚动...

【问题讨论】:

标签: android video scroll android-videoview android-recyclerview


【解决方案1】:

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

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

【讨论】:

  • 我没有得到 U,例如什么?
  • 在滚动视图中,视频无法使用 wrap_content 或 match_parent 播放。这时候我们要给videoView的Height & Width静态值,
【解决方案2】:

ScrollView 内的 VideoView 带有高度/宽度 wrap-content 或 match-content 会给你意想不到的结果。它不会正确获得高度和宽度。

解决方案:
您可以像这样在布局 XML 中为高度和宽度提供一个固定数字:

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

或者像这样在运行时将高度和宽度设置为videoView:

videoView.setDimension(256,256);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-02
    相关资源
    最近更新 更多