15
15
*/
16
16
package androidx .media3 .exoplayer ;
17
17
18
+ import static androidx .media3 .common .util .Assertions .checkArgument ;
19
+
20
+ import androidx .annotation .FloatRange ;
18
21
import androidx .annotation .Nullable ;
19
22
import androidx .media3 .common .C ;
20
23
import androidx .media3 .common .C .TrackType ;
21
24
import androidx .media3 .common .util .UnstableApi ;
22
25
import com .google .common .collect .ImmutableSet ;
23
26
import com .google .errorprone .annotations .CanIgnoreReturnValue ;
27
+ import java .util .Objects ;
24
28
import java .util .Set ;
25
29
26
30
/**
@@ -42,6 +46,8 @@ public final class ScrubbingModeParameters {
42
46
*/
43
47
public static final class Builder {
44
48
private ImmutableSet <@ TrackType Integer > disabledTrackTypes ;
49
+ @ Nullable private Double fractionalSeekToleranceBefore ;
50
+ @ Nullable private Double fractionalSeekToleranceAfter ;
45
51
46
52
/** Creates an instance. */
47
53
public Builder () {
@@ -50,6 +56,8 @@ public Builder() {
50
56
51
57
private Builder (ScrubbingModeParameters scrubbingModeParameters ) {
52
58
this .disabledTrackTypes = scrubbingModeParameters .disabledTrackTypes ;
59
+ this .fractionalSeekToleranceBefore = scrubbingModeParameters .fractionalSeekToleranceBefore ;
60
+ this .fractionalSeekToleranceAfter = scrubbingModeParameters .fractionalSeekToleranceAfter ;
53
61
}
54
62
55
63
/**
@@ -69,6 +77,37 @@ public Builder setDisabledTrackTypes(Set<@TrackType Integer> disabledTrackTypes)
69
77
return this ;
70
78
}
71
79
80
+ /**
81
+ * Sets the fraction of the media duration to use for {@link SeekParameters#toleranceBeforeUs}
82
+ * and {@link SeekParameters#toleranceAfterUs} when scrubbing.
83
+ *
84
+ * Pass {@code null} for both values to use the {@linkplain ExoPlayer#getSeekParameters()
85
+ * player-level seek parameters} when scrubbing.
86
+ *
87
+ * Defaults to {code null} for both values, so all seeks are exact (this may change in a
88
+ * future release).
89
+ *
90
+ * See {@link ScrubbingModeParameters#fractionalSeekToleranceBefore} and {@link
91
+ * ScrubbingModeParameters#fractionalSeekToleranceAfter}.
92
+ *
93
+ * @param toleranceBefore The fraction of the media duration to use for {@link
94
+ * SeekParameters#toleranceBeforeUs}, or null to use the player-level seek parameters.
95
+ * @param toleranceAfter The fraction of the media duration to use for {@link
96
+ * SeekParameters#toleranceAfterUs}, or null to use the player-level seek parameters.
97
+ * @return This builder for convenience.
98
+ */
99
+ @ CanIgnoreReturnValue
100
+ public Builder setFractionalSeekTolerance (
101
+ @ Nullable @ FloatRange (from = 0 , to = 1 ) Double toleranceBefore ,
102
+ @ Nullable @ FloatRange (from = 0 , to = 1 ) Double toleranceAfter ) {
103
+ checkArgument ((toleranceBefore == null ) == (toleranceAfter == null ));
104
+ checkArgument (toleranceBefore == null || (toleranceBefore >= 0 && toleranceBefore <= 1 ));
105
+ checkArgument (toleranceAfter == null || (toleranceAfter >= 0 && toleranceAfter <= 1 ));
106
+ this .fractionalSeekToleranceBefore = toleranceBefore ;
107
+ this .fractionalSeekToleranceAfter = toleranceAfter ;
108
+ return this ;
109
+ }
110
+
72
111
/** Returns the built {@link ScrubbingModeParameters}. */
73
112
public ScrubbingModeParameters build () {
74
113
return new ScrubbingModeParameters (this );
@@ -78,8 +117,32 @@ public ScrubbingModeParameters build() {
78
117
/** Which track types will be disabled in scrubbing mode. */
79
118
public final ImmutableSet <@ TrackType Integer > disabledTrackTypes ;
80
119
120
+ /**
121
+ * The fraction of the media duration to use for {@link SeekParameters#toleranceBeforeUs} when
122
+ * scrubbing.
123
+ *
124
+ * If this is {@code null} or the media duration is not known then the {@linkplain
125
+ * ExoPlayer#getSeekParameters()} non-scrubbing seek parameters} are used.
126
+ */
127
+ @ Nullable
128
+ @ FloatRange (from = 0 , to = 1 )
129
+ public final Double fractionalSeekToleranceBefore ;
130
+
131
+ /**
132
+ * The fraction of the media duration to use for {@link SeekParameters#toleranceAfterUs} when
133
+ * scrubbing.
134
+ *
135
+ * If this is {@code null} or the media duration is not known then the {@linkplain
136
+ * ExoPlayer#getSeekParameters()} non-scrubbing seek parameters} are used.
137
+ */
138
+ @ Nullable
139
+ @ FloatRange (from = 0 , to = 1 )
140
+ public final Double fractionalSeekToleranceAfter ;
141
+
81
142
private ScrubbingModeParameters (Builder builder ) {
82
143
this .disabledTrackTypes = builder .disabledTrackTypes ;
144
+ this .fractionalSeekToleranceBefore = builder .fractionalSeekToleranceBefore ;
145
+ this .fractionalSeekToleranceAfter = builder .fractionalSeekToleranceAfter ;
83
146
}
84
147
85
148
/** Returns a {@link Builder} initialized with the values from this instance. */
@@ -93,11 +156,14 @@ public boolean equals(@Nullable Object o) {
93
156
return false ;
94
157
}
95
158
ScrubbingModeParameters that = (ScrubbingModeParameters ) o ;
96
- return disabledTrackTypes .equals (that .disabledTrackTypes );
159
+ return disabledTrackTypes .equals (that .disabledTrackTypes )
160
+ && Objects .equals (fractionalSeekToleranceBefore , that .fractionalSeekToleranceBefore )
161
+ && Objects .equals (fractionalSeekToleranceAfter , that .fractionalSeekToleranceAfter );
97
162
}
98
163
99
164
@ Override
100
165
public int hashCode () {
101
- return disabledTrackTypes .hashCode ();
166
+ return Objects .hash (
167
+ disabledTrackTypes , fractionalSeekToleranceBefore , fractionalSeekToleranceAfter );
102
168
}
103
169
}
0 commit comments