@@ -88,7 +88,8 @@ public Builder() {
8888 }
8989
9090 /**
91- * Set the identifier of the {@link AudioStream}.
91+ * Set the identifier of the {@link AudioStream} which uniquely identifies the stream,
92+ * e.g. for YouTube this would be the itag
9293 *
9394 * <p>
9495 * It <b>must not be null</b> and should be non empty.
@@ -108,14 +109,14 @@ public Builder setId(@Nonnull final String id) {
108109 }
109110
110111 /**
111- * Set the content of the {@link AudioStream}.
112- *
112+ * Set the content or the URL of the {@link AudioStream}, depending on whether isUrl is
113+ * true
113114 * <p>
114115 * It must not be null, and should be non empty.
115116 * </p>
116117 *
117118 * @param content the content of the {@link AudioStream}
118- * @param isUrl whether the content is a URL
119+ * @param isUrl whether content is the URL or the actual content of e.g. a DASH manifest
119120 * @return this {@link Builder} instance
120121 */
121122 public Builder setContent (@ Nonnull final String content ,
@@ -126,7 +127,7 @@ public Builder setContent(@Nonnull final String content,
126127 }
127128
128129 /**
129- * Set the {@link MediaFormat} used by the {@link AudioStream}.
130+ * Set the {@link MediaFormat} used by the {@link AudioStream}, which can be null
130131 *
131132 * <p>
132133 * It should be one of the audio {@link MediaFormat}s ({@link MediaFormat#M4A M4A},
@@ -278,16 +279,22 @@ public Builder setItagItem(@Nullable final ItagItem itagItem) {
278279 * Build an {@link AudioStream} using the builder's current values.
279280 *
280281 * <p>
281- * The identifier and the content (and so the {@code isUrl} boolean ) properties must have
282+ * The identifier and the content (and thus {@code isUrl}) properties must have
282283 * been set.
283284 * </p>
284285 *
285286 * @return a new {@link AudioStream} using the builder's current values
286- * @throws IllegalStateException if {@code id}, {@code content} (and so {@code isUrl}) or
287+ * @throws IllegalStateException if {@code id}, {@code content} (and thus {@code isUrl}) or
287288 * {@code deliveryMethod} have been not set, or have been set as {@code null}
288289 */
289290 @ Nonnull
290291 public AudioStream build () {
292+ validateBuild ();
293+
294+ return new AudioStream (this );
295+ }
296+
297+ void validateBuild () {
291298 if (id == null ) {
292299 throw new IllegalStateException (
293300 "The identifier of the audio stream has been not set or is null. If you "
@@ -305,64 +312,39 @@ public AudioStream build() {
305312 "The delivery method of the audio stream has been set as null, which is "
306313 + "not allowed. Pass a valid one instead with setDeliveryMethod." );
307314 }
308-
309- return new AudioStream (id , content , isUrl , mediaFormat , deliveryMethod , averageBitrate ,
310- manifestUrl , audioTrackId , audioTrackName , audioLocale , audioTrackType ,
311- itagItem );
312315 }
313316 }
314317
315318
316319 /**
317- * Create a new audio stream.
320+ * Create a new audio stream using the given {@link Builder} .
318321 *
319- * @param id the identifier which uniquely identifies the stream, e.g. for YouTube
320- * this would be the itag
321- * @param content the content or the URL of the stream, depending on whether isUrl is
322- * true
323- * @param isUrl whether content is the URL or the actual content of e.g. a DASH
324- * manifest
325- * @param format the {@link MediaFormat} used by the stream, which can be null
326- * @param deliveryMethod the {@link DeliveryMethod} of the stream
327- * @param averageBitrate the average bitrate of the stream (which can be unknown, see
328- * {@link #UNKNOWN_BITRATE})
329- * @param audioTrackId the id of the audio track
330- * @param audioTrackName the name of the audio track
331- * @param audioLocale the {@link Locale} of the audio stream, representing its language
332- * @param itagItem the {@link ItagItem} corresponding to the stream, which cannot be null
333- * @param manifestUrl the URL of the manifest this stream comes from (if applicable,
334- * otherwise null)
322+ * @param builder The {@link Builder} to use to create the audio stream
335323 */
336324 @ SuppressWarnings ("checkstyle:ParameterNumber" )
337- private AudioStream (@ Nonnull final String id ,
338- @ Nonnull final String content ,
339- final boolean isUrl ,
340- @ Nullable final MediaFormat format ,
341- @ Nonnull final DeliveryMethod deliveryMethod ,
342- final int averageBitrate ,
343- @ Nullable final String manifestUrl ,
344- @ Nullable final String audioTrackId ,
345- @ Nullable final String audioTrackName ,
346- @ Nullable final Locale audioLocale ,
347- @ Nullable final AudioTrackType audioTrackType ,
348- @ Nullable final ItagItem itagItem ) {
349- super (id , content , isUrl , format , deliveryMethod , manifestUrl );
350- if (itagItem != null ) {
351- this .itagItem = itagItem ;
352- this .itag = itagItem .id ;
353- this .quality = itagItem .getQuality ();
354- this .bitrate = itagItem .getBitrate ();
355- this .initStart = itagItem .getInitStart ();
356- this .initEnd = itagItem .getInitEnd ();
357- this .indexStart = itagItem .getIndexStart ();
358- this .indexEnd = itagItem .getIndexEnd ();
359- this .codec = itagItem .getCodec ();
325+ AudioStream (final Builder builder ) {
326+ super (builder .id ,
327+ builder .content ,
328+ builder .isUrl ,
329+ builder .mediaFormat ,
330+ builder .deliveryMethod ,
331+ builder .manifestUrl );
332+ if (builder .itagItem != null ) {
333+ this .itagItem = builder .itagItem ;
334+ this .itag = builder .itagItem .id ;
335+ this .quality = builder .itagItem .getQuality ();
336+ this .bitrate = builder .itagItem .getBitrate ();
337+ this .initStart = builder .itagItem .getInitStart ();
338+ this .initEnd = builder .itagItem .getInitEnd ();
339+ this .indexStart = builder .itagItem .getIndexStart ();
340+ this .indexEnd = builder .itagItem .getIndexEnd ();
341+ this .codec = builder .itagItem .getCodec ();
360342 }
361- this .averageBitrate = averageBitrate ;
362- this .audioTrackId = audioTrackId ;
363- this .audioTrackName = audioTrackName ;
364- this .audioLocale = audioLocale ;
365- this .audioTrackType = audioTrackType ;
343+ this .averageBitrate = builder . averageBitrate ;
344+ this .audioTrackId = builder . audioTrackId ;
345+ this .audioTrackName = builder . audioTrackName ;
346+ this .audioLocale = builder . audioLocale ;
347+ this .audioTrackType = builder . audioTrackType ;
366348 }
367349
368350 /**
0 commit comments