JVLC Client Example help

Microsoft Windows specific usage questions
Forum rules
Please post only Windows specific questions in this forum category. If you don't know where to post, please read the different forums' rules. Thanks.
jopenman
New Cone
New Cone
Posts: 6
Joined: 30 Jul 2008 21:19

JVLC Client Example help

Postby jopenman » 30 Jul 2008 21:26

Since there is no current VLCClient example in the nightly builds for jVlc I was wondering if someone can assist me in getting some code to work. Below is a snip of code that I am trying to get to play in a jPanel in NetBeans but fails when I hit the play button. Thanks for the help in advance.

Code: Select all

private JPanel jvcc; public JVLC jvlc; //Initialize VLC jvcanvas = new java.awt.Canvas(); jvcanvas.setSize(640,480); jPanel2.add(jvcanvas); String[] args = new String[] {}; // jvlc = new JVLC(args); medialist = new MediaList(jvlc); vlcPlayer = new MediaListPlayer(jvlc); vlcPlayer.setMediaList(medialist);
Code that is placed in teh ButtonActionPerformed call:

Code: Select all

if( vlcPlayer.isPlaying()) vlcPlayer.stop(); medialist.clear(); jvlc.setVideoOutput(jvcanvas); medialist.addMedia(jLabel1.getText()); vlcPlayer.play();
Am I missing some key element to get this to work?

CamHart
New Cone
New Cone
Posts: 7
Joined: 28 Jul 2008 20:46

Re: JVLC Client Example help

Postby CamHart » 31 Jul 2008 03:47

You understand more about this stuff than I do, but here's the example code incase it helps.
http://trac.videolan.org/vlc/browser/bi ... lient.java

jopenman
New Cone
New Cone
Posts: 6
Joined: 30 Jul 2008 21:19

Re: JVLC Client Example help

Postby jopenman » 31 Jul 2008 05:35

Thanks CamHart for the reply. But the example that you posted here is way out of date. I am using the latest 0.9 build and some of the classes (like Playlist) are being phased out and you need to use newer MediaList class instead. The problem is there is very little documentation on how to properly setup MediaList to play in a jPanel as there was in previous versions with PlayList.

randgen22
New Cone
New Cone
Posts: 8
Joined: 25 Jul 2008 20:51

Re: JVLC Client Example help

Postby randgen22 » 31 Jul 2008 19:28

Hi jopenman,

Have you tried this?

Code: Select all

//vlcPlayer.play(); vlcPlayer.playItem(0);
That change works for me, however, the JVM crashes on me when I try to push stop for certain videos. I've posted that issue in another thread:
viewtopic.php?f=2&t=48534&p=155019

jgg
Cone that earned his stripes
Cone that earned his stripes
Posts: 144
Joined: 03 Nov 2007 15:49

Re: JVLC Client Example help

Postby jgg » 27 Aug 2008 00:44

Hi,

I have written a simple Swing-based JVLC client with the latest 0.9.0-test3 jar library and I have experienced some problems with the Swing integration and the playlist management.

First, the only way I can have a visible integrated JVLC canvas is adding it directly to the JFrame container, having this a border layout and adding the canvas with the center position, while adding button and other panels in north and south positions. I can't use vertical/horizontal box or flow layouts because when launching the application I get a "Content must be displayable" error immediately (even using a flow layout and only adding the canvas). Is there any solution to this issue? Why can't I treat the JVLC canvas as any other Swing component?

On the other side, I have tried to use MediaList and MediaListPlayer classes from the new 0.9.0 JVLC API instead the deprecated Playlist one, but I have got no success. My simple application just adds video files to a list (add button) and allows playing and other simple actions (play, stop, next, mute... buttons). With the deprecated Playlist class I can add and play different video files with no problem, but when I create a MediaList with the new API and add some video files, using the play() and next() methods from the MediaListPlayer class I get an error and the program stops running.

This is the code of my simple application:

Code: Select all

package test; import java.awt.BorderLayout; import java.awt.Canvas; import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingUtilities; import org.videolan.jvlc.Audio; import org.videolan.jvlc.JVLC; import org.videolan.jvlc.MediaDescriptor; import org.videolan.jvlc.MediaList; import org.videolan.jvlc.MediaListPlayer; import org.videolan.jvlc.MediaPlayer; import org.videolan.jvlc.Playlist; import org.videolan.jvlc.VLCException; import org.videolan.jvlc.Video; public class GUITest extends JFrame { private JButton playButton, addButton, stopButton, pauseButton, muteButton, nextButton, prevButton, fullscreenButton; private JTextField mrlField; private JPanel buttonPanelUp, buttonPanelBottom, textEntryPanel, buttonPanel; private Canvas canvas; private Container container; private JVLC jvlc; private MediaList mediaList; private MediaListPlayer mediaListPlayer; private MediaDescriptor mediaDescriptor; private Audio audio; private Video video; private Playlist playlist; public GUITest(){ super("JVLC GUI test"); setPreferredSize(new Dimension(500, 500)); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // VIDEO FRAME // New canvas = new Canvas(); jvlc = new JVLC(); mediaList = jvlc.getMediaList(); mediaListPlayer = new MediaListPlayer(jvlc); mediaListPlayer.setMediaList(mediaList); video = new Video(jvlc); audio = new Audio(jvlc); // Deprecated playlist = new Playlist(jvlc); // BUTTONS playButton = new JButton("Play"); playButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ play(); } }); pauseButton = new JButton("Pause"); pauseButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ pause(); } }); stopButton = new JButton("Stop"); stopButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ stop(); } }); muteButton = new JButton("Mute"); muteButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ mute(); } }); fullscreenButton = new JButton("Full Screen"); fullscreenButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ fullscreen(); } }); nextButton = new JButton("Next"); nextButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ next(); } }); prevButton = new JButton("Prev"); prevButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ prev(); } }); addButton = new JButton("Add"); addButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ add(); } }); // TEXT FIELD mrlField = new JTextField("/home/dulceangustia/diptvServerLinux32/contents/", 40); // PANELS buttonPanelUp = new JPanel(new FlowLayout()); buttonPanelUp.add(playButton); buttonPanelUp.add(pauseButton); buttonPanelUp.add(stopButton); buttonPanelUp.add(fullscreenButton); buttonPanelBottom = new JPanel(new FlowLayout()); buttonPanelBottom.add(muteButton); buttonPanelBottom.add(prevButton); buttonPanelBottom.add(nextButton); buttonPanelBottom.add(addButton); textEntryPanel = new JPanel(new FlowLayout()); textEntryPanel.add(mrlField); buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS)); buttonPanel.add(buttonPanelUp); buttonPanel.add(buttonPanelBottom); container = getContentPane(); container.setLayout(new BorderLayout()); container.add(canvas, BorderLayout.CENTER); container.add(buttonPanel, BorderLayout.NORTH); container.add(textEntryPanel, BorderLayout.SOUTH); pack(); setVisible(true); jvlc.setVideoOutput(canvas); } private void play() { mediaListPlayer.playItem(0); // With the deprecated playlist class /*try { playlist.play(); } catch (VLCException e) { e.printStackTrace(); }*/ } private void pause() { if (mediaListPlayer.isPlaying()) mediaListPlayer.pause(); else mediaListPlayer.play(); // With the deprecated playlist class /*try { playlist.togglePause(); } catch (VLCException e) { e.printStackTrace(); }*/ } private void stop() { if (mediaListPlayer.isPlaying()) mediaListPlayer.stop(); // With the deprecated playlist class /*try { playlist.stop(); } catch (VLCException e) { e.printStackTrace(); }*/ } private void mute() { audio.toggleMute(); } private void fullscreen() { //video.toggleFullscreen(mediaListPlayer); } private void next() { mediaListPlayer.next(); // With the deprecated playlist class /*try { playlist.next(); } catch (VLCException e) { e.printStackTrace(); }*/ } private void prev() { //mediaListPlayer.playItem(); // With the deprecated playlist class /*try { playlist.prev(); } catch (VLCException e) { e.printStackTrace(); }*/ } private void add() { mediaDescriptor = new MediaDescriptor(jvlc, mrlField.getText().toString()); mediaList.addMedia(mediaDescriptor); // With the deprecated playlist class /*try { playlist.add(mrlField.getText().toString(), mrlField.getText().toString()); } catch (VLCException e) { e.printStackTrace(); }*/ } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new GUITest(); } }); } }

And this is the error message that appears when I click the next button when I have more than one item in the MediaList:

Code: Select all

[00000001] main libvlc debug: VLC media player - version 0.9.0-test3 Grishenko - (c) 1996-2008 the VideoLAN team [00000001] main libvlc debug: libvlc was configured with ./configure '--mandir=/share/man' '--build=i486-linux-gnu' '--enable-maintaner-mode' '--enable-release' '--prefix=/usr' '--enable-libtool' '--enable-fast-install' '--disable-update-check' '--disable-gnome' '--disable-gtk' '--disable-familiar' '--disable-fb' '--enable-ggi' '--enable-sdl' '--enable-esd' '--enable-mad' '--enable-arts' '--enable-jack' '--enable-pulse' '--enable-lirc' '--enable-a52' '--enable-aa' '--enable-dvbpsi' '--enable-mozilla' '--disable-kde' '--enable-mp4' '--enable-dvb' '--disable-satellite' '--enable-ogg' '--enable-vorbis' '--enable-shout' '--enable-wxwidgets' '--with-wx-config=wx-config' '--enable-qt4' '--disable-slp' '--enable-flac' '--disable-skins' '--disable-basic-skins' '--enable-skins2' '--enable-freetype' '--enable-mkv' '--enable-speex' '--enable-caca' '--enable-live555' '--enable-libmpeg2' '--enable-fribidi' '--enable-cdio' '--enable-mod' '--enable-theora' '--enable-modplug' '--enable-dvdnav' '--enable-gnutls' '--enable-ffmpeg' '--enable-ncurses' '--enable-smb' '--disable-gnomevfs' '--enable-bonjour' '--enable-mpc' '--enable-vcd' '--enable-vcdx' '--enable-notify' '--enable-debug' '--enable-twolame' '--enable-x264' '--enable-faad' '--disable-zvbi' '--enable-telx' '--enable-mediacontrol-bindings' '--disable-x264' '--disable-atmo' '--enable-alsa' '--enable-dv' '--enable-v4l' '--enable-v4l2' '--enable-pvr' '--enable-svgalib' '--enable-dvd' '--without-dvdcss' 'build_alias=i486-linux-gnu' 'CFLAGS=-g -O2' 'LDFLAGS=-Wl,-Bsymbolic-functions' 'CPPFLAGS=' 'CXXFLAGS=-g -O2' [00000001] main libvlc debug: translation test: code is "C" *** LibVLC Exception not handled: No active input Set a breakpoint in 'libvlc_exception_not_handled' to debug. LibVLC fatal error locking mutex in thread 3040652176 at control/media_list.c:174: 35 Error message: Resource deadlock avoided at: /usr/lib/libvlccore.so.0(vlc_pthread_fatal+0xa7)[0xb5301207] /usr/lib/libvlc.so(libvlc_media_list_release+0xa5)[0xb5361c15] /usr/lib/libvlc.so(libvlc_media_list_player_next+0x499)[0xb5362e59] /tmp/jna42322.tmp(ffi_call_SYSV+0x17)[0xb5376f7f] /tmp/jna42322.tmp(ffi_call+0x52)[0xb5376d42] /tmp/jna42322.tmp[0xb536d457] /tmp/jna42322.tmp(Java_com_sun_jna_Function_invokeVoid+0x32)[0xb536dc74] [0xb5d60e9d] [0xb5d59edd] [0xb5d59d77] [0xb5d59d77] [0xb5d59d77] [0xb5d5a253] [0xb5d5a3b9] [0xb5d59edd] [0xb5d59edd] [0xb5d59edd] [0xb5d5a3b9] [0xb5d59edd] [0xb5d5a3b9]
Note that, as randgen22 said, I must use the playItem(0) method instead of play() to start playing the created playlist with MediaList. Is this the way it should be or play() should work as well?

In addition, it seems that there is no implemented method in MediaListPlayer to play the previous item in the playlist as it exists in the deprecated Playlist class. Will it eventually be implemented?

And last but not least, how can I set the full screen mode to a playing media from a MediaList? The Video class has setFullscreen(MediaPlayer, boolean) and toggleFullscreen(MediaPlayer) methods to do that, but they need a MediaPlayer instance, which is only created for a specific file and not for a MediaList, which needs a MediaListPlayer instead a MediaPlayer, so... what should I do to toggle the fullscreen option?


Hope somebody can help me with these issues. Your help is much appreciated.


Thank you,
Javi


Return to “VLC media player for Windows Troubleshooting”

Who is online

Users browsing this forum: No registered users and 65 guests