From 1d7f15d6566e1f82a19d2c83f8fb9dacf9e7595c Mon Sep 17 00:00:00 2001 From: Omer Habib <30689349+omerhabib26@users.noreply.github.com> Date: Mon, 9 Oct 2023 21:27:45 +0500 Subject: [PATCH] fix: Handle fallback video format on CourseUnitNavigationActivity (#1835) - Show fallback video in case course doesn't have any video quality available fixes: LEARNER-9658 --- .../org/edx/mobile/model/course/VideoBlockModel.java | 8 +++++--- .../org/edx/mobile/module/db/DatabaseModelFactory.java | 10 ++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/OpenEdXMobile/src/main/java/org/edx/mobile/model/course/VideoBlockModel.java b/OpenEdXMobile/src/main/java/org/edx/mobile/model/course/VideoBlockModel.java index 86b2c8ded3..3b7bb8d954 100644 --- a/OpenEdXMobile/src/main/java/org/edx/mobile/model/course/VideoBlockModel.java +++ b/OpenEdXMobile/src/main/java/org/edx/mobile/model/course/VideoBlockModel.java @@ -77,9 +77,11 @@ public void setData(VideoData data) { * @return The size of the video if available, -1 otherwise. */ public long getPreferredVideoEncodingSize(VideoQuality preferredVideoQuality) { - if (data != null && data.encodedVideos != null - && data.encodedVideos.getPreferredVideoInfoForDownloading(preferredVideoQuality) != null) { - return data.encodedVideos.getPreferredVideoInfoForDownloading(preferredVideoQuality).fileSize; + if (data != null && data.encodedVideos != null) { + VideoInfo videoInfo = data.encodedVideos.getPreferredVideoInfoForDownloading(preferredVideoQuality); + if (videoInfo != null && videoInfo.fileSize > 0) { + return videoInfo.fileSize; + } } return -1; } diff --git a/OpenEdXMobile/src/main/java/org/edx/mobile/module/db/DatabaseModelFactory.java b/OpenEdXMobile/src/main/java/org/edx/mobile/module/db/DatabaseModelFactory.java index a150ef34cc..73bf736b85 100644 --- a/OpenEdXMobile/src/main/java/org/edx/mobile/module/db/DatabaseModelFactory.java +++ b/OpenEdXMobile/src/main/java/org/edx/mobile/module/db/DatabaseModelFactory.java @@ -103,9 +103,15 @@ public static VideoModel getModel(VideoData vrm, VideoBlockModel block, VideoQua e.eid = root.getCourseId(); e.duration = vrm.duration; final VideoInfo preferredVideoInfo = vrm.encodedVideos.getPreferredVideoInfoForDownloading(videoQuality); - e.size = preferredVideoInfo.fileSize; + final VideoInfo videoInfo = vrm.encodedVideos.getPreferredNativeVideoInfo(); + if (preferredVideoInfo != null) { + e.size = preferredVideoInfo.fileSize; + e.url = preferredVideoInfo.url; + } else if (videoInfo != null) { + e.size = videoInfo.fileSize; + e.url = videoInfo.url; + } e.title = block.getDisplayName(); - e.url = preferredVideoInfo.url; e.url_hls = getVideoNetworkUrlOrNull(vrm.encodedVideos.getHls()); e.url_high_quality = getVideoNetworkUrlOrNull(vrm.encodedVideos.getMobileHigh()); e.url_low_quality = getVideoNetworkUrlOrNull(vrm.encodedVideos.getMobileLow());