diff options
author | Alex Ning <chineseperson5@gmail.com> | 2019-09-10 08:41:54 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2019-09-10 08:41:54 +0000 |
commit | 354a215209d3181ec6d233164f457a1266f05afb (patch) | |
tree | 6a8a2238984a9e2a643b29742a43babc203e6d11 /app/src/main | |
parent | f4515514c10d2f653a638bcdef6bc7ba1ac494b0 (diff) | |
download | infinity-for-reddit-354a215209d3181ec6d233164f457a1266f05afb.tar infinity-for-reddit-354a215209d3181ec6d233164f457a1266f05afb.tar.gz infinity-for-reddit-354a215209d3181ec6d233164f457a1266f05afb.tar.bz2 infinity-for-reddit-354a215209d3181ec6d233164f457a1266f05afb.tar.lz infinity-for-reddit-354a215209d3181ec6d233164f457a1266f05afb.tar.xz infinity-for-reddit-354a215209d3181ec6d233164f457a1266f05afb.tar.zst infinity-for-reddit-354a215209d3181ec6d233164f457a1266f05afb.zip |
Load HLS video instead of Dash video to support older Android versions. Fixed app crashes on opening video or images on older Android versions.
Diffstat (limited to '')
11 files changed, 31 insertions, 39 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java index c20177b9..c4595c5e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java @@ -429,7 +429,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie Intent intent = new Intent(mActivity, ViewVideoActivity.class); intent.setData(gifVideoUri); intent.putExtra(ViewVideoActivity.TITLE_KEY, mPost.getTitle()); - intent.putExtra(ViewVideoActivity.IS_DASH_VIDEO_KEY, mPost.isDashVideo()); + intent.putExtra(ViewVideoActivity.IS_HLS_VIDEO_KEY, mPost.isHLSVideo()); intent.putExtra(ViewVideoActivity.IS_DOWNLOADABLE_KEY, mPost.isDownloadableGifOrVideo()); if(mPost.isDownloadableGifOrVideo()) { intent.putExtra(ViewVideoActivity.DOWNLOAD_URL_KEY, mPost.getGifOrVideoDownloadUrl()); @@ -447,7 +447,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie Intent intent = new Intent(mActivity, ViewVideoActivity.class); intent.setData(videoUri); intent.putExtra(ViewVideoActivity.TITLE_KEY, mPost.getTitle()); - intent.putExtra(ViewVideoActivity.IS_DASH_VIDEO_KEY, mPost.isDashVideo()); + intent.putExtra(ViewVideoActivity.IS_HLS_VIDEO_KEY, mPost.isHLSVideo()); intent.putExtra(ViewVideoActivity.IS_DOWNLOADABLE_KEY, mPost.isDownloadableGifOrVideo()); if(mPost.isDownloadableGifOrVideo()) { intent.putExtra(ViewVideoActivity.DOWNLOAD_URL_KEY, mPost.getGifOrVideoDownloadUrl()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java index 4346ccbe..269e4f41 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java @@ -34,7 +34,7 @@ public class JSONUtils { static final String URL_KEY = "url"; static final String MEDIA_KEY = "media"; static final String REDDIT_VIDEO_KEY = "reddit_video"; - static final String DASH_URL_KEY = "dash_url"; + static final String HLS_URL_KEY = "hls_url"; static final String IS_VIDEO_KEY = "is_video"; static final String CROSSPOST_PARENT_LIST = "crosspost_parent_list"; static final String REDDIT_VIDEO_PREVIEW_KEY = "reddit_video_preview"; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java index bbfe8d56..bf8334d6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java @@ -262,7 +262,7 @@ class ParsePost { //Video post JSONObject redditVideoObject = data.getJSONObject(JSONUtils.MEDIA_KEY).getJSONObject(JSONUtils.REDDIT_VIDEO_KEY); int postType = Post.VIDEO_TYPE; - String videoUrl = Html.fromHtml(redditVideoObject.getString(JSONUtils.DASH_URL_KEY)).toString(); + String videoUrl = Html.fromHtml(redditVideoObject.getString(JSONUtils.HLS_URL_KEY)).toString(); post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title, previewUrl, permalink, score, postType, voteType, gilded, flair, hidden, @@ -290,10 +290,10 @@ class ParsePost { post.setDownloadableGifOrVideo(true); post.setGifOrVideoDownloadUrl(gifDownloadUrl); } else if(data.getJSONObject(JSONUtils.PREVIEW_KEY).has(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY)) { - //Gif video post (Dash) + //Gif video post (HLS) int postType = Post.GIF_VIDEO_TYPE; String videoUrl = Html.fromHtml(data.getJSONObject(JSONUtils.PREVIEW_KEY) - .getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.DASH_URL_KEY)).toString(); + .getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.HLS_URL_KEY)).toString(); post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, title, previewUrl, permalink, score, postType, voteType, diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java index 8d9fd436..bf963745 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java @@ -47,7 +47,7 @@ class Post implements Parcelable { private boolean locked; private boolean saved; private boolean isCrosspost; - private boolean isDashVideo; + private boolean isHLSVideo; private boolean isDownloadableGifOrVideo; private String crosspostParentId; @@ -55,7 +55,7 @@ class Post implements Parcelable { String postTime, String title, String previewUrl, String permalink, int score, int postType, int voteType, int gilded, String flair, boolean hidden, boolean spoiler, boolean nsfw, boolean stickied, boolean archived, boolean locked, boolean saved, boolean isCrosspost, - boolean isDashVideo) { + boolean isHLSVideo) { this.id = id; this.fullName = fullName; this.subredditName = subredditName; @@ -79,7 +79,7 @@ class Post implements Parcelable { this.locked = locked; this.saved = saved; this.isCrosspost = isCrosspost; - this.isDashVideo = isDashVideo; + this.isHLSVideo = isHLSVideo; } Post(String id, String fullName, String subredditName, String subredditNamePrefixed, String author, @@ -172,7 +172,7 @@ class Post implements Parcelable { locked = in.readByte() != 0; saved = in.readByte() != 0; isCrosspost = in.readByte() != 0; - isDashVideo = in.readByte() != 0; + isHLSVideo = in.readByte() != 0; isDownloadableGifOrVideo = in.readByte() != 0; crosspostParentId = in.readString(); } @@ -354,8 +354,8 @@ class Post implements Parcelable { return 0; } - boolean isDashVideo() { - return isDashVideo; + boolean isHLSVideo() { + return isHLSVideo; } void setDownloadableGifOrVideo(boolean isDownloadableGifOrVideo) { @@ -431,7 +431,7 @@ class Post implements Parcelable { parcel.writeByte((byte) (locked ? 1 : 0)); parcel.writeByte((byte) (saved ? 1 : 0)); parcel.writeByte((byte) (isCrosspost ? 1 : 0)); - parcel.writeByte((byte) (isDashVideo ? 1 : 0)); + parcel.writeByte((byte) (isHLSVideo ? 1 : 0)); parcel.writeByte((byte) (isDownloadableGifOrVideo ? 1 : 0)); parcel.writeString(crosspostParentId); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java index fa2c097f..db11bb3b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java @@ -419,7 +419,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo Intent intent = new Intent(mContext, ViewVideoActivity.class); intent.setData(gifVideoUri); intent.putExtra(ViewVideoActivity.TITLE_KEY, title); - intent.putExtra(ViewVideoActivity.IS_DASH_VIDEO_KEY, post.isDashVideo()); + intent.putExtra(ViewVideoActivity.IS_HLS_VIDEO_KEY, post.isHLSVideo()); intent.putExtra(ViewVideoActivity.IS_DOWNLOADABLE_KEY, post.isDownloadableGifOrVideo()); if(post.isDownloadableGifOrVideo()) { intent.putExtra(ViewVideoActivity.DOWNLOAD_URL_KEY, post.getGifOrVideoDownloadUrl()); @@ -437,7 +437,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo Intent intent = new Intent(mContext, ViewVideoActivity.class); intent.setData(videoUri); intent.putExtra(ViewVideoActivity.TITLE_KEY, title); - intent.putExtra(ViewVideoActivity.IS_DASH_VIDEO_KEY, post.isDashVideo()); + intent.putExtra(ViewVideoActivity.IS_HLS_VIDEO_KEY, post.isHLSVideo()); intent.putExtra(ViewVideoActivity.IS_DOWNLOADABLE_KEY, post.isDownloadableGifOrVideo()); if(post.isDownloadableGifOrVideo()) { intent.putExtra(ViewVideoActivity.DOWNLOAD_URL_KEY, post.getGifOrVideoDownloadUrl()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewImageActivity.java index bf0e2f29..9ed2fe62 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewImageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewImageActivity.java @@ -95,7 +95,7 @@ public class ViewImageActivity extends AppCompatActivity { ActionBar actionBar = getSupportActionBar(); Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp); actionBar.setHomeAsUpIndicator(upArrow); - actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparentActionBarColor))); + actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor))); setTitle(""); Intent intent = getIntent(); @@ -113,7 +113,7 @@ public class ViewImageActivity extends AppCompatActivity { float pxHeight = getResources().getDisplayMetrics().heightPixels; int activityColorFrom = getResources().getColor(android.R.color.black); - int actionBarColorFrom = getResources().getColor(R.color.transparentActionBarColor); + int actionBarColorFrom = getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor); int actionBarElementColorFrom = getResources().getColor(android.R.color.white); int colorTo = getResources().getColor(android.R.color.transparent); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java index c3ed9951..bb471562 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java @@ -39,8 +39,8 @@ import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.SimpleExoPlayer; import com.google.android.exoplayer2.source.ExtractorMediaSource; import com.google.android.exoplayer2.source.dash.DashChunkSource; -import com.google.android.exoplayer2.source.dash.DashMediaSource; import com.google.android.exoplayer2.source.dash.DefaultDashChunkSource; +import com.google.android.exoplayer2.source.hls.HlsMediaSource; import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; import com.google.android.exoplayer2.trackselection.TrackSelection; @@ -59,7 +59,7 @@ public class ViewVideoActivity extends AppCompatActivity { private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0; static final String TITLE_KEY = "TK"; - static final String IS_DASH_VIDEO_KEY = "IDVK"; + static final String IS_HLS_VIDEO_KEY = "IHVK"; static final String IS_DOWNLOADABLE_KEY = "IDK"; static final String DOWNLOAD_URL_KEY = "DUK"; static final String SUBREDDIT_KEY = "SK"; @@ -76,7 +76,7 @@ public class ViewVideoActivity extends AppCompatActivity { private String mGifOrVideoFileName; private String mDownloadUrl; - private boolean mIsDashVideo; + private boolean mIsHLSVideo; private boolean wasPlaying; private boolean isDownloading = false; private float totalLengthY = 0.0f; @@ -92,10 +92,9 @@ public class ViewVideoActivity extends AppCompatActivity { ActionBar actionBar = getSupportActionBar(); Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp); actionBar.setHomeAsUpIndicator(upArrow); - actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparentActionBarColor))); + actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor))); setTitle(""); - if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT || getResources().getBoolean(R.bool.isTablet)) { //Set player controller bottom margin in order to display it above the navbar int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android"); @@ -112,7 +111,7 @@ public class ViewVideoActivity extends AppCompatActivity { Intent intent = getIntent(); mVideoUri = intent.getData(); - mIsDashVideo = intent.getExtras().getBoolean(IS_DASH_VIDEO_KEY); + mIsHLSVideo = intent.getExtras().getBoolean(IS_HLS_VIDEO_KEY); if(intent.getExtras().getBoolean(IS_DOWNLOADABLE_KEY)) { mGifOrVideoFileName = intent.getExtras().getString(SUBREDDIT_KEY).substring(2) @@ -123,7 +122,7 @@ public class ViewVideoActivity extends AppCompatActivity { final float pxHeight = getResources().getDisplayMetrics().heightPixels; int activityColorFrom = getResources().getColor(android.R.color.black); - int actionBarColorFrom = getResources().getColor(R.color.transparentActionBarColor); + int actionBarColorFrom = getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor); int actionBarElementColorFrom = getResources().getColor(android.R.color.white); int colorTo = getResources().getColor(android.R.color.transparent); @@ -286,7 +285,7 @@ public class ViewVideoActivity extends AppCompatActivity { }); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); - TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); + TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(this, trackSelector); videoPlayerView.setPlayer(player); @@ -295,9 +294,9 @@ public class ViewVideoActivity extends AppCompatActivity { Util.getUserAgent(this, "Infinity"), bandwidthMeter); // Prepare the player with the source. - if(mIsDashVideo) { + if(mIsHLSVideo) { DashChunkSource.Factory dashChunkSourceFactory = new DefaultDashChunkSource.Factory(dataSourceFactory); - player.prepare(new DashMediaSource(mVideoUri, dataSourceFactory, dashChunkSourceFactory, null, null)); + player.prepare(new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(mVideoUri)); } else { player.prepare(new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(mVideoUri)); } @@ -308,7 +307,7 @@ public class ViewVideoActivity extends AppCompatActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { - if(!mIsDashVideo) { + if(!mIsHLSVideo) { getMenuInflater().inflate(R.menu.view_video, menu); mMenu = menu; } diff --git a/app/src/main/res/layout/exo_playback_control_view.xml b/app/src/main/res/layout/exo_playback_control_view.xml index 93a801af..ed305e41 100644 --- a/app/src/main/res/layout/exo_playback_control_view.xml +++ b/app/src/main/res/layout/exo_playback_control_view.xml @@ -7,7 +7,7 @@ android:paddingStart="16dp" android:paddingEnd="16dp" android:paddingBottom="16dp" - android:background="@color/transparentActionBarColor" + android:background="@color/transparentActionBarAndExoPlayerControllerColor" android:orientation="vertical"> <LinearLayout diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml index 6f4c322a..b6930940 100644 --- a/app/src/main/res/values-night/colors.xml +++ b/app/src/main/res/values-night/colors.xml @@ -6,7 +6,7 @@ <color name="downvoted">#E91E63</color> - <color name="transparentActionBarColor">#88000000</color> + <color name="transparentActionBarAndExoPlayerControllerColor">#88000000</color> <color name="gold">#FFC107</color> diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 42b7bc1c..6c8a40b5 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -4,7 +4,7 @@ <color name="colorPrimaryDark">#0D47A1</color> <color name="colorAccent">#FF4081</color> - <color name="transparentActionBarColor">#88000000</color> + <color name="transparentActionBarAndExoPlayerControllerColor">#88000000</color> <color name="gold">#FFC107</color> diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index e4119c67..0b7ea5c2 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -28,7 +28,7 @@ </style> <style name="AppTheme.ActionBar.Transparent" parent="AppTheme"> - <item name="colorPrimary">@color/transparentActionBarColor</item> + <item name="android:windowBackground">@android:color/black</item> <item name="android:windowTranslucentStatus">true</item> <item name="android:windowTranslucentNavigation">true</item> </style> @@ -37,13 +37,6 @@ <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.DayNight" /> - <style name="Theme.AppCompat.Transparent" parent="AppTheme.ActionBar.Transparent"> - <item name="android:windowNoTitle">true</item> - <item name="android:windowBackground">@android:color/transparent</item> - <item name="android:colorBackgroundCacheHint">@null</item> - <item name="android:windowIsTranslucent">true</item> - </style> - <style name="CustomTabLayout" parent="Widget.Design.TabLayout"> <item name="tabIndicatorColor">@android:color/white</item> <item name="tabIndicatorHeight">3dp</item> |