【发布时间】:2015-12-04 05:51:47
【问题描述】:
我正在尝试在我的应用中显示图像和视频。为此,我使用RecyclerView。图像显示,但视频不显示。视频已完全下载,但不会进入VideoView 中的OnPreparedListener。如果我只使用VideoView 视频正在播放....请提出一些解决方案....谢谢。 (如果有人想看我会发布的代码)
我也使用了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) 视图没有滚动...
【问题讨论】:
-
你可能想看看:stackoverflow.com/a/10161316/295004 和 Grafika 的 DoubleDecode 活动github.com/google/grafika
-
嗨,@MorrisonChang 我检查了答案,这是有效的,但在我的情况下,在任何滚动视图中视频都没有播放......任何想法 1
标签: android video scroll android-videoview android-recyclerview