我试图在我的应用程序中显示图像和视频。为此,我正在使用RecyclerView
。图像正在显示,但视频不显示。该视频完全下载,但它不在OnPreparedListener
VideoView
内。如果我只使用VideoView
视频正在播放....请提出一些解决方案....谢谢。 (如果有人想看到的代码,我将发布)内部滚动视图(ScrollView/RecyclerView/ListView)视频不在播放。
我以前TextureView
和SurfaceView
还,我得到同样的问题,这些观点太...
这是scrollView
和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>
更新:
我试着用ListView
与VideoView
太....它也没有工作....
我所滚动的观点(ListView
/RecyclerView
内思考/ ScrollView
)视频(VideoView
)不在播放....如果播放(TextureView
/SurfaceView
)视图不滚动...
发布相关代码! –
你可能想看看:http://stackoverflow.com/a/10161316/295004和Grafika的DoubleDecode活动https://github.com/google/grafika/ –
嗨,@MorrisonChang我检查了答案,那工作,但在我的情况下,在任何滚动查看视频不播放....任何想法1 –