modules/media/src/main/java/javafx/scene/media/Media.java

Print this page




  70  * copy of the source media data to be used by all players, or it might require a
  71  * separate copy of the data for each player. The choice of implementation will
  72  * not however have any effect on player behavior at the interface level.</p>
  73  *
  74  * @see MediaPlayer
  75  * @see MediaException
  76  * @since JavaFX 2.0
  77  */
  78 public final class Media {
  79     /**
  80      * A property set to a MediaException value when an error occurs.
  81      * If <code>error</code> is non-<code>null</code>, then the media could not
  82      * be loaded and is not usable. If {@link #onErrorProperty onError} is non-<code>null</code>,
  83      * it will be invoked when the <code>error</code> property is set.
  84      *
  85      * @see MediaException
  86      */
  87     private ReadOnlyObjectWrapper<MediaException> error;
  88 
  89     private void setError(MediaException value) {

  90         errorPropertyImpl().set(value);
  91     }

  92 
  93     /**
  94      * Return any error encountered in the media.
  95      * @return a {@link MediaException} or <code>null</code> if there is no error.
  96      */
  97     public final MediaException getError() {
  98         return error == null ? null : error.get();
  99     }
 100 
 101     public ReadOnlyObjectProperty<MediaException> errorProperty() {
 102         return errorPropertyImpl().getReadOnlyProperty();
 103     }
 104 
 105     private ReadOnlyObjectWrapper<MediaException> errorPropertyImpl() {
 106         if (error == null) {
 107             error = new ReadOnlyObjectWrapper<MediaException>() {
 108 
 109                 @Override
 110                 protected void invalidated() {
 111                     if (getOnError() != null) {


 318      * mapping from a name to a point in time between the beginning and end of
 319      * the media.
 320      */
 321     private ObservableMap<String, Duration> markers = FXCollections.observableMap(new HashMap<String,Duration>());
 322 
 323     /**
 324      * Retrieve the markers defined on this <code>Media</code> instance. If
 325      * there are no markers the returned {@link ObservableMap} will be empty.
 326      * Programmatic markers may be added by inserting entries in the returned
 327      * <code>Map</code>.
 328      *
 329      * @return the markers defined on this media source.
 330      */
 331     public final ObservableMap<String, Duration> getMarkers() {
 332         return markers;
 333     }
 334 
 335     /**
 336      * Constructs a <code>Media</code> instance.  This is the only way to
 337      * specify the media source. The source must represent a valid <code>URI</code>
 338      * and is immutable. Only HTTP, FILE, and JAR <code>URL</code>s are supported. If the
 339      * provided URL is invalid then an exception will be thrown.  If an
 340      * asynchronous error occurs, the {@link #errorProperty error} property will be set. Listen
 341      * to this property to be notified of any such errors.
 342      *
 343      * <p>If the source uses a non-blocking protocol such as FILE, then any
 344      * problems which can be detected immediately will cause a <code>MediaException</code>
 345      * to be thrown. Such problems include the media being inaccessible or in an
 346      * unsupported format. If however a potentially blocking protocol such as
 347      * HTTP is used, then the connection will be initialized asynchronously so
 348      * that these sorts of errors will be signaled by setting the {@link #errorProperty error}
 349      * property.</p>
 350      *
 351      * <p>Constraints:
 352      * <ul>
 353      * <li>The supplied URI must conform to RFC-2396 as required by
 354      * <A href="https://docs.oracle.com/javase/8/docs/api/java/net/URI.html">java.net.URI</A>.</li>
 355      * <li>Only HTTP, FILE, and JAR URIs are supported.</li>
 356      * </ul>
 357      *
 358      * <p>See <A href="https://docs.oracle.com/javase/8/docs/api/java/net/URI.html">java.net.URI</A>
 359      * for more information about URI formatting in general.
 360      * JAR URL syntax is specified in <a href="https://docs.oracle.com/javase/8/docs/api/java/net/JarURLConnection.html">java.net.JarURLConnection</A>.
 361      *
 362      * @param source The URI of the source media.
 363      * @throws NullPointerException if the URI string is <code>null</code>.
 364      * @throws IllegalArgumentException if the URI string does not conform to RFC-2396
 365      * or, if appropriate, the Jar URL specification, or is in a non-compliant
 366      * form which cannot be modified to a compliant form.
 367      * @throws IllegalArgumentException if the URI string has a <code>null</code>
 368      * scheme.
 369      * @throws UnsupportedOperationException if the protocol specified for the
 370      * source is not supported.
 371      * @throws MediaException if the media source cannot be connected
 372      * (type {@link MediaException.Type#MEDIA_INACCESSIBLE}) or is not supported
 373      * (type {@link MediaException.Type#MEDIA_UNSUPPORTED}).
 374      */
 375     public Media(@NamedArg("source") String source) {




  70  * copy of the source media data to be used by all players, or it might require a
  71  * separate copy of the data for each player. The choice of implementation will
  72  * not however have any effect on player behavior at the interface level.</p>
  73  *
  74  * @see MediaPlayer
  75  * @see MediaException
  76  * @since JavaFX 2.0
  77  */
  78 public final class Media {
  79     /**
  80      * A property set to a MediaException value when an error occurs.
  81      * If <code>error</code> is non-<code>null</code>, then the media could not
  82      * be loaded and is not usable. If {@link #onErrorProperty onError} is non-<code>null</code>,
  83      * it will be invoked when the <code>error</code> property is set.
  84      *
  85      * @see MediaException
  86      */
  87     private ReadOnlyObjectWrapper<MediaException> error;
  88 
  89     private void setError(MediaException value) {
  90         if (getError() == null) {
  91             errorPropertyImpl().set(value);
  92         }
  93     }
  94 
  95     /**
  96      * Return any error encountered in the media.
  97      * @return a {@link MediaException} or <code>null</code> if there is no error.
  98      */
  99     public final MediaException getError() {
 100         return error == null ? null : error.get();
 101     }
 102 
 103     public ReadOnlyObjectProperty<MediaException> errorProperty() {
 104         return errorPropertyImpl().getReadOnlyProperty();
 105     }
 106 
 107     private ReadOnlyObjectWrapper<MediaException> errorPropertyImpl() {
 108         if (error == null) {
 109             error = new ReadOnlyObjectWrapper<MediaException>() {
 110 
 111                 @Override
 112                 protected void invalidated() {
 113                     if (getOnError() != null) {


 320      * mapping from a name to a point in time between the beginning and end of
 321      * the media.
 322      */
 323     private ObservableMap<String, Duration> markers = FXCollections.observableMap(new HashMap<String,Duration>());
 324 
 325     /**
 326      * Retrieve the markers defined on this <code>Media</code> instance. If
 327      * there are no markers the returned {@link ObservableMap} will be empty.
 328      * Programmatic markers may be added by inserting entries in the returned
 329      * <code>Map</code>.
 330      *
 331      * @return the markers defined on this media source.
 332      */
 333     public final ObservableMap<String, Duration> getMarkers() {
 334         return markers;
 335     }
 336 
 337     /**
 338      * Constructs a <code>Media</code> instance.  This is the only way to
 339      * specify the media source. The source must represent a valid <code>URI</code>
 340      * and is immutable. Only HTTP, HTTPS, FILE, and JAR <code>URL</code>s are supported. If the
 341      * provided URL is invalid then an exception will be thrown.  If an
 342      * asynchronous error occurs, the {@link #errorProperty error} property will be set. Listen
 343      * to this property to be notified of any such errors.
 344      *
 345      * <p>If the source uses a non-blocking protocol such as FILE, then any
 346      * problems which can be detected immediately will cause a <code>MediaException</code>
 347      * to be thrown. Such problems include the media being inaccessible or in an
 348      * unsupported format. If however a potentially blocking protocol such as
 349      * HTTP is used, then the connection will be initialized asynchronously so
 350      * that these sorts of errors will be signaled by setting the {@link #errorProperty error}
 351      * property.</p>
 352      *
 353      * <p>Constraints:
 354      * <ul>
 355      * <li>The supplied URI must conform to RFC-2396 as required by
 356      * <A href="https://docs.oracle.com/javase/8/docs/api/java/net/URI.html">java.net.URI</A>.</li>
 357      * <li>Only HTTP, HTTPS, FILE, and JAR URIs are supported.</li>
 358      * </ul>
 359      *
 360      * <p>See <A href="https://docs.oracle.com/javase/8/docs/api/java/net/URI.html">java.net.URI</A>
 361      * for more information about URI formatting in general.
 362      * JAR URL syntax is specified in <a href="https://docs.oracle.com/javase/8/docs/api/java/net/JarURLConnection.html">java.net.JarURLConnection</A>.
 363      *
 364      * @param source The URI of the source media.
 365      * @throws NullPointerException if the URI string is <code>null</code>.
 366      * @throws IllegalArgumentException if the URI string does not conform to RFC-2396
 367      * or, if appropriate, the Jar URL specification, or is in a non-compliant
 368      * form which cannot be modified to a compliant form.
 369      * @throws IllegalArgumentException if the URI string has a <code>null</code>
 370      * scheme.
 371      * @throws UnsupportedOperationException if the protocol specified for the
 372      * source is not supported.
 373      * @throws MediaException if the media source cannot be connected
 374      * (type {@link MediaException.Type#MEDIA_INACCESSIBLE}) or is not supported
 375      * (type {@link MediaException.Type#MEDIA_UNSUPPORTED}).
 376      */
 377     public Media(@NamedArg("source") String source) {