public GstMediaPlayer(UnsignedIntegerFourBytes instanceId, LastChange avTransportLastChange, LastChange renderingControlLastChange) { super(); this.instanceId = instanceId; this.avTransportLastChange = avTransportLastChange; this.renderingControlLastChange = renderingControlLastChange; try { // Disconnect the old bus listener /* TODO: That doesn't work for some reason... getPipeline().getBus().disconnect( (Bus.STATE_CHANGED) Reflections.getField(getClass(), "stateChanged").get(this) ); */ // Connect a fixed bus state listener getPipeline().getBus().connect(busStateChanged); // Connect a bus tag listener getPipeline().getBus().connect(busTag); } catch (Exception ex) { throw new RuntimeException(ex); } addMediaListener(new GstMediaListener()); setVideoSink(videoComponent.getElement()); }
public void run() { frame = new JFrame("DecodeBin Player"); videoComponent = new VideoComponent(); videoComponent.setPreferredSize(new Dimension(640, 480)); frame.add(videoComponent, BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); // Wait until a video pad is linked to make it visible frame.setVisible(false); pipe.add(videoComponent.getElement()); pipe.play(); } });
setLayout(null); add(renderComponent); renderComponent.addMouseMotionListener(mouseListener); renderComponent.addKeyListener(keyListener); addKeyListener(keyListener); addComponentListener(componentAdapter); renderComponent.setBounds(getBounds()); setOpaque(true); setBackground(Color.BLACK);
@Override protected void paintComponent(Graphics g) { if (isOpaque()) { Graphics2D g2d = (Graphics2D) g.create(); g2d.setColor(getBackground()); if (alpha < 1.0f) { g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); } g2d.fillRect(0, 0, getWidth(), getHeight()); g2d.dispose(); } } private class RenderComponent extends javax.swing.JComponent {
public void run() { // // A VideoComponent displays video in a lightweight swing component // VideoComponent videoComponent = new VideoComponent(); // Add the video component as the playbin video output playbin.setVideoSink(videoComponent.getElement()); // Start the pipeline playing playbin.play(); // // Initialise the top-level frame and add the video component // JFrame frame = new JFrame("VideoPlayer"); frame.getContentPane().add(videoComponent, BorderLayout.CENTER); frame.setPreferredSize(new Dimension(640, 480)); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } });
/** * Renders to a volatile image, and then paints that to the screen. * This helps with scaling performance on accelerated surfaces (e.g. OpenGL) * * @param g the graphics to paint the image to * @param x the left coordinate to start painting at. * @param y the top coordinate to start painting at. * @param w the width of the paint area * @param h the height of the paint area */ private void volatileRender(Graphics g, int x, int y, int w, int h) { do { if (updatePending || volatileImage == null || volatileImage.validate(getGraphicsConfiguration()) != VolatileImage.IMAGE_OK) { bufferLock.lock(); try { updatePending = false; renderVolatileImage(currentImage); } finally { bufferLock.unlock(); } } g.drawImage(volatileImage, x, y, w, h, null); } while (volatileImage.contentsLost()); }
@Override public void keyPressed(KeyEvent evt) { for (KeyListener l : videoComponent.getKeyListeners()) { l.keyPressed(evt); } }
private void renderVolatileImage(BufferedImage bufferedImage) { do { int w = bufferedImage.getWidth(), h = bufferedImage.getHeight(); GraphicsConfiguration gc = getGraphicsConfiguration(); if (volatileImage == null || volatileImage.getWidth() != w || volatileImage.getHeight() != h || volatileImage.validate(gc) == VolatileImage.IMAGE_INCOMPATIBLE) { if (volatileImage != null) { volatileImage.flush(); } volatileImage = gc.createCompatibleVolatileImage(w, h); volatileImage.setAccelerationPriority(1.0f); } // // Now paint the BufferedImage into the accelerated image // Graphics2D g = volatileImage.createGraphics(); g.drawImage(bufferedImage, 0, 0, null); g.dispose(); } while (volatileImage.contentsLost()); }
public void run() { // Create the video component and link it in VideoComponent videoComponent = new VideoComponent(); Element videosink = videoComponent.getElement(); pipe.addMany(videosrc, videofilter, videosink); Element.linkMany(videosrc, videofilter, videosink); // Now create a JFrame to display the video output JFrame frame = new JFrame("Swing Video Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(videoComponent, BorderLayout.CENTER); videoComponent.setPreferredSize(new Dimension(720, 576)); frame.pack(); frame.setVisible(true); // Start the pipeline processing pipe.play(); } });
public VideoPlayer(MediaPlayer player) { mediaPlayer = player; videoComponent = new VideoComponent(); mediaPlayer.setVideoSink(videoComponent.getElement()); setLayout(new BorderLayout()); add(videoComponent, BorderLayout.CENTER);
@Override public void keyReleased(KeyEvent evt) { for (KeyListener l : videoComponent.getKeyListeners()) { l.keyReleased(evt); } } });
public void run() { // Create the video component and link it in VideoComponent videoComponent = new VideoComponent(); System.out.println(PREFIX + "VideoComponent created successfully"); System.out.flush(); Element videosink = videoComponent.getElement(); pipe.addMany(videosrc, videofilter, videosink); Element.linkMany(videosrc, videofilter, videosink); // Now create a JFrame to display the video output JFrame frame = new JFrame("Swing Video Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(videoComponent, BorderLayout.CENTER); videoComponent.setPreferredSize(new Dimension(width, height)); frame.pack(); frame.setVisible(true); // Start the pipeline processing pipe.play(); System.out.println(PREFIX + "pipeline set to PLAYING state"); System.out.flush(); } });
public void padAdded(Element element, Pad pad) { /* only link once */ if (pad.isLinked()) { return; } /* check media type */ Caps caps = pad.getCaps(); Structure struct = caps.getStructure(0); if (struct.getName().startsWith("audio/")) { System.out.println("Linking audio pad: " + struct.getName()); pad.link(audioBin.getStaticPad("sink")); } else if (struct.getName().startsWith("video/")) { System.out.println("Linking video pad: " + struct.getName()); pad.link(videoComponent.getElement().getStaticPad("sink")); // Make the video frame visible SwingUtilities.invokeLater(new Runnable() { public void run() { frame.setVisible(true); } }); } else { System.out.println("Unknown pad [" + struct.getName() + "]"); } } });
public void run() { System.out.println("Creating GstVideoComponent"); final VideoComponent videoComponent = new VideoComponent(); videoComponent.setPreferredSize(new Dimension(width, height)); JFrame frame = new JFrame("Swing Video Test"); frame.add(videoComponent, BorderLayout.CENTER); Element videosink = videoComponent.getElement();
public void run() { JFrame frame = new JFrame("FakeSrcTest"); VideoComponent panel = new VideoComponent(); panel.setPreferredSize(new Dimension(width, height)); frame.add(panel, BorderLayout.CENTER); Element videosink = panel.getElement(); pipeline.addMany(appsrc, srcfilter, videorate, ratefilter, videosink); Element.linkMany(appsrc, srcfilter, videorate, ratefilter, videosink);
public void run() { JFrame frame = new JFrame("FakeSrcTest"); VideoComponent panel = new VideoComponent(); panel.setPreferredSize(new Dimension(width, height)); frame.add(panel, BorderLayout.CENTER); Element videosink = panel.getElement(); pipeline.addMany(fakesrc, srcfilter, videorate, ratefilter, videosink); Element.linkMany(fakesrc, srcfilter, videorate, ratefilter, videosink);