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

Print this page


   1 /*
   2  * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 509             }
 510         } catch (com.sun.media.jfxmedia.MediaException e) {
 511             throw MediaException.exceptionToMediaException(e);
 512         }
 513 
 514         // Register for the Player's event
 515         Platform.runLater(() -> {
 516             registerListeners();
 517         });
 518     }
 519 
 520     private class InitMediaPlayer implements Runnable {
 521 
 522         @Override
 523         public void run() {
 524             try {
 525                 init();
 526             } catch (com.sun.media.jfxmedia.MediaException e) {
 527                 handleError(MediaException.exceptionToMediaException(e));
 528             } catch (MediaException e) {




 529                 handleError(e);

 530             } catch (Exception e) {
 531                 handleError(new MediaException(MediaException.Type.UNKNOWN, e.getMessage()));
 532             }
 533         }
 534     }
 535 
 536     /**
 537      * Observable property set to a <code>MediaException</code> if an error occurs.
 538      */
 539     private ReadOnlyObjectWrapper<MediaException> error;
 540 
 541     private void setError(MediaException value) {
 542         if (getError() == null) {
 543             errorPropertyImpl().set(value);
 544         }
 545     }
 546 
 547     /**
 548      * Retrieve the value of the {@link #errorProperty error} property or <code>null</code>
 549      * if there is no error.


   1 /*
   2  * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 509             }
 510         } catch (com.sun.media.jfxmedia.MediaException e) {
 511             throw MediaException.exceptionToMediaException(e);
 512         }
 513 
 514         // Register for the Player's event
 515         Platform.runLater(() -> {
 516             registerListeners();
 517         });
 518     }
 519 
 520     private class InitMediaPlayer implements Runnable {
 521 
 522         @Override
 523         public void run() {
 524             try {
 525                 init();
 526             } catch (com.sun.media.jfxmedia.MediaException e) {
 527                 handleError(MediaException.exceptionToMediaException(e));
 528             } catch (MediaException e) {
 529                 // Check media object for error. If it is connection related, then Media object will have better error message
 530                 if (media.getError() != null) {
 531                     handleError(media.getError());
 532                 } else {
 533                     handleError(e);
 534                 }
 535             } catch (Exception e) {
 536                 handleError(new MediaException(MediaException.Type.UNKNOWN, e.getMessage()));
 537             }
 538         }
 539     }
 540 
 541     /**
 542      * Observable property set to a <code>MediaException</code> if an error occurs.
 543      */
 544     private ReadOnlyObjectWrapper<MediaException> error;
 545 
 546     private void setError(MediaException value) {
 547         if (getError() == null) {
 548             errorPropertyImpl().set(value);
 549         }
 550     }
 551 
 552     /**
 553      * Retrieve the value of the {@link #errorProperty error} property or <code>null</code>
 554      * if there is no error.