Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8111709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:13:13+00:00 2026-06-06T02:13:13+00:00

I am creating multiple video panels using vlcj. For each video window I should

  • 0

I am creating multiple video panels using vlcj. For each video window I should add code:

 factory0 = new MediaPlayerFactory();
 mediaPlayer0 = factory0.newEmbeddedMediaPlayer();
 mediaPlayer0.setVideoSurface(factory0.newVideoSurface(videoCanvas[0]));
 mediaPlayer0.setPlaySubItems(true);
 ...

If I want to have 8 video panels then I will have to repeat these codes (not dynamic).

My Question is: I’d like to have MediaPlayerFactory and MediaPlayerFactory as arrays so that I can shorten my code and then this will behave dynamically by just changing Num_Video.

My complete code is as follows. I am creating 4 videos panels in mainPanel.

Thanks.

import uk.co.caprica.vlcj.binding.internal.libvlc_media_t;
import uk.co.caprica.vlcj.player.MediaPlayer;
import uk.co.caprica.vlcj.player.MediaPlayerEventAdapter;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;


public class MultiThreadedWindow extends JFrame implements ActionListener {

    private JPanel topPanel = new JPanel();
    private JPanel statusPanel = new JPanel();
    private JButton playButton = new JButton("Play");private JButton btnStop = new JButton("Stop");
    private JButton btnPause = new JButton("Pause");
    private MediaPlayerFactory factory0, factory1, factory2, factory3;
    private EmbeddedMediaPlayer mediaPlayer0, mediaPlayer1, mediaPlayer2, mediaPlayer3;




    int Video_Width = 200;
    int Video_Height = 150;
    int Num_Video = 4;

