From 5d41c996b0c2d5d2a951fd81b57355c6fdfd0f40 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Sat, 24 Feb 2024 09:29:32 -0500 Subject: Use mp4 version of the fallback video. --- .../infinityforreddit/activities/ViewVideoActivity.java | 17 ++++++++++------- .../infinityforreddit/post/ParsePost.java | 4 ++-- .../ml/docilealligator/infinityforreddit/post/Post.java | 14 +++++++------- 3 files changed, 19 insertions(+), 16 deletions(-) (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java index ba3a9c15..d827bcc8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java @@ -184,7 +184,7 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe private String videoDownloadUrl; private String videoFileName; - private String videoFallbackHLSUrl; + private String videoFallbackDirectUrl; private String subredditName; private String id; private boolean wasPlaying; @@ -411,7 +411,7 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe Post post = intent.getParcelableExtra(EXTRA_POST); if (post != null) { titleTextView.setText(post.getTitle()); - videoFallbackHLSUrl = post.getVideoFallBackHLSUrl(); + videoFallbackDirectUrl = post.getVideoFallBackDirectUrl(); } trackSelector = new DefaultTrackSelector(this); @@ -757,7 +757,7 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe new FetchPost.FetchPostListener() { @Override public void fetchPostSuccess(Post post) { - videoFallbackHLSUrl = post.getVideoFallBackHLSUrl(); + videoFallbackDirectUrl = post.getVideoFallBackDirectUrl(); if (post.isRedgifs()) { videoType = VIDEO_TYPE_REDGIFS; String redgifsId = post.getRedgifsId(); @@ -851,12 +851,15 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe } private void loadFallbackVideo(Bundle savedInstanceState) { - if (videoFallbackHLSUrl != null) { + if (videoFallbackDirectUrl != null) { MediaItem mediaItem = player.getCurrentMediaItem(); - if (mediaItem == null || mediaItem.localConfiguration != null && !videoFallbackHLSUrl.equals(mediaItem.localConfiguration.uri.toString())) { - videoType = VIDEO_TYPE_NORMAL; + if (mediaItem == null || mediaItem.localConfiguration != null && !videoFallbackDirectUrl.equals(mediaItem.localConfiguration.uri.toString())) { + videoType = VIDEO_TYPE_DIRECT; + videoDownloadUrl = videoFallbackDirectUrl; + mVideoUri = Uri.parse(videoFallbackDirectUrl); + videoFileName = FilenameUtils.getName(videoDownloadUrl); player.prepare(); - player.setMediaSource(new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(videoFallbackHLSUrl))); + player.setMediaSource(new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(mVideoUri))); preparePlayer(savedInstanceState); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java index c0a65008..6c786189 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java @@ -399,8 +399,8 @@ public class ParsePost { post.setVideoUrl(videoUrl); post.setVideoDownloadUrl(videoDownloadUrl); } - post.setVideoFallBackHLSUrl(Html.fromHtml(data.getJSONObject(JSONUtils.PREVIEW_KEY) - .getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.HLS_URL_KEY)).toString()); + post.setVideoFallBackDirectUrl(Html.fromHtml(data.getJSONObject(JSONUtils.PREVIEW_KEY) + .getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.FALLBACK_URL_KEY)).toString()); } else { if (path.endsWith(".jpg") || path.endsWith(".png") || path.endsWith(".jpeg")) { //Image post diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java index e8fc7ee1..d15c6f7e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java @@ -43,7 +43,7 @@ public class Post implements Parcelable { private String url; private String videoUrl; private String videoDownloadUrl; - private String videoFallBackHLSUrl; + private String videoFallBackDirectUrl; private String redgifsId; private String streamableShortCode; private boolean isImgur; @@ -168,7 +168,7 @@ public class Post implements Parcelable { url = in.readString(); videoUrl = in.readString(); videoDownloadUrl = in.readString(); - videoFallBackHLSUrl = in.readString(); + videoFallBackDirectUrl = in.readString(); redgifsId = in.readString(); streamableShortCode = in.readString(); isImgur = in.readByte() != 0; @@ -330,12 +330,12 @@ public class Post implements Parcelable { this.videoDownloadUrl = videoDownloadUrl; } - public String getVideoFallBackHLSUrl() { - return videoFallBackHLSUrl; + public String getVideoFallBackDirectUrl() { + return videoFallBackDirectUrl; } - public void setVideoFallBackHLSUrl(String videoFallBackHLSUrl) { - this.videoFallBackHLSUrl = videoFallBackHLSUrl; + public void setVideoFallBackDirectUrl(String videoFallBackDirectUrl) { + this.videoFallBackDirectUrl = videoFallBackDirectUrl; } public String getRedgifsId() { @@ -498,7 +498,7 @@ public class Post implements Parcelable { dest.writeString(url); dest.writeString(videoUrl); dest.writeString(videoDownloadUrl); - dest.writeString(videoFallBackHLSUrl); + dest.writeString(videoFallBackDirectUrl); dest.writeString(redgifsId); dest.writeString(streamableShortCode); dest.writeByte((byte) (isImgur ? 1 : 0)); -- cgit v1.2.3