1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // UNO 29 import com.sun.star.uno.UnoRuntime; 30 import com.sun.star.uno.XComponentContext; 31 import com.sun.star.uno.AnyConverter; 32 import com.sun.star.uno.IQueryInterface; 33 import com.sun.star.lang.XInitialization; 34 35 // media 36 import com.sun.star.media.*; 37 38 public class Manager implements com.sun.star.lang.XServiceInfo, 39 com.sun.star.lang.XTypeProvider, 40 com.sun.star.media.XManager 41 42 { 43 private com.sun.star.lang.XMultiServiceFactory maFactory; 44 45 // ------------------------------------------------------------------------- 46 47 public Manager( com.sun.star.lang.XMultiServiceFactory aFactory ) 48 { 49 maFactory = aFactory; 50 } 51 52 // ------------ 53 // - XManager - 54 // ------------ 55 56 public com.sun.star.media.XPlayer createPlayer( String aURL ) 57 { 58 javax.media.Player aPlayer = null; 59 60 try 61 { 62 aPlayer = javax.media.Manager.createRealizedPlayer( new java.net.URL( aURL ) ); 63 } 64 catch( java.net.MalformedURLException e ) 65 { 66 } 67 catch( java.io.IOException e ) 68 { 69 } 70 catch( javax.media.NoPlayerException e ) 71 { 72 } 73 catch( javax.media.CannotRealizeException e ) 74 { 75 } 76 catch( java.lang.Exception e ) 77 { 78 } 79 80 if( aPlayer != null ) 81 { 82 return new Player( maFactory, aPlayer, aURL ); 83 } 84 else 85 return null; 86 } 87 88 // ---------------- 89 // - XServiceInfo - 90 // ---------------- 91 92 private static final String s_implName = "com.sun.star.comp.media.Manager_Java"; 93 private static final String s_serviceName = "com.sun.star.media.Manager_Java"; 94 95 public synchronized String getImplementationName() 96 { 97 return s_implName; 98 } 99 100 // ------------------------------------------------------------------------- 101 102 public synchronized String [] getSupportedServiceNames() 103 { 104 return new String [] { s_serviceName }; 105 } 106 107 // ------------------------------------------------------------------------- 108 109 public synchronized boolean supportsService( String serviceName ) 110 { 111 return serviceName.equals( s_serviceName ); 112 } 113 114 // ----------------- 115 // - XTypeProvider - 116 // ----------------- 117 protected byte[] maImplementationId; 118 119 public com.sun.star.uno.Type[] getTypes() 120 { 121 com.sun.star.uno.Type[] retValue = new com.sun.star.uno.Type[ 3 ]; 122 123 retValue[ 0 ]= new com.sun.star.uno.Type( com.sun.star.lang.XServiceInfo.class ); 124 retValue[ 1 ]= new com.sun.star.uno.Type( com.sun.star.lang.XTypeProvider.class ); 125 retValue[ 2 ]= new com.sun.star.uno.Type( com.sun.star.media.XManager.class ); 126 127 return retValue; 128 } 129 130 // ------------------------------------------------------------------------- 131 132 synchronized public byte[] getImplementationId() 133 { 134 if( maImplementationId == null) 135 { 136 maImplementationId = new byte[ 16 ]; 137 138 int hash = hashCode(); 139 140 maImplementationId[ 0 ] = (byte)(hash & 0xff); 141 maImplementationId[ 1 ] = (byte)((hash >>> 8) & 0xff); 142 maImplementationId[ 2 ] = (byte)((hash >>> 16) & 0xff); 143 maImplementationId[ 3 ] = (byte)((hash >>>24) & 0xff); 144 } 145 146 return maImplementationId; 147 } 148 } 149