jvlc + mouse event = ERROR

This forum is about all development around libVLC.
moijdikssekool
Blank Cone
Blank Cone
Posts: 29
Joined: 06 Jun 2011 03:35

jvlc + mouse event = ERROR

Postby moijdikssekool » 13 Jul 2011 02:07

hi
i'm trying to use jvlc and i have some problems with the mouse listener which is lied to the canvas (lied to mediaPlayerFactory VLC works with)
if i don't launch the video with the line "mediaPlayer.play();", the mouse listener works fine.
as soon as the line "mediaPlayer.play();" is read, the mouse listener is disabled
something strange happens: when the video is launched, some events are detected even if i don't touch the mouse (i launch the program with a keyboard shortcut): first, the mouse is detected to enter the video window, then move and finally exit off the video window, while the mouse doesn't move on screen
It's clearly a problem wih vlc, jvlc or java, not my prog. If you have some other solutions...

here is the whole prog

package myplayer;

import java.awt.*;
import java.awt.event.*;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import uk.co.caprica.vlcj.player.MediaPlayer;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
import uk.co.caprica.vlcj.player.embedded.videosurface.CanvasVideoSurface;
import uk.co.caprica.vlcj.player.events.VideoOutputEventListener;

public class MyPlayer implements MouseListener, MouseMotionListener{

private final JFrame frame;
private final JPanel contentPane;
private final Canvas canvas;

private final MediaPlayerFactory mediaPlayerFactory;
private final EmbeddedMediaPlayer mediaPlayer;
private final CanvasVideoSurface videoSurface;

public static void main(final String[] args) {
System.setProperty("jna.library.path", "c:/VLC");
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {MonThread t = new MonThread() ;
t.start();
}
});
}

public MyPlayer() {
canvas = new Canvas();
canvas.setBackground(Color.black);
canvas.addMouseMotionListener(this);
canvas.addMouseListener(this);
contentPane = new JPanel();
contentPane.setBackground(Color.black);
contentPane.setLayout(new BorderLayout());
contentPane.add(canvas, BorderLayout.CENTER);
frame = new JFrame("My vlcj player");
frame.setContentPane(contentPane);
frame.setSize(800, 600);
frame.setLayout(new GridLayout(1,2));
frame.setUndecorated(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mediaPlayerFactory = new MediaPlayerFactory(new String[] {"--no-video-title-show"});

mediaPlayer = mediaPlayerFactory.newEmbeddedMediaPlayer();
videoSurface = mediaPlayerFactory.newVideoSurface(canvas);

mediaPlayer.setVideoSurface(videoSurface);

mediaPlayer.addVideoOutputEventListener(new VideoOutputEventListener() {
@Override
public void videoOutputAvailable(MediaPlayer mediaPlayer, boolean videoOutput) {
if(videoOutput) {
Dimension size = mediaPlayer.getVideoDimension();
if(size != null) {
//canvas.setSize(1366,768);
canvas.setSize(size.width, size.height);
frame.pack();
}
}
}
});

frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
mediaPlayer.release();
mediaPlayerFactory.release();
}
});

frame.setVisible(true);
}

public void pause()
{
// mediaPlayer.pause();

}
public void start()
{
mediaPlayer.prepareMedia("shadok.avi");
mediaPlayer.play(); //delete this line and the mouse detection will work!
}
public void mouseMoved(MouseEvent e)
{ System.out.println("Vous déplacez la souris"); }

public void mouseDragged(MouseEvent e)
{ System.out.println("Vous déplacez et vous appuyez"); }

public void mouseClicked(MouseEvent e)
{ System.out.println("Click\t x = " + e.getX());
System.out.println("\t\t y = " + e.getY());
System.out.println("Count = " + e.getClickCount());
}
public void mousePressed(MouseEvent e)
{ System.out.println("Bouton"); }
public void mouseReleased(MouseEvent e)
{ System.out.println("Relaché"); }
public void mouseEntered(MouseEvent e)
{ System.out.println("Entrée"); }
public void mouseExited(MouseEvent e)
{ System.out.println("Sortie" + e.getX() +" "+e.getY()); }
}


class MonThread extends Thread
{
MyPlayer a;
public void run()
{
a = new MyPlayer();
a.start();
}
}

Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 20 guests