From 05e3889fe7eb9c01bd050da1da9d9e7f24f0945e Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sat, 12 Sep 2020 23:28:19 +0800 Subject: Fix gfycat videos cannot be played after clicking the preview or fullscreen in PostRecyclerViewAdapter and CommentAndPostRecyclerViewAdapter. --- .../Activity/ViewVideoActivity.java | 5 +-- .../Adapter/CommentAndPostRecyclerViewAdapter.java | 39 ++++++++++++++++----- .../Adapter/PostRecyclerViewAdapter.java | 40 +++++++++++++++++----- 3 files changed, 66 insertions(+), 18 deletions(-) (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java index 8e26f0e0..946d92a5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java @@ -33,7 +33,6 @@ import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.SimpleExoPlayer; import com.google.android.exoplayer2.source.ProgressiveMediaSource; import com.google.android.exoplayer2.source.TrackGroupArray; -import com.google.android.exoplayer2.source.dash.DashMediaSource; import com.google.android.exoplayer2.source.hls.HlsMediaSource; import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; @@ -217,6 +216,8 @@ public class ViewVideoActivity extends AppCompatActivity { mVideoUri = Uri.parse(videoUrl); videoDownloadUrl = savedInstanceState.getString(VIDEO_DOWNLOAD_URL_STATE); } + } else { + mVideoUri = intent.getData(); } if (mVideoUri == null) { @@ -234,7 +235,7 @@ public class ViewVideoActivity extends AppCompatActivity { } else { dataSourceFactory = new DefaultDataSourceFactory(ViewVideoActivity.this, Util.getUserAgent(ViewVideoActivity.this, "Infinity")); - player.prepare(new DashMediaSource.Factory(dataSourceFactory).createMediaSource(mVideoUri)); + player.prepare(new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(mVideoUri)); preparePlayer(savedInstanceState); } } else if (videoType == VIDEO_TYPE_DIRECT) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java index c86b4d38..b93f3375 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -2353,10 +2353,25 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { Intent intent = new Intent(mActivity, ViewVideoActivity.class); - intent.setData(Uri.parse(mPost.getVideoUrl())); - intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl()); - intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, mPost.getSubredditName()); - intent.putExtra(ViewVideoActivity.EXTRA_ID, mPost.getId()); + if (mPost.isGfycat()) { + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT); + intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, mPost.getGfycatId()); + if (mPost.isLoadGfyOrRedgifsVideoSuccess()) { + intent.setData(Uri.parse(mPost.getVideoUrl())); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl()); + } + } else if (mPost.isRedgifs()) { + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS); + intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, mPost.getGfycatId()); + if (mPost.isLoadGfyOrRedgifsVideoSuccess()) { + intent.setData(Uri.parse(mPost.getVideoUrl())); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl()); + } + } else { + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl()); + intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, mPost.getSubredditName()); + intent.putExtra(ViewVideoActivity.EXTRA_ID, mPost.getId()); + } intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, mPost.getTitle()); intent.putExtra(ViewVideoActivity.EXTRA_PROGRESS_SECONDS, helper.getLatestPlaybackInfo().getResumePosition()); intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, mPost.isNSFW()); @@ -2551,10 +2566,18 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { if (mPost.getPostType() == Post.VIDEO_TYPE) { Intent intent = new Intent(mActivity, ViewVideoActivity.class); - intent.setData(Uri.parse(mPost.getVideoUrl())); - intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl()); - intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, mPost.getSubredditName()); - intent.putExtra(ViewVideoActivity.EXTRA_ID, mPost.getId()); + if (mPost.isGfycat()) { + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT); + intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, mPost.getGfycatId()); + } else if (mPost.isRedgifs()) { + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS); + intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, mPost.getGfycatId()); + } else { + intent.setData(Uri.parse(mPost.getVideoUrl())); + intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, mPost.getSubredditName()); + intent.putExtra(ViewVideoActivity.EXTRA_ID, mPost.getId()); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl()); + } intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, mPost.getTitle()); intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, mPost.isNSFW()); mActivity.startActivity(intent); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index 9315f153..db81a51f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -1868,10 +1868,26 @@ public class PostRecyclerViewAdapter extends PagedListAdapter