WMPMedia.java :  » Swing-Library » DJ-Project-0.9.9 » chrriis » dj » nativeswing » swtimpl » components » win32 » Java Open Source

Java Open Source » Swing Library » DJ Project 0.9.9 
DJ Project 0.9.9 » chrriis » dj » nativeswing » swtimpl » components » win32 » WMPMedia.java
/*
 * Christopher Deckers (chrriis@nextencia.net)
 * http://www.nextencia.net
 *
 * See the file "readme.txt" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */
package chrriis.dj.nativeswing.swtimpl.components.win32;

/**
 * A Media Player object responsible for media-related actions.
 * @author Christopher Deckers
 * @author Matt Brooke-Smith
 */
public class WMPMedia {

  private NativeWMediaPlayer nativeComponent;

  WMPMedia(JWMediaPlayer wMediaPlayer) {
    nativeComponent = (NativeWMediaPlayer)wMediaPlayer.getNativeComponent();
  }

  /**
   * Get the duration in milliseconds of the current media.
   * @return the duration in milliseconds, or -1 in case of failure.
   */
  public int getDuration() {
    try {
      return (int)Math.round((Double)nativeComponent.getOleProperty(new String[]{"currentMedia", "duration"}) * 1000);
    } catch(IllegalStateException e) {
      // Invalid UI thread is an illegal state
      throw e;
    } catch (Exception e) {
      return -1;
    }
  }


}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.