VLCJ ,LightWeight HAvyweight issue

This forum is about all development around libVLC.
shacoshe
New Cone
New Cone
Posts: 1
Joined: 10 Jun 2010 15:49

VLCJ ,LightWeight HAvyweight issue

Postby shacoshe » 10 Jun 2010 16:00

hello all
i was able to place a transparent jpanel on top of VLC player ,
so far so good ,
i wanted to add some transparent components on top of this panel (in the example the content pane color is set to red),
when adding transparent components i see the Frame content pane where those transparent component should be

here is my example ,
my be someone know how to solve this issue ?

thank you

Code: Select all

/* * Created on Jun 10, 2010 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package vlcj; /* * This file is part of VLCJ. * * VLCJ is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * VLCJ is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VLCJ. If not, see <http://www.gnu.org/licenses/>. * * Copyright 2009, 2010 Caprica Software Limited. */ import java.awt.AlphaComposite; import java.awt.BorderLayout; import java.awt.Canvas; import java.awt.Color; import java.awt.Composite; import java.awt.FlowLayout; import java.awt.Frame; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLayeredPane; import javax.swing.JPanel; import javax.swing.SwingUtilities; import javax.swing.border.EmptyBorder; import org.apache.log4j.BasicConfigurator; import uk.co.caprica.vlcj.player.MediaPlayer; import uk.co.caprica.vlcj.player.MediaPlayerFactory; import uk.co.caprica.vlcj.runtime.RuntimeUtil; import com.sun.awt.AWTUtilities; import com.sun.jna.NativeLibrary; /** * Minimal media player application. * <p> * Specify a single media MRL as a command-line argument. * <p> * VLCJ depends on log4j, so ensure you have a log4j.jar file in your class-path. * <p> * If you don't know how to do that, you're already out of your depth. */ public class NumptyPlayer { private JFrame mainFrame; private Canvas videoSurface; JLayeredPane m_layeredPane = new JLayeredPane(); JPanel m_pnlControls = new JPanel(); private MediaPlayerFactory mediaPlayerFactory; private MediaPlayer mediaPlayer; public static void main(final String[] args) throws Exception { BasicConfigurator.configure(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new NumptyPlayer(args); } }); } public NumptyPlayer(String[] args) { args = new String[]{"d:\\blender\\books\\carpaint.mp4"}; if(args.length != 1) { System.out.println("Specify a single media URL"); System.exit(1); } videoSurface = new Canvas(); NativeLibrary.addSearchPath("libvlc", "C:\\Program Files (x86)\\VideoLAN\\VLC"); // This burns so many people on Windows that I decided to leave it in... String vlcArgs = null; if(RuntimeUtil.isWindows()) { // vlcArgs = "--plugin-path=" + WindowsRuntimeUtil.getVlcInstallDir() + "\\plugins"; vlcArgs = "--plugin-path=" + "C:\\Program Files (x86)\\VideoLAN\\VLC"; } mediaPlayerFactory = new MediaPlayerFactory(vlcArgs != null ? new String[] {vlcArgs} : new String[]{}); mediaPlayer = mediaPlayerFactory.newMediaPlayer(null); AWTUtilities.setComponentMixingCutoutShape(m_pnlControls, new Rectangle()); // m_pnlControls.setOpaque(false); m_layeredPane.add(m_pnlControls , new Integer(10)); m_layeredPane.add(videoSurface , new Integer(1)); JPanel pnlTest = new JPanel(new FlowLayout(FlowLayout.LEADING)) { protected void paintComponent(Graphics g){ super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; Object hintOriginal = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING ,RenderingHints.VALUE_ANTIALIAS_ON); Composite oldComposite = g2.getComposite(); AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.2f); g2.setComposite(composite); g2.setColor(Color.BLUE); g2.fillRoundRect(0, 0, getSize().width, getSize().height, 80, 80); g2.setComposite(oldComposite); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, hintOriginal); } }; pnlTest.setOpaque(false); pnlTest.add(new JButton("asdfasdf")); m_pnlControls.setBorder(new EmptyBorder(20, 20, 20, 20)); m_pnlControls.setLayout(new BorderLayout(10 ,10)); m_pnlControls.add(pnlTest ,BorderLayout.SOUTH); mainFrame = new JFrame("VLCJ Numpty Player") { public void doLayout(){ super.doLayout(); m_layeredPane.setBounds(0, 0, getSize().width, getSize().height); if(videoSurface != null){ videoSurface.setBounds(0, 0, getSize().width, getSize().height); } m_pnlControls.setBounds(0, 0, getSize().width, getSize().height); } }; m_pnlControls.setOpaque(false); mainFrame.getContentPane().setBackground(Color.RED); mainFrame.setUndecorated(true); mainFrame.setLayout(new BorderLayout()); // mainFrame.add(videoSurface, BorderLayout.CENTER); mainFrame.add(m_layeredPane, BorderLayout.CENTER); mainFrame.setSize(800, 600); mainFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { mediaPlayer.release(); mediaPlayer = null; mediaPlayerFactory.release(); System.exit(0); } }); mainFrame.setVisible(true); mediaPlayer.setVideoSurface(videoSurface); // There is a race condition in native libraries when starting up, so // do not play immediately - empirically the most reliable way to avoid // a native library crash is to sleep for a bit, then start the player // on the EDT. Not ideal, if you find a better way let me know. try { Thread.sleep(1000); } catch (InterruptedException e) { } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { mediaPlayer.playMedia("d:\\blender\\books\\carpaint.mp4"); } }); } }

gnosygnu
Blank Cone
Blank Cone
Posts: 45
Joined: 06 Jun 2010 16:06

Re: VLCJ ,LightWeight HAvyweight issue

Postby gnosygnu » 11 Jun 2010 05:18

I tried something similar a while ago. viewtopic.php?f=32&t=75768
I'm not sure if my situation applies though. I think you're looking for a transparent panel with opaque buttons. I was looking for a fully transparent panel to capture mouse events.

At any rate, if you're interested in my situation, you can try the following
1: add simple JFrame

Code: Select all

class MyFrame extends JFrame { public MyFrame() { this.setSize(400, 800); JButton jb = new JButton(); jb.setText("push me"); this.add(jb); } }
2: change your vlcArgs to use no-overlay

Code: Select all

vlcArgs = new String[] {"--plugin-path=C:\\VLC\\plugins", "--no-overlay"};
3: add code to create transparent MyFrame (I placed it underneath AWTUtilities.setComponentMixingCutoutShape)

Code: Select all

MyFrame transparentFrame = new MyFrame(); AWTUtilities.setWindowOpacity(transparentFrame, 0.10f); transparentFrame.setVisible(true);
Run the sample, and bring MyFrame to the front.

In this case you'll have semi-transparency. It will be ugly (lots of flickering), but you can decrease the setWindowOpacity to .01f to get full transparency.
Hope this helps


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 4 guests