Accessing Microsoft Windows Media Server from Java

Java/J2EE COM Interoperability Products Page

This example demonstrates how to access Microsoft Windows Media Server from Java. J-Integra® for COM is a Java interoperability component that bridges Java and Microsoft Windows Media Server. It provides bi-directional access of Java objects and COM components.

// This example shows a pure Java client using the J-Integra® pure Java-COM 
// bridge to talk to the Windows Media Server COM components to display 
// events when clients access media files.  You can run this program on any 
// machine that supports a standard JVM. 
// 
// For information on J-Integra® and to download an evaluation copy please 
// see http://j-integra.intrinsyc.com/ 
// 
// Create a file called WindowsMediaServerExample.java containing this 
// Java code. 
// 
// Create a subdirectory called 'windowsmedia' under the directory containing 
// this Java program, then generate the pure Java proxy files used by 
// this program to access the Windows Media Server COM components by running 
// the 'com2java' tool from the J-Integra® 'bin' directory. Specify 
// "\Program Files\Windows Media Components\Server\nsunimgr.ocx" 
// as the type library and "windowsmedia" as the package name, and the 
// windowsmedia subdirectory you created above, as the output directory. 
// 
// Compile and run the program with the J-Integra® runtime jintegra.jar in your  
// CLASSPATH. Start a client running from your browser, by selecting a URL such 
// as "mms://localhost/sample.asf" 
// 
// Watch the events arrive in the java client. 
 
import windowsmedia.*; 
 
public class WindowsMediaServerExample { 
 
  public static void main(java.lang.String[] args) throws Exception { 
    try { 
      // No need to do this if running under Windows, and J-Integra® 'bin' directory is in 
      // your PATH. 
      // com.linar.jintegra.AuthInfo.setDefault("NTDOMAIN", "username", "password"); 
 
      // Start the container used to host the OCX Windows Media Player COM components. 
      // Specify the host name of the remote Windows machine as a parameter 
      // if not running locally. 
      NsoAdminControl adminControl = new NsoAdminControl(); 
 
      adminControl.connect("localhost"); 
 
      if (adminControl.getServerStatus() == NSOADM_SERVER_STATES.NSOADM_SERVER_RUNNING) { 
        System.out.println("Server is running"); 
      } else { 
        System.err.println("Server is NOT running"); 
        return; 
      } 
 
      adminControl.add_NsoEventsListener(new NsoEvents()); 
 
      while (true) { 
        // keep the client alive to receive events 
        Thread.sleep(10000000); 
      } 
 
    } finally { 
      // Release all remote objects that haven't already been garbage collected. 
      com.linar.jintegra.Cleaner.releaseAll(); 
    } 
  } 
} 
 
class NsoEvents 
  extends _NsoEventsAdapter { 
 
  public void onClientConnect(_NsoEventsOnClientConnectEvent theEvent) { 
    System.out.println("Client Connected from " + theEvent.getStrIpAddress()); 
  } 
 
  public void onClientDisconnect(_NsoEventsOnClientDisconnectEvent theEvent) { 
    System.out.println("Client Disconnected from " + theEvent.getStrIpAddress()); 
  } 
 
  public void onClientPlay(_NsoEventsOnClientPlayEvent theEvent) { 
    System.out.println("Client Playing " + theEvent.getStrFileName()); 
  } 
 
  public void onClientStop(_NsoEventsOnClientStopEvent theEvent) { 
    System.out.println("Client Stopped Playing " + theEvent.getStrFileName()); 
  } 
}