1*e357d40eSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*e357d40eSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*e357d40eSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*e357d40eSAndrew Rist * distributed with this work for additional information 6*e357d40eSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*e357d40eSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*e357d40eSAndrew Rist * "License"); you may not use this file except in compliance 9*e357d40eSAndrew Rist * with the License. You may obtain a copy of the License at 10*e357d40eSAndrew Rist * 11*e357d40eSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*e357d40eSAndrew Rist * 13*e357d40eSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*e357d40eSAndrew Rist * software distributed under the License is distributed on an 15*e357d40eSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*e357d40eSAndrew Rist * KIND, either express or implied. See the License for the 17*e357d40eSAndrew Rist * specific language governing permissions and limitations 18*e357d40eSAndrew Rist * under the License. 19*e357d40eSAndrew Rist * 20*e357d40eSAndrew Rist *************************************************************/ 21*e357d40eSAndrew Rist 22*e357d40eSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // UNO 25cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 26cdf0e10cSrcweir import com.sun.star.uno.XComponentContext; 27cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 28cdf0e10cSrcweir import com.sun.star.uno.IQueryInterface; 29cdf0e10cSrcweir import com.sun.star.lang.XInitialization; 30cdf0e10cSrcweir 31cdf0e10cSrcweir // media 32cdf0e10cSrcweir import com.sun.star.media.*; 33cdf0e10cSrcweir 34cdf0e10cSrcweir public class Manager implements com.sun.star.lang.XServiceInfo, 35cdf0e10cSrcweir com.sun.star.lang.XTypeProvider, 36cdf0e10cSrcweir com.sun.star.media.XManager 37cdf0e10cSrcweir 38cdf0e10cSrcweir { 39cdf0e10cSrcweir private com.sun.star.lang.XMultiServiceFactory maFactory; 40cdf0e10cSrcweir 41cdf0e10cSrcweir // ------------------------------------------------------------------------- 42cdf0e10cSrcweir Manager( com.sun.star.lang.XMultiServiceFactory aFactory )43cdf0e10cSrcweir public Manager( com.sun.star.lang.XMultiServiceFactory aFactory ) 44cdf0e10cSrcweir { 45cdf0e10cSrcweir maFactory = aFactory; 46cdf0e10cSrcweir } 47cdf0e10cSrcweir 48cdf0e10cSrcweir // ------------ 49cdf0e10cSrcweir // - XManager - 50cdf0e10cSrcweir // ------------ 51cdf0e10cSrcweir createPlayer( String aURL )52cdf0e10cSrcweir public com.sun.star.media.XPlayer createPlayer( String aURL ) 53cdf0e10cSrcweir { 54cdf0e10cSrcweir javax.media.Player aPlayer = null; 55cdf0e10cSrcweir 56cdf0e10cSrcweir try 57cdf0e10cSrcweir { 58cdf0e10cSrcweir aPlayer = javax.media.Manager.createRealizedPlayer( new java.net.URL( aURL ) ); 59cdf0e10cSrcweir } 60cdf0e10cSrcweir catch( java.net.MalformedURLException e ) 61cdf0e10cSrcweir { 62cdf0e10cSrcweir } 63cdf0e10cSrcweir catch( java.io.IOException e ) 64cdf0e10cSrcweir { 65cdf0e10cSrcweir } 66cdf0e10cSrcweir catch( javax.media.NoPlayerException e ) 67cdf0e10cSrcweir { 68cdf0e10cSrcweir } 69cdf0e10cSrcweir catch( javax.media.CannotRealizeException e ) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir } 72cdf0e10cSrcweir catch( java.lang.Exception e ) 73cdf0e10cSrcweir { 74cdf0e10cSrcweir } 75cdf0e10cSrcweir 76cdf0e10cSrcweir if( aPlayer != null ) 77cdf0e10cSrcweir { 78cdf0e10cSrcweir return new Player( maFactory, aPlayer, aURL ); 79cdf0e10cSrcweir } 80cdf0e10cSrcweir else 81cdf0e10cSrcweir return null; 82cdf0e10cSrcweir } 83cdf0e10cSrcweir 84cdf0e10cSrcweir // ---------------- 85cdf0e10cSrcweir // - XServiceInfo - 86cdf0e10cSrcweir // ---------------- 87cdf0e10cSrcweir 88cdf0e10cSrcweir private static final String s_implName = "com.sun.star.comp.media.Manager_Java"; 89cdf0e10cSrcweir private static final String s_serviceName = "com.sun.star.media.Manager_Java"; 90cdf0e10cSrcweir getImplementationName()91cdf0e10cSrcweir public synchronized String getImplementationName() 92cdf0e10cSrcweir { 93cdf0e10cSrcweir return s_implName; 94cdf0e10cSrcweir } 95cdf0e10cSrcweir 96cdf0e10cSrcweir // ------------------------------------------------------------------------- 97cdf0e10cSrcweir getSupportedServiceNames()98cdf0e10cSrcweir public synchronized String [] getSupportedServiceNames() 99cdf0e10cSrcweir { 100cdf0e10cSrcweir return new String [] { s_serviceName }; 101cdf0e10cSrcweir } 102cdf0e10cSrcweir 103cdf0e10cSrcweir // ------------------------------------------------------------------------- 104cdf0e10cSrcweir supportsService( String serviceName )105cdf0e10cSrcweir public synchronized boolean supportsService( String serviceName ) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir return serviceName.equals( s_serviceName ); 108cdf0e10cSrcweir } 109cdf0e10cSrcweir 110cdf0e10cSrcweir // ----------------- 111cdf0e10cSrcweir // - XTypeProvider - 112cdf0e10cSrcweir // ----------------- 113cdf0e10cSrcweir protected byte[] maImplementationId; 114cdf0e10cSrcweir getTypes()115cdf0e10cSrcweir public com.sun.star.uno.Type[] getTypes() 116cdf0e10cSrcweir { 117cdf0e10cSrcweir com.sun.star.uno.Type[] retValue = new com.sun.star.uno.Type[ 3 ]; 118cdf0e10cSrcweir 119cdf0e10cSrcweir retValue[ 0 ]= new com.sun.star.uno.Type( com.sun.star.lang.XServiceInfo.class ); 120cdf0e10cSrcweir retValue[ 1 ]= new com.sun.star.uno.Type( com.sun.star.lang.XTypeProvider.class ); 121cdf0e10cSrcweir retValue[ 2 ]= new com.sun.star.uno.Type( com.sun.star.media.XManager.class ); 122cdf0e10cSrcweir 123cdf0e10cSrcweir return retValue; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir // ------------------------------------------------------------------------- 127cdf0e10cSrcweir getImplementationId()128cdf0e10cSrcweir synchronized public byte[] getImplementationId() 129cdf0e10cSrcweir { 130cdf0e10cSrcweir if( maImplementationId == null) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir maImplementationId = new byte[ 16 ]; 133cdf0e10cSrcweir 134cdf0e10cSrcweir int hash = hashCode(); 135cdf0e10cSrcweir 136cdf0e10cSrcweir maImplementationId[ 0 ] = (byte)(hash & 0xff); 137cdf0e10cSrcweir maImplementationId[ 1 ] = (byte)((hash >>> 8) & 0xff); 138cdf0e10cSrcweir maImplementationId[ 2 ] = (byte)((hash >>> 16) & 0xff); 139cdf0e10cSrcweir maImplementationId[ 3 ] = (byte)((hash >>>24) & 0xff); 140cdf0e10cSrcweir } 141cdf0e10cSrcweir 142cdf0e10cSrcweir return maImplementationId; 143cdf0e10cSrcweir } 144cdf0e10cSrcweir } 145