How to play two videos at the same time
Hi everyone!
Ok, so what I'm trying to do is basically play two videos, which are already saved on the computer, at the same time. I can get one video to play, but when i try to start another it just displays a blank screen.
import javax.swing.*;
import javax.media.*;
import java.awt.*;
import javax.media.protocol.*;
publicclass TwoVideoTest{
publicstaticvoid main(String[]args){
MediaLocator locator1 =null;
MediaLocator locator2 =null;
try{
locator1 =new MediaLocator("file:/C:/truck1.mpg");
locator2 =new MediaLocator("file:/C:/truck2.mpg");
}catch(Exception e){
System.out.println("COULNDT CREATE LOCATORS IN MAIN TEST CLASS");
System.exit(-1);
}
Player player1 =null;
Player player2 =null;
try{
player1 = Manager.createRealizedPlayer(locator1);
player2 = Manager.createRealizedPlayer(locator2);
}catch(Exception e){
System.exit(0);
}
JFrame frame =new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel1 =new JPanel();
JPanel panel2 =new JPanel();
panel1.add(player1.getVisualComponent());
frame.getContentPane().add(panel1);
frame.setSize(new Dimension(500,500));
frame.setVisible(true);
player1.start();
player2.start();
}
}
[2585 byte] By [
Stegdura] at [2007-11-26 18:44:22]

# 3
HELLO AGAIN! I guess i post too soon....
So i modified my code and now the videos play together. Threads, sigh.
But the audio that comes with the video doesn't appear to be starting at the same time. And this problem I ASSURE you i have no clue how to handle. And yes i know, the two video audios will overlap, but this a test for heavens sake!
Anyways, heres the modified code in case it will help anyone
import javax.swing.*;
import javax.media.*;
import java.awt.*;
import javax.media.protocol.*;
public class Video implements Runnable{
String url;
MediaLocator locator;
Player player;
JPanel panel;
public Video (String url,JPanel panel) {
this.url = url;
try {
locator = new MediaLocator(url);
player = Manager.createRealizedPlayer(locator);
panel.add(player.getVisualComponent());
player.start();
} catch (Exception e) {
System.out.println("ERROR CREATING MEDIALOCATOR");
System.exit(-1);
}
}
public void run() {
try {
Thread.sleep(100);
} catch(Exception e) {}
}
public static void main(String[]args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
panel1.setPreferredSize(new Dimension(100,100));
panel2.setPreferredSize(new Dimension(100,100));
Thread thread1 = new Thread(new Video("file:/C:/truck1.mpg",panel1));
Thread thread2 = new Thread(new Video("file:/C:/truck2.mpg",panel2));
frame.getContentPane().add(panel1);
frame.getContentPane().add(panel2);
frame.setSize(new Dimension(500,500));
frame.setVisible(true);
thread1.start();
thread2.start();
}
}