Ejemplo n.º 1
0
    @Override
    public void run() {
      Logger.debug("run()");
      try {
        hHook =
            USER32_INSTANCE.SetWindowsHookEx(
                WinUser.WH_MOUSE_LL,
                WindowsMouseHook.this,
                Kernel32.INSTANCE.GetModuleHandle(null),
                0);
        MSG msg = new MSG();
        while ((USER32_INSTANCE.GetMessage(msg, null, 0, 0)) != 0) {
          // This code is never reached
          USER32_INSTANCE.TranslateMessage(msg);
          USER32_INSTANCE.DispatchMessage(msg);
          if (getHook() == null) {
            break;
          }
        }
      } catch (Exception e) {
        Logger.error("Mouse hook failure", e);
      }

      Logger.debug("mouse hook runnable exits");
    }
Ejemplo n.º 2
0
 public synchronized void release() {
   Logger.debug("release()");
   HHOOK hook = getHook();
   if (hook != null) {
     USER32_INSTANCE.UnhookWindowsHookEx(hHook);
     hook = null;
     // TODO ordinarily I'd interrupt the thread to force it to exit if it's
     // blocked, but in this case a fatal VM failure would occur
     // hookThread.interrupt();
   }
   Logger.debug("released");
 }
Ejemplo n.º 3
0
 /**
  * Create a new mouse hook.
  *
  * @param relativeTo component to report mouse coordinates relative to
  */
 public WindowsMouseHook(Component relativeTo) {
   Logger.debug("WindowsMouseHook(relativeTo={})", relativeTo);
   if (!Platform.isWindows()) {
     throw new IllegalStateException("Windows only");
   }
   this.relativeTo = relativeTo;
 }
Ejemplo n.º 4
0
 /** Start the hook. */
 public void start() {
   Logger.debug("start()");
   if (hookThread != null) {
     throw new IllegalStateException("Mouse hook already installed");
   }
   hookThread = new MouseHookThread();
   hookThread.start();
 }
Ejemplo n.º 5
0
 /**
  * Get the VLC installation directory.
  *
  * <p>If vlc is installed correctly, this should not be needed.
  *
  * @return fully-qualified directory name, or <code>null</code> if the value could not be obtained
  */
 public static String getVlcInstallDir() {
   Logger.debug("getVlcInstallDir()");
   try {
     return Advapi32Util.registryGetStringValue(
         WinReg.HKEY_LOCAL_MACHINE, VLC_REGISTRY_KEY, VLC_INSTALL_DIR_KEY);
   } catch (Exception e) {
     Logger.warn("Failed to get VLC installation directory from the registry", e);
     return null;
   }
 }
Ejemplo n.º 6
0
 /** @param enable */
 @SuppressWarnings("unused")
 private void enableMousePointer(boolean enable) {
   Logger.debug("enableMousePointer(enable={})", enable);
   if (enable) {
     videoSurface.setCursor(null);
   } else {
     Image blankImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
     videoSurface.setCursor(
         Toolkit.getDefaultToolkit().createCustomCursor(blankImage, new Point(0, 0), ""));
   }
 }
Ejemplo n.º 7
0
 /** @param listener */
 public void removeMouseWheelListener(MouseWheelListener listener) {
   Logger.debug("removeMouseWheelListener(listener={})", listener);
   listenerList.remove(MouseWheelListener.class, listener);
 }
Ejemplo n.º 8
0
 /** @param listener */
 public void addMouseWheelListener(MouseWheelListener listener) {
   Logger.debug("addMouseWheelListener(listener={})", listener);
   listenerList.add(MouseWheelListener.class, listener);
 }
Ejemplo n.º 9
0
 @Override
 public void paused(MediaPlayer mediaPlayer) {
   Logger.debug("paused(mediaPlayer={})", mediaPlayer);
 }
Ejemplo n.º 10
0
 @Override
 public void keyTyped(KeyEvent e) {
   Logger.debug("keyTyped(e={})", e);
 }
Ejemplo n.º 11
0
 @Override
 public void mouseExited(MouseEvent e) {
   Logger.debug("mouseExited(e={})", e);
 }
Ejemplo n.º 12
0
 @Override
 public void mouseWheelMoved(MouseWheelEvent e) {
   Logger.debug("mouseWheelMoved(e={})", e);
 }
Ejemplo n.º 13
0
    @Override
    public void videoOutput(MediaPlayer mediaPlayer, int newCount) {
      Logger.debug("videoOutput(mediaPlayer={},newCount={})", mediaPlayer, newCount);
      if (newCount == 0) {
        return;
      }

      MediaDetails mediaDetails = mediaPlayer.getMediaDetails();
      Logger.info("mediaDetails={}", mediaDetails);

      MediaMeta mediaMeta = mediaPlayer.getMediaMeta();
      Logger.info("mediaMeta={}", mediaMeta);

      final Dimension dimension = mediaPlayer.getVideoDimension();
      Logger.debug("dimension={}", dimension);
      if (dimension != null) {
        SwingUtilities.invokeLater(
            new Runnable() {
              @Override
              public void run() {
                videoSurface.setSize(dimension);
                mainFrame.pack();
              }
            });
      }

      // You can set a logo like this if you like...
      File logoFile = new File("./etc/vlcj-logo.png");
      if (logoFile.exists()) {
        mediaPlayer.setLogoFile(logoFile.getAbsolutePath());
        mediaPlayer.setLogoOpacity(0.5f);
        mediaPlayer.setLogoLocation(10, 10);
        mediaPlayer.enableLogo(true);
      }

      // Demo the marquee
      mediaPlayer.setMarqueeText("vlcj java bindings for vlc");
      mediaPlayer.setMarqueeSize(40);
      mediaPlayer.setMarqueeOpacity(95);
      mediaPlayer.setMarqueeColour(Color.white);
      mediaPlayer.setMarqueeTimeout(5000);
      mediaPlayer.setMarqueeLocation(50, 120);
      mediaPlayer.enableMarquee(true);

      // Not quite sure how crop geometry is supposed to work...
      //
      // Assertions in libvlc code:
      //
      // top + height must be less than visible height
      // left + width must be less than visible width
      //
      // With DVD source material:
      //
      // Reported size is 1024x576 - this is what libvlc reports when you call
      // get video size
      //
      // mpeg size is 720x576 - this is what is reported in the native log
      //
      // The crop geometry relates to the mpeg size, not the size reported
      // through the API
      //
      // For 720x576, attempting to set geometry to anything bigger than
      // 719x575 results in the assertion failures above (seems like it should
      // allow 720x576) to me

      // mediaPlayer.setCropGeometry("4:3");
    }
Ejemplo n.º 14
0
 @Override
 public void mediaMetaChanged(MediaPlayer mediaPlayer, int metaType) {
   Logger.debug("mediaMetaChanged(mediaPlayer={},metaType={})", mediaPlayer, metaType);
 }
Ejemplo n.º 15
0
 @Override
 public void mediaChanged(MediaPlayer mediaPlayer, libvlc_media_t media, String mrl) {
   Logger.debug("mediaChanged(mediaPlayer={},media={},mrl={})", mediaPlayer, media, mrl);
 }
Ejemplo n.º 16
0
 @Override
 public void playing(MediaPlayer mediaPlayer) {
   Logger.debug("playing(mediaPlayer={})", mediaPlayer);
   MediaDetails mediaDetails = mediaPlayer.getMediaDetails();
   Logger.info("mediaDetails={}", mediaDetails);
 }
Ejemplo n.º 17
0
 @Override
 public void mediaParsedChanged(MediaPlayer mediaPlayer, int newStatus) {
   Logger.debug("mediaParsedChanged(mediaPlayer={},newStatus={})", mediaPlayer, newStatus);
 }
Ejemplo n.º 18
0
 @Override
 public void mediaDurationChanged(MediaPlayer mediaPlayer, long newDuration) {
   Logger.debug("mediaDurationChanged(mediaPlayer={},newDuration={})", mediaPlayer, newDuration);
 }
Ejemplo n.º 19
0
 @Override
 public void mediaSubItemAdded(MediaPlayer mediaPlayer, libvlc_media_t subItem) {
   Logger.debug("mediaSubItemAdded(mediaPlayer={},subItem={})", mediaPlayer, subItem);
 }
Ejemplo n.º 20
0
 @Override
 public void error(MediaPlayer mediaPlayer) {
   Logger.debug("error(mediaPlayer={})", mediaPlayer);
 }
Ejemplo n.º 21
0
 @Override
 public void finished(MediaPlayer mediaPlayer) {
   Logger.debug("finished(mediaPlayer={})", mediaPlayer);
 }
Ejemplo n.º 22
0
 @Override
 public void mediaFreed(MediaPlayer mediaPlayer) {
   Logger.debug("mediaFreed(mediaPlayer={})", mediaPlayer);
 }
Ejemplo n.º 23
0
 @Override
 public void stopped(MediaPlayer mediaPlayer) {
   Logger.debug("stopped(mediaPlayer={})", mediaPlayer);
 }
Ejemplo n.º 24
0
 @Override
 public void mediaStateChanged(MediaPlayer mediaPlayer, int newState) {
   Logger.debug("mediaStateChanged(mediaPlayer={},newState={})", mediaPlayer, newState);
 }
Ejemplo n.º 25
0
  public TestPlayer(String[] args) {
    if (RuntimeUtil.isWindows()) {
      // If running on Windows and you want the mouse/keyboard event hack...
      videoSurface = new WindowsCanvas();
    } else {
      videoSurface = new Canvas();
    }

    Logger.debug("videoSurface={}", videoSurface);

    videoSurface.setBackground(Color.black);
    videoSurface.setSize(800, 600); // Only for initial layout

    // Since we're mixing lightweight Swing components and heavyweight AWT
    // components this is probably a good idea
    JPopupMenu.setDefaultLightWeightPopupEnabled(false);

    TestPlayerMouseListener mouseListener = new TestPlayerMouseListener();
    videoSurface.addMouseListener(mouseListener);
    videoSurface.addMouseMotionListener(mouseListener);
    videoSurface.addMouseWheelListener(mouseListener);
    videoSurface.addKeyListener(new TestPlayerKeyListener());

    List<String> vlcArgs = new ArrayList<String>();

    vlcArgs.add("--no-plugins-cache");
    vlcArgs.add("--no-video-title-show");
    vlcArgs.add("--no-snapshot-preview");
    vlcArgs.add("--quiet");
    vlcArgs.add("--quiet-synchro");
    vlcArgs.add("--intf");
    vlcArgs.add("dummy");

    // Special case to help out users on Windows (supposedly this is not actually needed)...
    // if(RuntimeUtil.isWindows()) {
    // vlcArgs.add("--plugin-path=" + WindowsRuntimeUtil.getVlcInstallDir() + "\\plugins");
    // }
    // else {
    // vlcArgs.add("--plugin-path=/home/linux/vlc/lib");
    // }

    // vlcArgs.add("--plugin-path=" + System.getProperty("user.home") + "/.vlcj");

    Logger.debug("vlcArgs={}", vlcArgs);

    mainFrame = new JFrame("VLCJ Test Player");
    mainFrame.setIconImage(
        new ImageIcon(getClass().getResource("/icons/vlcj-logo.png")).getImage());

    FullScreenStrategy fullScreenStrategy = new DefaultFullScreenStrategy(mainFrame);

    mediaPlayerFactory = new MediaPlayerFactory(vlcArgs.toArray(new String[vlcArgs.size()]));
    mediaPlayerFactory.setUserAgent("vlcj test player");

    List<AudioOutput> audioOutputs = mediaPlayerFactory.getAudioOutputs();
    Logger.debug("audioOutputs={}", audioOutputs);

    mediaPlayer = mediaPlayerFactory.newEmbeddedMediaPlayer(fullScreenStrategy);
    mediaPlayer.setVideoSurface(mediaPlayerFactory.newVideoSurface(videoSurface));
    mediaPlayer.setPlaySubItems(true);

    mediaPlayer.setEnableKeyInputHandling(false);
    mediaPlayer.setEnableMouseInputHandling(false);

    controlsPanel = new PlayerControlsPanel(mediaPlayer);
    videoAdjustPanel = new PlayerVideoAdjustPanel(mediaPlayer);

    mainFrame.setLayout(new BorderLayout());
    mainFrame.setBackground(Color.black);
    mainFrame.add(videoSurface, BorderLayout.CENTER);
    mainFrame.add(controlsPanel, BorderLayout.SOUTH);
    mainFrame.add(videoAdjustPanel, BorderLayout.EAST);
    mainFrame.setJMenuBar(buildMenuBar());
    mainFrame.pack();
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mainFrame.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent evt) {
            Logger.debug("windowClosing(evt={})", evt);

            if (videoSurface instanceof WindowsCanvas) {
              ((WindowsCanvas) videoSurface).release();
            }

            if (mediaPlayer != null) {
              mediaPlayer.release();
              mediaPlayer = null;
            }

            if (mediaPlayerFactory != null) {
              mediaPlayerFactory.release();
              mediaPlayerFactory = null;
            }
          }
        });

    // Global AWT key handler, you're better off using Swing's InputMap and
    // ActionMap with a JFrame - that would solve all sorts of focus issues too
    Toolkit.getDefaultToolkit()
        .addAWTEventListener(
            new AWTEventListener() {
              @Override
              public void eventDispatched(AWTEvent event) {
                if (event instanceof KeyEvent) {
                  KeyEvent keyEvent = (KeyEvent) event;
                  if (keyEvent.getID() == KeyEvent.KEY_PRESSED) {
                    if (keyEvent.getKeyCode() == KeyEvent.VK_F12) {
                      controlsPanel.setVisible(!controlsPanel.isVisible());
                      videoAdjustPanel.setVisible(!videoAdjustPanel.isVisible());
                      mainFrame.getJMenuBar().setVisible(!mainFrame.getJMenuBar().isVisible());
                      mainFrame.invalidate();
                      mainFrame.validate();
                    } else if (keyEvent.getKeyCode() == KeyEvent.VK_A) {
                      mediaPlayer.setAudioDelay(mediaPlayer.getAudioDelay() - 50000);
                    } else if (keyEvent.getKeyCode() == KeyEvent.VK_S) {
                      mediaPlayer.setAudioDelay(mediaPlayer.getAudioDelay() + 50000);
                    }
                    // else if(keyEvent.getKeyCode() == KeyEvent.VK_N) {
                    // mediaPlayer.nextFrame();
                    // }
                    else if (keyEvent.getKeyCode() == KeyEvent.VK_1) {
                      mediaPlayer.setTime(60000 * 1);
                    } else if (keyEvent.getKeyCode() == KeyEvent.VK_2) {
                      mediaPlayer.setTime(60000 * 2);
                    } else if (keyEvent.getKeyCode() == KeyEvent.VK_3) {
                      mediaPlayer.setTime(60000 * 3);
                    } else if (keyEvent.getKeyCode() == KeyEvent.VK_4) {
                      mediaPlayer.setTime(60000 * 4);
                    } else if (keyEvent.getKeyCode() == KeyEvent.VK_5) {
                      mediaPlayer.setTime(60000 * 5);
                    } else if (keyEvent.getKeyCode() == KeyEvent.VK_6) {
                      mediaPlayer.setTime(60000 * 6);
                    } else if (keyEvent.getKeyCode() == KeyEvent.VK_7) {
                      mediaPlayer.setTime(60000 * 7);
                    } else if (keyEvent.getKeyCode() == KeyEvent.VK_8) {
                      mediaPlayer.setTime(60000 * 8);
                    } else if (keyEvent.getKeyCode() == KeyEvent.VK_9) {
                      mediaPlayer.setTime(60000 * 9);
                    }
                  }
                }
              }
            },
            AWTEvent.KEY_EVENT_MASK);

    mainFrame.setVisible(true);

    mediaPlayer.addMediaPlayerEventListener(new TestPlayerMediaPlayerEventListener());

    // Won't work with OpenJDK or JDK1.7, requires a Sun/Oracle JVM (currently)
    boolean transparentWindowsSupport = true;
    try {
      Class.forName("com.sun.awt.AWTUtilities");
    } catch (Exception e) {
      transparentWindowsSupport = false;
    }

    Logger.debug("transparentWindowsSupport={}", transparentWindowsSupport);

    if (transparentWindowsSupport) {
      final Window test =
          new Window(null, WindowUtils.getAlphaCompatibleGraphicsConfiguration()) {
            private static final long serialVersionUID = 1L;

            @Override
            public void paint(Graphics g) {
              Graphics2D g2 = (Graphics2D) g;

              g2.setRenderingHint(
                  RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
              g2.setRenderingHint(
                  RenderingHints.KEY_TEXT_ANTIALIASING,
                  RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);

              g.setColor(Color.white);
              g.fillRoundRect(100, 150, 100, 100, 32, 32);

              g.setFont(new Font("Sans", Font.BOLD, 32));
              g.drawString("Heavyweight overlay test", 100, 300);
            }
          };

      AWTUtilities.setWindowOpaque(test, false); // Doesn't work in full-screen exclusive
      // mode, you would have to use 'simulated'
      // full-screen - requires Sun/Oracle JDK
      test.setBackground(new Color(0, 0, 0, 0)); // This is what you do in JDK7

      // mediaPlayer.setOverlay(test);
      // mediaPlayer.enableOverlay(true);
    }

    // This might be useful
    // enableMousePointer(false);
  }