Fix gfycat videos cannot be played after clicking the preview or fullscreen in PostRecyclerViewAdapter and CommentAndPostRecyclerViewAdapter.

This commit is contained in:
Alex Ning 2020-09-12 23:28:19 +08:00
parent 52ee70a57e
commit 05e3889fe7
3 changed files with 66 additions and 18 deletions

View File

@ -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) {

View File

@ -2353,10 +2353,25 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
fullscreenButton.setOnClickListener(view -> {
Intent intent = new Intent(mActivity, ViewVideoActivity.class);
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<Recy
mImageView.setOnClickListener(view -> {
if (mPost.getPostType() == Post.VIDEO_TYPE) {
Intent intent = new Intent(mActivity, ViewVideoActivity.class);
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_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl());
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);

View File

@ -1868,10 +1868,26 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
Post post = getItem(position);
if (post != null) {
Intent intent = new Intent(mActivity, ViewVideoActivity.class);
if (post.isGfycat()) {
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT);
intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId());
if (post.isLoadGfyOrRedgifsVideoSuccess()) {
intent.setData(Uri.parse(post.getVideoUrl()));
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl());
}
} else if (post.isRedgifs()) {
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS);
intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId());
if (post.isLoadGfyOrRedgifsVideoSuccess()) {
intent.setData(Uri.parse(post.getVideoUrl()));
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl());
}
} else {
intent.setData(Uri.parse(post.getVideoUrl()));
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl());
intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, post.getSubredditName());
intent.putExtra(ViewVideoActivity.EXTRA_ID, post.getId());
}
intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, post.getTitle());
intent.putExtra(ViewVideoActivity.EXTRA_PROGRESS_SECONDS, helper.getLatestPlaybackInfo().getResumePosition());
intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, post.isNSFW());
@ -2081,10 +2097,18 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
if (post != null) {
if (post.getPostType() == Post.VIDEO_TYPE) {
Intent intent = new Intent(mActivity, ViewVideoActivity.class);
if (post.isGfycat()) {
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT);
intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId());
} else if (post.isRedgifs()) {
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS);
intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId());
} else {
intent.setData(Uri.parse(post.getVideoUrl()));
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl());
intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, post.getSubredditName());
intent.putExtra(ViewVideoActivity.EXTRA_ID, post.getId());
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl());
}
intent.putExtra(ViewVideoActivity.EXTRA_POST_TITLE, post.getTitle());
intent.putExtra(ViewVideoActivity.EXTRA_IS_NSFW, post.isNSFW());
mActivity.startActivity(intent);