modules/media/src/main/java/com/sun/media/jfxmediaimpl/NativeMediaPlayer.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


 733                 eventQueue.offer(event);
 734             }
 735         }
 736 
 737         /**
 738          * Signals the thread to terminate.
 739          */
 740         public void terminateLoop() {
 741             stopped = true;
 742             // put an event to unblock eventQueue.take()
 743             try {
 744                 eventQueue.put(new PlayerEvent());
 745             } catch(InterruptedException ex) {}
 746         }
 747 
 748         private void sendFakeBufferProgressEvent() {
 749             // Send fake 100% buffer progress event for HLS or !http protcol
 750             String contentType = media.getLocator().getContentType();
 751             String protocol = media.getLocator().getProtocol();
 752             if ((contentType != null && (contentType.equals(MediaUtils.CONTENT_TYPE_M3U) || contentType.equals(MediaUtils.CONTENT_TYPE_M3U8)))
 753                     || (protocol != null && !protocol.equals("http"))) {
 754                 HandleBufferEvents(new BufferProgressEvent(getDuration(), 0, 1, 1));
 755             }
 756         }
 757     }
 758 
 759     /**
 760      * Internal function to get called when the native player is ready.
 761      */
 762     private synchronized void onNativeInit() {
 763         try {
 764             playerInit();
 765         } catch (MediaException me) {
 766             sendPlayerMediaErrorEvent(me.getMediaError().code());
 767         }
 768     }
 769 
 770     //**************************************************************************
 771     //***** MediaPlayer implementation
 772     //**************************************************************************
 773     //***** Listener (un)registration.


   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


 733                 eventQueue.offer(event);
 734             }
 735         }
 736 
 737         /**
 738          * Signals the thread to terminate.
 739          */
 740         public void terminateLoop() {
 741             stopped = true;
 742             // put an event to unblock eventQueue.take()
 743             try {
 744                 eventQueue.put(new PlayerEvent());
 745             } catch(InterruptedException ex) {}
 746         }
 747 
 748         private void sendFakeBufferProgressEvent() {
 749             // Send fake 100% buffer progress event for HLS or !http protcol
 750             String contentType = media.getLocator().getContentType();
 751             String protocol = media.getLocator().getProtocol();
 752             if ((contentType != null && (contentType.equals(MediaUtils.CONTENT_TYPE_M3U) || contentType.equals(MediaUtils.CONTENT_TYPE_M3U8)))
 753                     || (protocol != null && !protocol.equals("http") && !protocol.equals("https"))) {
 754                 HandleBufferEvents(new BufferProgressEvent(getDuration(), 0, 1, 1));
 755             }
 756         }
 757     }
 758 
 759     /**
 760      * Internal function to get called when the native player is ready.
 761      */
 762     private synchronized void onNativeInit() {
 763         try {
 764             playerInit();
 765         } catch (MediaException me) {
 766             sendPlayerMediaErrorEvent(me.getMediaError().code());
 767         }
 768     }
 769 
 770     //**************************************************************************
 771     //***** MediaPlayer implementation
 772     //**************************************************************************
 773     //***** Listener (un)registration.