Reputation: 368
I am trying to display Images and Videos in my App. For that I am using RecyclerView
. Images are displaying but Videos are not displaying. The video completely downloading but it's not going inside OnPreparedListener
in VideoView
. If I am using only VideoView
the video is playing .... Please suggest some solution.... Thank you. ( If anyone want to see the code I will post )
I used TextureView
and SurfaceView
also, I am getting same problem with these views too...
This is the sample example with scrollView
and VideoView
.
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>
Update:
I tried with ListView
with VideoView
too.... it is also not working ....
What I am thinking inside scroll views ( ListView
/ RecyclerView
/ ScrollView
) the video ( VideoView
) is not playing .... If playing ( TextureView
/ SurfaceView
) the view is not scrolling...
Upvotes: 0
Views: 1456
Reputation: 1
VideoView inside ScrollView with height/width wrap-content or match-content will give you unexpected results. It will not get height and width properly.
Solution:
Either you provide a fixed number for the height and width in the layout XML like this:
<VideoView
android:id="@+id/videoView"
android:layout_width="256dp"
android:layout_height="256dp"
/>
Or set the height and width to videoView at runtime like this:
videoView.setDimension(256,256);
Upvotes: 0
Reputation: 368
After all my experiments I got to know that inside any scroll views ( ListView
/ RecyclerView
/ ScrollView
) if you want to play video ( videoView
/ TextureView
/ SurfaceView
) then you can't use wrap_content
or match_parent
for width & height. You have to assign static or dynamic values to the video. Then the video will work on scrolling views.
<VideoView
android:id="@+id/videoView2"
android:layout_width="250dp"
android:layout_height="300dp"
/>
Upvotes: 1