From b5af62c3eae6501c6db3561976fd4ac7458c5763 Mon Sep 17 00:00:00 2001 From: Valere Date: Tue, 27 Aug 2019 16:50:02 +0200 Subject: [PATCH] Some video won't play VideoView fails to play some remote uri video on some device. For now video is downloaded locally in internal cache then played. This offers basic support before full media preview implementation --- CHANGES.md | 1 + .../features/media/VideoContentRenderer.kt | 36 ++++++++++++++++--- .../layout/activity_video_media_viewer.xml | 3 ++ 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a3b37761..2c498851 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,7 @@ Bugfix: - Fix text diff linebreak display (#441) - Date change message repeats for each redaction until a normal message (#358) - Slide-in reply icon is distorted (#423) + - Some video won't play Translations: - diff --git a/vector/src/main/java/im/vector/riotx/features/media/VideoContentRenderer.kt b/vector/src/main/java/im/vector/riotx/features/media/VideoContentRenderer.kt index 22650b0e..0509a0d4 100644 --- a/vector/src/main/java/im/vector/riotx/features/media/VideoContentRenderer.kt +++ b/vector/src/main/java/im/vector/riotx/features/media/VideoContentRenderer.kt @@ -89,18 +89,44 @@ class VideoContentRenderer @Inject constructor(private val activeSessionHolder: }) } } else { - thumbnailView.isVisible = false - loadingView.isVisible = false val resolvedUrl = contentUrlResolver.resolveFullSize(data.url) if (resolvedUrl == null) { + thumbnailView.isVisible = false + loadingView.isVisible = false errorView.isVisible = true errorView.setText(R.string.unknown_error) } else { - videoView.isVisible = true - videoView.setVideoPath(resolvedUrl) - videoView.start() + + //Temporary code, some remote videos are not played by videoview setVideoUri + //So for now we download them then play + thumbnailView.isVisible = true + loadingView.isVisible = true + + activeSessionHolder.getActiveSession() + .downloadFile( + FileService.DownloadMode.FOR_INTERNAL_USE, + data.eventId, + data.filename, + data.url, + null, + object : MatrixCallback { + override fun onSuccess(data: File) { + thumbnailView.isVisible = false + loadingView.isVisible = false + videoView.isVisible = true + + videoView.setVideoPath(data.path) + videoView.start() + } + + override fun onFailure(failure: Throwable) { + loadingView.isVisible = false + errorView.isVisible = true + errorView.text = errorFormatter.toHumanReadable(failure) + } + }) } } } diff --git a/vector/src/main/res/layout/activity_video_media_viewer.xml b/vector/src/main/res/layout/activity_video_media_viewer.xml index f21e6daf..c68577bc 100644 --- a/vector/src/main/res/layout/activity_video_media_viewer.xml +++ b/vector/src/main/res/layout/activity_video_media_viewer.xml @@ -34,7 +34,9 @@ android:id="@+id/videoMediaViewerThumbnailView" android:layout_width="match_parent" android:layout_height="match_parent" + android:layout_gravity="center" android:visibility="gone" + android:scaleType="centerInside" tools:visibility="visible" />