    public MultiThreadedWindow() {
        final String jnaLibraryPath = System.getProperty("jna.library.path");
        final StringBuilder newJnaLibraryPath = new StringBuilder(jnaLibraryPath != null ? (jnaLibraryPath + ":") : "");
        newJnaLibraryPath.append("/Applications/VLC.app/Contents/MacOS/lib");
        System.setProperty("jna.library.path", newJnaLibraryPath.toString());



        playButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                play();
            }
        });

        btnStop.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
               stop();
            }
        });

        btnPause.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
               pause();
            }
        });


        topPanel.add(playButton);
        topPanel.add(btnStop);
        topPanel.add(btnPause);

        this.setSize(1000, 800);
        this.setLayout(new BorderLayout());
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel mainPanel = new JPanel(new FlowLayout());


        Canvas[] videoCanvas = new Canvas[Num_Video];
        JPanel[] vidPanel = new JPanel[Num_Video];

        for (int i = 0; i < Num_Video; i++) {
            vidPanel[i] = new JPanel();
            videoCanvas[i] = new Canvas();

            vidPanel[i].setPreferredSize(new Dimension(Video_Width, Video_Height));
            vidPanel[i].setBackground(Color.black);
            vidPanel[i].setLayout(new BorderLayout());

            videoCanvas[i].setBackground(Color.black);
            vidPanel[i].add(videoCanvas[i], BorderLayout.CENTER);

            mainPanel.add(vidPanel[i]);

        }





        factory0 = new MediaPlayerFactory();
        mediaPlayer0 = factory0.newEmbeddedMediaPlayer();
        mediaPlayer0.setVideoSurface(factory0.newVideoSurface(videoCanvas[0]));
        mediaPlayer0.setPlaySubItems(true);
        mediaPlayer0.addMediaPlayerEventListener(new MediaPlayerEventAdapter() {

            @Override
            public void mediaSubItemAdded(MediaPlayer mediaPlayer, libvlc_media_t subItem) {
                List<String> items = mediaPlayer.subItems();
                System.out.println(items);
            }
        });

        factory1 = new MediaPlayerFactory();
        mediaPlayer1 = factory1.newEmbeddedMediaPlayer();
        mediaPlayer1.setVideoSurface(factory1.newVideoSurface(videoCanvas[1]));
        mediaPlayer1.setPlaySubItems(true);
        mediaPlayer1.addMediaPlayerEventListener(new MediaPlayerEventAdapter() {

            @Override
            public void mediaSubItemAdded(MediaPlayer mediaPlayer, libvlc_media_t subItem) {
                List<String> items = mediaPlayer.subItems();
                System.out.println(items);
            }
        });

        factory2 = new MediaPlayerFactory();
        mediaPlayer2 = factory2.newEmbeddedMediaPlayer();
        mediaPlayer2.setVideoSurface(factory2.newVideoSurface(videoCanvas[2]));
        mediaPlayer2.setPlaySubItems(true);
        mediaPlayer2.addMediaPlayerEventListener(new MediaPlayerEventAdapter() {

            @Override
            public void mediaSubItemAdded(MediaPlayer mediaPlayer, libvlc_media_t subItem) {
                List<String> items = mediaPlayer.subItems();
                System.out.println(items);
            }
        });

        factory3 = new MediaPlayerFactory();
        mediaPlayer3 = factory3.newEmbeddedMediaPlayer();
        mediaPlayer3.setVideoSurface(factory3.newVideoSurface(videoCanvas[3]));
        mediaPlayer3.setPlaySubItems(true);
        mediaPlayer3.addMediaPlayerEventListener(new MediaPlayerEventAdapter() {

            @Override
            public void mediaSubItemAdded(MediaPlayer mediaPlayer, libvlc_media_t subItem) {
                List<String> items = mediaPlayer.subItems();
                System.out.println(items);
            }
        });

        this.add(topPanel, BorderLayout.NORTH);
        this.add(mainPanel, BorderLayout.CENTER);
        this.add(statusPanel, BorderLayout.SOUTH);
    }

    public void actionPerformed(ActionEvent e) throws IllegalStateException {

        if (e.getActionCommand().equals("OK")) {
            this.dispose();
        }
    }

    private void start() {
        this.setVisible(true);
    }

    private void play() {
        mediaPlayer0.playMedia("/Users/pujan/1-pix.mp4");
        mediaPlayer1.playMedia("/Users/pujan/1-shakira.mp4");
        mediaPlayer2.playMedia("/Users/pujan/1-flowers.mp4");
        mediaPlayer3.playMedia("/Users/pujan/1-aam.mp4");
    }

    private void stop() {
        mediaPlayer0.stop();
        mediaPlayer1.stop();
        mediaPlayer2.stop();
        mediaPlayer3.stop();
    }

    private void pause() {
        mediaPlayer0.pause();
        mediaPlayer1.pause();
        mediaPlayer2.pause();
        mediaPlayer3.pause();
    }

    public static void main(String[] args) throws Exception {

        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                new MultiThreadedWindow().start();
            }
        });
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T02:13:14+00:00Added an answer on June 6, 2026 at 2:13 am

    I am able to achieve by this

    EmbeddedMediaPlayer mediaPlayer[] = new EmbeddedMediaPlayer[Num_Video];
    

    and then in the loop

    factory[i] = new MediaPlayerFactory();
    mediaPlayer[i] = factory[i].newEmbeddedMediaPlayer();
    mediaPlayer[i].setVideoSurface(factory[i].newVideoSurface(videoCanvas[i]));
    mediaPlayer[i].setPlaySubItems(true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating multiple borders to element using box-shadow, but they don't show at Webkit.
I'm creating multiple asynchronous web requests using IObservables and reactive extensions. So this creates
I am creating an PriorityQueue with multiple queues. I am using an Array to
Suppose you are creating a class with multiple .cpp files (which each contain the
Please check the below code, where I am creating multiple reference for an array
Issue: To avoid creating multiple objects or multiple queries when possible. I am using
I'm creating multiple UI tests and instead of opening a new instance of Microsoft.VisualStudio.TestTools.UITesting.BrowserWindow
I have done following code for creating multiple UISwitches programmatically and handle particular switch.
I have done following code in Viewdid Load for creating multiple switch programmatically. float
Most often when creating multiple classes inside a program that use each other, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.