SponsorBlock: Added button to player that enables/disables segment skipping for the current video
This commit is contained in:
parent
8a1e474b6f
commit
9e66a8656b
7 changed files with 70 additions and 11 deletions
|
@ -205,6 +205,7 @@ public abstract class BasePlayer implements
|
|||
private Disposable stateLoader;
|
||||
|
||||
protected int currentState = STATE_PREFLIGHT;
|
||||
private boolean isBlockingSponsors;
|
||||
|
||||
public BasePlayer(@NonNull final Context context) {
|
||||
this.context = context;
|
||||
|
@ -236,6 +237,9 @@ public abstract class BasePlayer implements
|
|||
this.renderFactory = new DefaultRenderersFactory(context);
|
||||
|
||||
this.mPrefs = PreferenceManager.getDefaultSharedPreferences(App.getApp());
|
||||
|
||||
isBlockingSponsors = mPrefs.getBoolean(context.getString(R.string.sponsorblock_enable_key),
|
||||
false);
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
|
@ -691,6 +695,17 @@ public abstract class BasePlayer implements
|
|||
return simpleExoPlayer.getVolume() == 0;
|
||||
}
|
||||
|
||||
public void onBlockingSponsorsButtonClicked() {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "onBlockingSponsorsButtonClicked() called");
|
||||
}
|
||||
isBlockingSponsors = !isBlockingSponsors;
|
||||
}
|
||||
|
||||
public boolean isBlockingSponsors() {
|
||||
return isBlockingSponsors;
|
||||
}
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
// Progress Updates
|
||||
//////////////////////////////////////////////////////////////////////////*/
|
||||
|
@ -716,7 +731,9 @@ public abstract class BasePlayer implements
|
|||
simpleExoPlayer.getBufferedPercentage()
|
||||
);
|
||||
|
||||
if (mPrefs.getBoolean(context.getString(R.string.sponsorblock_enable_key), false)) {
|
||||
if (isBlockingSponsors
|
||||
&& mPrefs.getBoolean(
|
||||
context.getString(R.string.sponsorblock_enable_key), false)) {
|
||||
VideoSegment segment = getSkippableSegment(currentProgress);
|
||||
if (segment == null) {
|
||||
return;
|
||||
|
|
|
@ -163,6 +163,7 @@ public class VideoPlayerImpl extends VideoPlayer
|
|||
private ImageButton playerCloseButton;
|
||||
private ImageButton screenRotationButton;
|
||||
private ImageButton muteButton;
|
||||
private ImageButton blockSponsorsButton;
|
||||
|
||||
private ImageButton playPauseButton;
|
||||
private ImageButton playPreviousButton;
|
||||
|
@ -295,6 +296,7 @@ public class VideoPlayerImpl extends VideoPlayer
|
|||
this.screenRotationButton = view.findViewById(R.id.screenRotationButton);
|
||||
this.playerCloseButton = view.findViewById(R.id.playerCloseButton);
|
||||
this.muteButton = view.findViewById(R.id.switchMute);
|
||||
this.blockSponsorsButton = view.findViewById(R.id.switchSponsorBlocking);
|
||||
|
||||
this.playPauseButton = view.findViewById(R.id.playPauseButton);
|
||||
this.playPreviousButton = view.findViewById(R.id.playPreviousButton);
|
||||
|
@ -358,6 +360,7 @@ public class VideoPlayerImpl extends VideoPlayer
|
|||
playWithKodi.setVisibility(View.GONE);
|
||||
openInBrowser.setVisibility(View.GONE);
|
||||
muteButton.setVisibility(View.GONE);
|
||||
blockSponsorsButton.setVisibility(View.GONE);
|
||||
playerCloseButton.setVisibility(View.GONE);
|
||||
getTopControlsRoot().bringToFront();
|
||||
getTopControlsRoot().setClickable(false);
|
||||
|
@ -379,6 +382,11 @@ public class VideoPlayerImpl extends VideoPlayer
|
|||
showHideKodiButton();
|
||||
openInBrowser.setVisibility(View.VISIBLE);
|
||||
muteButton.setVisibility(View.VISIBLE);
|
||||
|
||||
boolean isSponsorBlockEnabled = mPrefs.getBoolean(
|
||||
context.getString(R.string.sponsorblock_enable_key), false);
|
||||
blockSponsorsButton.setVisibility(isSponsorBlockEnabled ? View.VISIBLE : View.GONE);
|
||||
|
||||
playerCloseButton.setVisibility(isFullscreen ? View.GONE : View.VISIBLE);
|
||||
// Top controls have a large minHeight which is allows to drag the player
|
||||
// down in fullscreen mode (just larger area to make easy to locate by finger)
|
||||
|
@ -393,6 +401,7 @@ public class VideoPlayerImpl extends VideoPlayer
|
|||
channelTextView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
setMuteButton(muteButton, isMuted());
|
||||
setBlockSponsorsButton(blockSponsorsButton, isBlockingSponsors());
|
||||
|
||||
animateRotation(moreOptionsButton, DEFAULT_CONTROLS_DURATION, 0);
|
||||
}
|
||||
|
@ -463,6 +472,7 @@ public class VideoPlayerImpl extends VideoPlayer
|
|||
openInBrowser.setOnClickListener(this);
|
||||
playerCloseButton.setOnClickListener(this);
|
||||
muteButton.setOnClickListener(this);
|
||||
blockSponsorsButton.setOnClickListener(this);
|
||||
|
||||
settingsContentObserver = new ContentObserver(new Handler()) {
|
||||
@Override
|
||||
|
@ -632,6 +642,12 @@ public class VideoPlayerImpl extends VideoPlayer
|
|||
setMuteButton(muteButton, isMuted());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockingSponsorsButtonClicked() {
|
||||
super.onBlockingSponsorsButtonClicked();
|
||||
setBlockSponsorsButton(blockSponsorsButton, isBlockingSponsors());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateProgress(final int currentProgress,
|
||||
final int duration, final int bufferPercent) {
|
||||
|
@ -798,6 +814,8 @@ public class VideoPlayerImpl extends VideoPlayer
|
|||
}
|
||||
} else if (v.getId() == muteButton.getId()) {
|
||||
onMuteUnmuteButtonClicked();
|
||||
} else if (v.getId() == blockSponsorsButton.getId()) {
|
||||
onBlockingSponsorsButtonClicked();
|
||||
} else if (v.getId() == playerCloseButton.getId()) {
|
||||
service.sendBroadcast(new Intent(VideoDetailFragment.ACTION_HIDE_MAIN_PLAYER));
|
||||
}
|
||||
|
@ -1568,6 +1586,13 @@ public class VideoPlayerImpl extends VideoPlayer
|
|||
? R.drawable.ic_volume_off_white_24dp : R.drawable.ic_volume_up_white_24dp));
|
||||
}
|
||||
|
||||
protected void setBlockSponsorsButton(final ImageButton button,
|
||||
final boolean isBlockingSponsors) {
|
||||
button.setImageDrawable(AppCompatResources.getDrawable(service, isBlockingSponsors
|
||||
? R.drawable.ic_sponsorblock_disable_white_24dp
|
||||
: R.drawable.ic_sponsorblock_enable_white_24dp));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if main player is attached to activity and activity inside multiWindow mode
|
||||
*/
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="95.99999dp"
|
||||
android:height="95.99999dp"
|
||||
android:tint="#FFFFFF"
|
||||
android:viewportWidth="25.399998"
|
||||
android:viewportHeight="25.399998">
|
||||
<path
|
||||
android:pathData="m10.1863,24.3334c-5.1983,-3.3663 -9.0751,-9.5941 -9.9752,-16.0242 -0.4424,-3.1609 -0.2227,-4.3389 0.9753,-5.2314 2.2404,-1.6689 7.4985,-3.0778 11.4861,-3.0778 4.291,0 9.8812,1.5959 11.7644,3.3586 0.8399,0.7862 0.963,1.0842 0.963,2.3319 0,4.6926 -1.9999,10.0269 -5.3513,14.2734 -1.2566,1.5923 -4.3624,4.2527 -5.8432,5.0052 -1.3827,0.7027 -2.1366,0.5835 -4.0192,-0.6357zM14.7012,23.5072c4.9811,-3.3429 8.4222,-8.8464 9.4522,-15.1172 0.6789,-4.1335 0.3933,-4.5717 -3.9902,-6.122 -4.7167,-1.6681 -9.9654,-1.7168 -14.6174,-0.1356 -4.5338,1.5411 -4.9266,2.0247 -4.4645,5.4954 0.5981,4.4917 2.2909,8.4406 5.0487,11.7778 1.9687,2.3822 5.5647,5.158 6.6909,5.1649 0.1613,0.001 1.0073,-0.4775 1.8802,-1.0633zM10.3328,22.1472c-4.8218,-3.7831 -7.9074,-9.4023 -8.2836,-15.0853l-0.1544,-2.3333 1.7,-0.8045c5.3961,-2.5533 12.4561,-2.5723 18.1578,-0.0488l1.7039,0.7541 -0.1575,2.3829c-0.1913,2.8952 -1.2564,6.3467 -2.7367,8.8694 -1.9541,3.3303 -6.3784,7.5343 -7.9285,7.5339 -0.3764,-0.0001 -1.4119,-0.5709 -2.301,-1.2685zM14.3279,13.8396c2.2843,-1.292 4.1155,-2.379 4.0693,-2.4155 -0.3589,-0.2834 -8.2933,-4.7752 -8.4351,-4.7752 -0.1001,0 -0.1821,2.1465 -0.1821,4.7699 0,2.6235 0.0888,4.7699 0.1975,4.7699 0.1086,0 2.0663,-1.0571 4.3507,-2.3491z"
|
||||
android:fillColor="#FF000000"/>
|
||||
</vector>
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,6 @@
|
|||
<vector android:height="24dp" android:viewportHeight="25.400005"
|
||||
android:viewportWidth="25.399996" android:width="23.999992dp" xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:tint="#FFFFFF">
|
||||
<path android:fillColor="#FF000000"
|
||||
android:pathData="m12.638,25.3999c-0.2786,-0.002 -0.6752,-0.0642 -0.8813,-0.1374 -0.2061,-0.0733 -0.6241,-0.283 -0.929,-0.4662 -0.3048,-0.1832 -1.0124,-0.675 -1.5724,-1.0929 -0.56,-0.4179 -1.4781,-1.1951 -2.0401,-1.727 -0.562,-0.532 -1.3809,-1.3936 -1.8197,-1.9146 -0.4388,-0.5211 -1.1538,-1.481 -1.5889,-2.1332 -0.4351,-0.6522 -1.0762,-1.7665 -1.4246,-2.4763 -0.3484,-0.7098 -0.7962,-1.7298 -0.9951,-2.2668 -0.1989,-0.537 -0.5112,-1.5622 -0.6941,-2.2782 -0.1829,-0.716 -0.411,-1.8368 -0.5071,-2.4905 -0.096,-0.6538 -0.179,-1.7904 -0.1843,-2.5258 -0.0085,-1.1718 0.0167,-1.3942 0.2041,-1.7977 0.1176,-0.2533 0.3864,-0.6322 0.5973,-0.8419 0.23,-0.2288 0.8413,-0.6047 1.5275,-0.9394 0.6292,-0.3068 1.5882,-0.7227 2.131,-0.9241 0.5428,-0.2014 1.4831,-0.4958 2.0896,-0.6542 0.6065,-0.1584 1.6624,-0.3876 2.3465,-0.5093 1.0646,-0.1895 1.6024,-0.2218 3.7315,-0.2242 1.9471,-0.002 2.7255,0.0363 3.5822,0.1772 0.602,0.0991 1.5611,0.2926 2.1314,0.4302 0.5702,0.1376 1.4798,0.4036 2.0213,0.5912 0.5415,0.1876 1.4533,0.5455 2.0264,0.7953 0.573,0.2498 1.3096,0.6265 1.6369,0.8371 0.3766,0.2423 0.7051,0.5555 0.8947,0.8531 0.1648,0.2586 0.3489,0.6492 0.4091,0.868 0.0701,0.2546 0.0877,0.879 0.0488,1.7349 -0.0334,0.7355 -0.1492,1.8721 -0.2574,2.5259 -0.1081,0.6537 -0.3076,1.6121 -0.4432,2.1296 -0.1356,0.5175 -0.409,1.409 -0.6075,1.9811 -0.1985,0.572 -0.666,1.6641 -1.039,2.4268 -0.373,0.7627 -1.0337,1.9218 -1.4683,2.5757 -0.4346,0.654 -1.1287,1.59 -1.5425,2.0801 -0.4138,0.4901 -1.1942,1.3167 -1.7342,1.8369 -0.54,0.5202 -1.3253,1.217 -1.7449,1.5485 -0.4197,0.3315 -1.1552,0.8598 -1.6346,1.174 -0.4793,0.3142 -1.0722,0.6314 -1.3175,0.7049 -0.2453,0.0735 -0.6739,0.1317 -0.9526,0.1293zM12.8415,24.3793c0.3751,-0.0216 0.6532,-0.1186 1.0448,-0.3643 0.2935,-0.1842 0.9367,-0.6314 1.4293,-0.9938 0.4926,-0.3624 1.2872,-1.0029 1.7659,-1.4233 0.4787,-0.4204 1.3008,-1.2626 1.8269,-1.8715 0.5261,-0.6089 1.3111,-1.6347 1.7444,-2.2796 0.4333,-0.6449 1.0927,-1.7857 1.4651,-2.5352 0.3725,-0.7495 0.884,-1.9826 1.1368,-2.7401 0.2527,-0.7575 0.5712,-1.9345 0.7076,-2.6155 0.1365,-0.681 0.2953,-1.671 0.353,-2.2 0.0577,-0.529 0.1039,-1.2868 0.1027,-1.6839 -0.001,-0.4851 -0.0621,-0.8534 -0.1849,-1.1223 -0.1005,-0.2202 -0.33,-0.5238 -0.5102,-0.6746 -0.1801,-0.1509 -0.5918,-0.4071 -0.9149,-0.5695 -0.3231,-0.1623 -1.0664,-0.4904 -1.6519,-0.7289 -0.5855,-0.2385 -1.5347,-0.5727 -2.1093,-0.7426 -0.5746,-0.1699 -1.6493,-0.4231 -2.3881,-0.5626 -1.0355,-0.1955 -1.7886,-0.2657 -3.2863,-0.3064 -1.2105,-0.0328 -2.3359,-0.008 -2.9852,0.0649 -0.5732,0.0647 -1.5894,0.2265 -2.2581,0.3597 -0.6687,0.1331 -1.7434,0.4145 -2.3882,0.6253 -0.6447,0.2108 -1.7388,0.6374 -2.4313,0.948 -0.6925,0.3106 -1.439,0.7181 -1.6589,0.9055 -0.2344,0.1998 -0.471,0.5261 -0.5717,0.7886 -0.1441,0.3756 -0.1611,0.6372 -0.1052,1.6212 0.0366,0.6453 0.1538,1.7025 0.2603,2.3493 0.1065,0.6468 0.3509,1.7453 0.5431,2.4412 0.1921,0.6959 0.5769,1.816 0.855,2.4893 0.2781,0.6733 0.776,1.7086 1.1065,2.3007 0.3305,0.5921 0.8504,1.4332 1.1553,1.869 0.3049,0.4358 0.815,1.1115 1.1334,1.5014 0.3184,0.39 0.9937,1.1218 1.5005,1.6264 0.5068,0.5045 1.3245,1.2375 1.8171,1.6288 0.4925,0.3913 1.2314,0.934 1.6418,1.2061 0.4105,0.2721 0.8806,0.5451 1.0448,0.6066 0.1642,0.0615 0.5285,0.0985 0.8096,0.0823zM12.7958,23.4902c-0.2922,0.0369 -0.4808,-0.0234 -0.9362,-0.2992 -0.3137,-0.19 -1.0072,-0.6723 -1.5411,-1.0718 -0.5339,-0.3995 -1.4454,-1.1944 -2.0255,-1.7665 -0.58,-0.5721 -1.3384,-1.3967 -1.6853,-1.8326 -0.3469,-0.4358 -0.932,-1.2515 -1.3002,-1.8125 -0.3682,-0.561 -0.9155,-1.5194 -1.2162,-2.1296 -0.3007,-0.6102 -0.7107,-1.5492 -0.9111,-2.0866 -0.2004,-0.5374 -0.494,-1.4957 -0.6524,-2.1296 -0.1584,-0.6339 -0.3563,-1.6206 -0.4397,-2.1927 -0.0834,-0.572 -0.1638,-1.5374 -0.1787,-2.1452 -0.0257,-1.0484 -0.0149,-1.1182 0.2116,-1.3593 0.1313,-0.1398 0.6463,-0.4507 1.1443,-0.6909 0.4981,-0.2402 1.3434,-0.5991 1.8785,-0.7977 0.5351,-0.1986 1.3823,-0.4701 1.8825,-0.6033 0.5003,-0.1333 1.473,-0.3417 2.1615,-0.4631 1.037,-0.1829 1.6277,-0.2213 3.441,-0.224 1.6543,-0.002 2.4565,0.0406 3.2837,0.1759 0.602,0.0985 1.5235,0.2861 2.0477,0.4168 0.5242,0.1308 1.4197,0.3989 1.9901,0.5958 0.5704,0.197 1.5334,0.5987 2.1401,0.8928 0.8994,0.4359 1.1369,0.5972 1.2865,0.8736 0.171,0.3162 0.1754,0.438 0.064,1.809 -0.0657,0.8085 -0.2324,2.0272 -0.3706,2.7082 -0.1382,0.681 -0.4471,1.8232 -0.6864,2.5383 -0.2393,0.7151 -0.6546,1.7625 -0.9229,2.3277 -0.2683,0.5652 -0.7472,1.4509 -1.0642,1.9681 -0.3171,0.5173 -0.88,1.3419 -1.2509,1.8325 -0.371,0.4906 -1.0432,1.2838 -1.4939,1.7626 -0.4507,0.4788 -1.2475,1.2263 -1.7706,1.6609 -0.5232,0.4347 -1.3491,1.0617 -1.8355,1.3932 -0.561,0.3825 -1.018,0.6198 -1.2502,0.6491zM9.9443,16.2914c0.0285,0 1.9203,-1.0732 4.2041,-2.385 2.2838,-1.3117 4.1841,-2.4154 4.2229,-2.4525 0.0388,-0.0371 -1.6365,-1.0477 -3.7231,-2.2457 -2.0865,-1.198 -4.0101,-2.3017 -4.2747,-2.4526l-0.4811,-0.2744v4.9051c0,2.6978 0.0233,4.9051 0.0518,4.9051z" android:strokeWidth="0.0992791"/>
|
||||
</vector>
|
|
@ -298,6 +298,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="37dp"
|
||||
android:padding="@dimen/player_main_buttons_padding"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:scaleType="fitXY"
|
||||
|
@ -306,6 +307,19 @@
|
|||
android:contentDescription="@string/mute"
|
||||
tools:ignore="RtlHardcoded" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageButton
|
||||
android:id="@+id/switchSponsorBlocking"
|
||||
android:layout_width="35dp"
|
||||
android:layout_height="35dp"
|
||||
android:padding="@dimen/player_main_buttons_padding"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:scaleType="fitXY"
|
||||
app:srcCompat="@drawable/ic_sponsorblock_disable_white_24dp"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:contentDescription="@string/sponsorblock_toggle_skipping"
|
||||
tools:ignore="RtlHardcoded" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -705,4 +705,5 @@
|
|||
<string name="sponsorblock_skip_interaction_message">Skipped interaction reminder segment</string>
|
||||
<string name="sponsorblock_skip_self_promo_message">Skipped unpaid/self promo segment</string>
|
||||
<string name="sponsorblock_skip_non_music_message">Skipped non-music segment</string>
|
||||
<string name="sponsorblock_toggle_skipping">Toggle skipping sponsors</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue