Note that there are some explanatory texts on larger screens.

plurals
  1. POplaying a video from lists of vlcj player
    primarykey
    data
    text
    <p>I am trying to play a video from the lists of MRL provided as a String.</p> <p>The problem is when I run the class, a list of panels shows with play button and a black screen, but only the last panel plays one video, out of the lists of videos, and when the play buttons of other panel is clicked, the last video replays again.</p> <p>What I want to achieve is, when I run the class, a single video plays, and when I click on the play button of another video, the current video stops and moves to the next video.</p> <p>I don't know where I have gone wrong.</p> <p>As for vlcj, i tried user other layout, but the video shows only when BorderLayout is used, which has limited my options</p> <p>Here is my code:</p> <pre><code>public class MediaPlayer2 extends JPanel { //Declares our media player component private EmbeddedMediaPlayerComponent mediaplayer; private final String vlcpath = "C:\\Program Files (x86)\\VideoLAN\\VLC"; private JPanel video_pnl, control_pnl; private JButton play_btn; ArrayList&lt;String&gt; file_location; public MediaPlayer2(ArrayList&lt;String&gt; file_location) { this.file_location = file_location; NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), vlcpath); int increment = 0; while (increment &lt; file_location.size()) { for (int i = 0; i &lt; 1; i++) { video_pnl = new JPanel(); video_pnl.setLayout(new BorderLayout()); play_btn = new JButton("Play"); mediaplayer = new EmbeddedMediaPlayerComponent(); control_pnl = new JPanel(); control_pnl.setLayout(new FlowLayout(FlowLayout.CENTER)); play_btn.setActionCommand("play"); video_pnl.add(mediaplayer, BorderLayout.CENTER); control_pnl.add(play_btn); video_pnl.add(control_pnl, BorderLayout.SOUTH); Handler handler = new Handler(); play_btn.addActionListener(handler); } add(video_pnl); increment++; } } private class Handler implements ActionListener { @Override public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("play")) { play(); } } } public void play() { for (int i = 0; i &lt; file_location.size(); i++) { mediaplayer.getMediaPlayer().playMedia(file_location.get(i)); } } public static void main(String[] args) { //Declare and initialize local variables ArrayList&lt;String&gt; file_location = new ArrayList&lt;&gt;(); file_location.add("C:\\\\Users\\\\goldAnthony\\\\Desktop\\\\Videos\\\\Whistle.mp4"); file_location.add("C:\\\\Users\\\\goldAnthony\\\\Desktop\\\\Videos\\\\Beyonce_Hello.mp4"); file_location.add("C:\\Users\\goldAnthony\\Desktop\\Videos\\HansRosling_2012S_480p.mp4"); file_location.add("C:\\Users\\goldAnthony\\Desktop\\Videos\\oow2010_2.mp4"); file_location.add("C:\\Users\\goldAnthony\\Desktop\\Videos\\The_Economic_Environment.mp4"); //creates instances of the VlcPlayer object, pass the mediaPath and invokes the method "run" MediaPlayer2 mediaplayer = new MediaPlayer2(file_location); JFrame ourframe = new JFrame(); ourframe.setContentPane(mediaplayer); ourframe.setLayout(new GridLayout(5, 1)); ourframe.setSize(300, 560); ourframe.setVisible(true); mediaplayer.play(); ourframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload