My project looks like: I have a bike speedometer attached to simple bike and connected to Raspberry Pi, which is connected over ethernet cable to laptop.
What I want to do is: Raspberry measure the speed of bike wheel and send this value over ethernet cable to laptop. Laptop now uses recieved value and speed up a video, which is played in VLC.
I have working java program on RPi to measure speed of a wheel, I have a working client (on laptop)-server (on RPi) java program to send values from RPi to laptop, and I have a working java program to control speed of video playing in VLC on laptop.
But my problem is, that I don't know how to use values, recieved from RPi over client-server program, in my program, which control speed of video, playing in VLC.
Down are my codes for client and to control speed of video.
Client code:
package player;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;
public class client {
public static int inputPlayer = 0;
public static void main(String[] args) throws UnknownHostException, IOException {
String accept;
int input;
DataInputStream inC = null;
Scanner sc1 = null;
Socket s = null;
try {
s = new Socket ("169.254.218.194", 1342);
Scanner sc = new Scanner (System.in);
System.out.println("Accept connection!");
accept = sc.next();
PrintStream p = new PrintStream (s.getOutputStream());
p.println(accept);
//inC = new DataInputStream(s.getInputStream());
}
catch (Exception e) {
e.printStackTrace();
}
while (true) {
sc1 = new Scanner (s.getInputStream());
input = sc1.nextInt();
if (input > 0) {
inputPlayer = input;
}
System.out.println("I" + input);
//System.out.println("IP" + inputPlayer);
}
}
public int getInputPlayer () {
return this.inputPlayer;
}
}
Player code:
package player;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Scanner;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.discovery.NativeDiscovery;
public class Player {
private final JFrame frame;
private final EmbeddedMediaPlayerComponent mediaPlayerComponent;
public static void main(final String[] args) {
new NativeDiscovery().discover();
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
new Player(args);
}
});
}
public Player(String[] args) {
frame = new JFrame("My First Media Player");
frame.setBounds(100, 100, 600, 400);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
#Override
public void windowClosing(WindowEvent e) {
mediaPlayerComponent.release();
System.exit(0);
}
});
JPanel contentPane = new JPanel();
contentPane.setLayout(new BorderLayout());
mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
contentPane.add(mediaPlayerComponent, BorderLayout.CENTER);
Scanner in = new Scanner (System.in);
frame.setContentPane(contentPane);
frame.setVisible(true);
mediaPlayerComponent.getMediaPlayer().playMedia("file:URL");
mediaPlayerComponent.getMediaPlayer().skip(1000);
client c = new client();
float i = c.getInputPlayer();
while (true) {
//float i = in.nextFloat();
//System.out.println(i);
mediaPlayerComponent.getMediaPlayer().setRate(i);
}
}
}
Everything I want to do is to use variable inputPlayer from client class as variable i in Player class.
As I have done, Eclipse return me error: "[000000001ade9eb0] core input error: input control fifo overflow, trashing type=2"
Thanks for your help.
Jan
There are several problems here:
the code in the client class (btw, class names should begin with uppercase) is never run. You've put all the code in that class in a main method, which only gets executed if you run the application by choosing that class. Essentially, you have two separate applications here. Even if you were to run them at the same time, it wouldn't help you since one would not have direct access to instances of classes in the other.
i is set only once and never updated inside the loop
you could turn that main method of the client class into an ordinary method, but even then you can't have two while(true) loops run at the same time if they are on the same thread.
If handling thread is a bit much for you at this stage, you could try simply combining both classes in one. One loop would scan for incoming data and set the players speed as it came. This might or might not work, depending on how the player itself is implemented, but you could give it a try.
Related
thanks so much in advance for helping me with this seemingly tiny thing - yet I can't figure it out. MP4 Video/audio playback works just fine, yet I can't set the position in the video.
Here's my stripped down code:
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import javax.swing.JPanel;
import com.sun.jna.NativeLibrary;
import java.util.logging.Level;
import java.util.logging.Logger;
import uk.co.caprica.vlcj.binding.RuntimeUtil;
import uk.co.caprica.vlcj.player.base.ControlsApi;
import uk.co.caprica.vlcj.player.base.MediaApi;
import uk.co.caprica.vlcj.player.base.MediaPlayer;
import uk.co.caprica.vlcj.player.component.CallbackMediaPlayerComponent;
import uk.co.caprica.vlcj.player.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.player.component.callback.FilledCallbackImagePainter;
import uk.co.caprica.vlcj.player.component.callback.FixedCallbackImagePainter;
import uk.co.caprica.vlcj.player.component.callback.ScaledCallbackImagePainter;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
import uk.co.caprica.vlcj.player.renderer.RendererItem;
import uk.co.caprica.vlcjplayer.event.TickEvent;
import uk.co.caprica.vlcjplayer.view.action.mediaplayer.MediaPlayerActions;
public class TestClass extends JPanel {
private EmbeddedMediaPlayerComponent ourMediaPlayer;
TestClass(){
//NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "C:\\Program Files\\VideoLAN\\VLC");
ourMediaPlayer = new EmbeddedMediaPlayerComponent();
/* Set the canvas */
Canvas c = new Canvas();
c.setBackground(Color.black);
c.setVisible(true);
/* Set the layout */
this.setLayout(new BorderLayout());
/* Add the canvas */
this.add(c, BorderLayout.CENTER);
this.setVisible(true);
this.add(ourMediaPlayer);
}
public void play() {
/* Play the video */
System.out.println("Starting...");
ourMediaPlayer.mediaPlayer().controls().setPosition((float) 0.5); // NOPE
ourMediaPlayer.mediaPlayer().media().play("/home/manfred/ExtraDisk/Work/BTL/Movement2022/walking.mp4"); // works
ourMediaPlayer.mediaPlayer().controls().stop(); // works
ourMediaPlayer.mediaPlayer().controls().setPosition((float) 0.5); //NOPE
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {
Logger.getLogger(TestClass.class.getName()).log(Level.SEVERE, null, ex);
}
ourMediaPlayer.mediaPlayer().controls().setPosition((float) 0.5); //NOPE
ourMediaPlayer.mediaPlayer().controls().setTime(2000); // NOPE
ourMediaPlayer.mediaPlayer().controls().start(); //works
//System.time.sleep(2);
System.out.println("Started!");
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {
Logger.getLogger(TestClass.class.getName()).log(Level.SEVERE, null, ex);
}
ourMediaPlayer.mediaPlayer().controls().stop(); // works
}
}
Playback via .mediaPlayer().media().play() works, so does start and stop via .mediaPlayer().controls().start() and .mediaPlayer().controls().stop().
What doesn't work is .mediaPlayer().controls().setTime(xx) and .mediaPlayer().controls().setPosition(xx), basically nothing happens.
What am I not doing right here? Is this a threading issue? Anyone have any working minimal examples?
Thanks again, any help is greatly appreciated!
It is not possible to use the API to set the time/position before playback has started.
LibVLC operates asynchronously for many operations. Just calling play() does not mean that playback has started, so setting the time/position immediately after play() is called will not (always) work.
There are at least two approaches you can use:
Wait for a media player "ready" event, and set the time/position (this will fire an event each time the media player is ready, so each time you play it, although you can write a one-shot listener that unregisters itself if you only want to do it the first time you play).
public static void main(String[] args) throws Exception {
MediaPlayer mediaPlayer = new MediaPlayerFactory().mediaPlayers().newMediaPlayer();
mediaPlayer.events().addMediaPlayerEventListener(new MediaPlayerEventAdapter() {
#Override
public void mediaPlayerReady(MediaPlayer mediaPlayer) {
mediaPlayer.controls().setTime(10000);
}
});
mediaPlayer.media().play("/home/movies/whatever.mp4");
Thread.currentThread().join();
}
With this first approach there is the small risk that you will see one or two video frames rendered before skipping occurs.
Use media options to set the start time (in seconds, including fractions of seconds like 10.5):
public static void main(String[] args) throws Exception {
MediaPlayer mediaPlayer = new MediaPlayerFactory().mediaPlayers().newMediaPlayer();
mediaPlayer.media().play("/home/movies/whatever.mp4", ":start-time=10");
Thread.currentThread().join();
}
Thanks to caprica's ingenious insights, this snippet actually works (don't know why, but it does - and that's all that matters for now):
ourMediaPlayer.mediaPlayer().media().play("/home/manfred/ExtraDisk/Work/BTL/Movement2022/walking.mp4"); // works
ourMediaPlayer.mediaPlayer().controls().stop(); // works
ourMediaPlayer.mediaPlayer().controls().start(); // works
ourMediaPlayer.mediaPlayer().controls().setTime(5000); // WORKS
Still a bit of a mystery, but I'll take it!
When trying to simulate input using AssertJ's pressAndReleaseKeys() for unit testing a JComboBox in a Java Swing program, I am not seeing the expected behavior. The program will most often hang on the pressAndReleaseKeys line and then fail, or occasionally will delete all the text currently in the JComboBox being tested, causing later assertions to fail (i.e. requireSelection()). The stack trace I receive for the provided example program (see below) when it hangs is as follows:
Focus change to javax.swing.JComboBox[name='combob', selectedItem='Bean', contents=["Pork", "Beans", "Rice"], editable=true, enabled=true, visible=true, showing=true] failed focus owner: javax.swing.plaf.metal.MetalComboBoxEditor$1(javax.swing.JTextField)[name=null, text='Bean', enabled=true, visible=true, showing=true]
org.assertj.swing.exception.ActionFailedException
at org.assertj.swing.exception.ActionFailedException.actionFailure(ActionFailedException.java:33)
at org.assertj.swing.core.BasicRobot.focus(BasicRobot.java:301)
at org.assertj.swing.core.BasicRobot.focusAndWaitForFocusGain(BasicRobot.java:270)
at org.assertj.swing.driver.ComponentDriver.focusAndWaitForFocusGain(ComponentDriver.java:419)
at org.assertj.swing.driver.ComponentDriver.pressAndReleaseKeys(ComponentDriver.java:315)
at org.assertj.swing.fixture.AbstractComponentFixture.pressAndReleaseKeys(AbstractComponentFixture.java:293)
at javapractice.ComboBoxSampleTest.testMain(ComboBoxSampleTest.java:59)
I have been using FEST and am hoping to migrate my tests to AssertJ since it is being actively maintained, whereas FEST hasn't been updated for years. I used Joel Costigliola's migration from Fest to AssertJ guide, but am having trouble when simulating keyboard input by using pressAndReleaseKeys(). I am able to simulate input when using a JTextComponentFixture i.e.
window.textBox("textB").pressAndReleaseKeys(KeyEvent.VK_LEFT);
(where window is a FrameFixture, a container in both AssertJ and FEST), but I am unable to simulate input when using a JComboBoxFixture i.e.
window.comboBox("comboB").pressAndReleaseKeys(KeyEvent.VK_LEFT);
This obstacle can usually be avoided, since most "key presses" can be simulated by using enterText i.e.
window.comboBox("comboB").enterText("\n"); //to press the enter key
window.comboBox("comboB").enterText("\b"); //to press the backspace key
but I would like to be able to use the arrow keys, control key, and other keys where I can't simulate the key press using enterText(). Is this failure due to an issue with my environment*, an issue with the way I'm using it, or is the API itself flawed?
I tried using pressKey() and then releaseKey() as a workaround, but that doesn't work with JComboBox either, and my program instead hangs on pressKey(). That being said, I am not able to use pressKey() and releaseKey() to test a JComboBox with FEST either.
*Environment details:
Language version: java version "1.8.0_131"
Platform version (e.g. .NET 3.5; note that this isn’t always implicit from the language version, or vice versa)
Operating system: Red Hat Release 6.10 (Santiago)
IDE: Netbeans 8.0.2
Sample GUI application:
package javapractice;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class ComboBoxSample extends JFrame implements ItemListener{
JPanel jp;
JComboBox jcb;
JLabel result;
JLabel title;
JTextField jtc;
public static void main(String[] args) {
ComboBoxSample frame = new ComboBoxSample();
}
ComboBoxSample() {
super();
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
this.setTitle("Testing AssertJ");
this.setLayout(new FlowLayout());
jp = new JPanel();
jcb = new JComboBox(new String[] {"Pork", "Beans", "Rice"});
jcb.setEditable(true);
jcb.setName("combob");
jtc = new JTextField();
jtc.setEditable(true);
jtc.setPreferredSize(new Dimension(150, 25));
jtc.setName("textb");
title = new JLabel("Food: ");
result = new JLabel("No food");
jp.add(title);
jp.add(jcb);
jp.add(result);
jp.add(jtc);
this.add(jp);
this.setLocationRelativeTo(null);
jcb.addItemListener(this);
this.pack();
this.repaint();
}
#Override
public void itemStateChanged(ItemEvent e) {
if(e.getSource() == jcb) {
result.setText("I'm eating " + jcb.getSelectedItem());
}
this.pack();
}
public void cleanUp() {
jcb = null;
result = null;
jtc = null;
jp = null;
title = null;
}
}
Test File for Fest:
package javapractice;
import com.sun.glass.events.KeyEvent;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* Fest imports.
*/
import org.fest.swing.edt.FailOnThreadViolationRepaintManager;
import org.fest.swing.edt.GuiActionRunner;
import org.fest.swing.edt.GuiQuery;
import org.fest.swing.fixture.FrameFixture;
public class ComboBoxSampleTest {
private FrameFixture window;
private ComboBoxSample frame;
#BeforeClass
public static void setUpClass() {
FailOnThreadViolationRepaintManager.install();
}
#AfterClass
public static void tearDownClass() {
}
#Before
public void setUp() {
frame = GuiActionRunner.execute(new GuiQuery<ComboBoxSample>() {
#Override
protected ComboBoxSample executeInEDT() {
return new ComboBoxSample();
}
});
window = new FrameFixture(frame);
window.show();
}
#After
public void tearDown() {
window.cleanUp();
frame.cleanUp();
}
/**
* Test of main method, of class ComboBoxSample.
*/
#Test
public void testMain() {
//Delay so that we can see what's going on
try {
Thread.sleep(2000);
} catch (InterruptedException ie) {
}
window.textBox("textb").enterText("hi there");
window.textBox("textb").pressAndReleaseKeys(KeyEvent.VK_BACKSPACE);
window.comboBox().replaceText("Bean");
window.comboBox().pressAndReleaseKeys(KeyEvent.VK_S);
window.comboBox().pressAndReleaseKeys(KeyEvent.VK_DOWN);
window.comboBox().pressAndReleaseKeys(KeyEvent.VK_DOWN);
window.comboBox().pressAndReleaseKeys(KeyEvent.VK_DOWN);
window.comboBox().pressAndReleaseKeys(KeyEvent.VK_ENTER);
}
}
Test File for AssertJ:
package javapractice;
import com.sun.glass.events.KeyEvent;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* AssertJ imports.
*/
import org.assertj.swing.edt.FailOnThreadViolationRepaintManager;
import org.assertj.swing.edt.GuiActionRunner;
import org.assertj.swing.fixture.FrameFixture;
public class ComboBoxSampleTest {
private FrameFixture window;
private ComboBoxSample frame;
#BeforeClass
public static void setUpClass() {
FailOnThreadViolationRepaintManager.install();
}
#AfterClass
public static void tearDownClass() {
}
#Before
public void setUp() {
frame = GuiActionRunner.execute(() -> new ComboBoxSample());
window = new FrameFixture(frame);
window.show();
}
#After
public void tearDown() {
window.cleanUp();
frame.cleanUp();
}
/**
* Test of main method, of class ComboBoxSample.
*/
#Test
public void testMain() {
//Delay so that we can see what's going on
try {
Thread.sleep(2000);
} catch (InterruptedException ie) {
}
window.textBox("textb").enterText("hi there");
window.textBox("textb").pressAndReleaseKeys(KeyEvent.VK_BACKSPACE);
window.comboBox().replaceText("Bean");
//the above line is the last one to execute
window.comboBox().pressAndReleaseKeys(KeyEvent.VK_S);
window.comboBox().pressAndReleaseKeys(KeyEvent.VK_DOWN);
window.comboBox().pressAndReleaseKeys(KeyEvent.VK_DOWN);
window.comboBox().pressAndReleaseKeys(KeyEvent.VK_DOWN);
window.comboBox().pressAndReleaseKeys(KeyEvent.VK_ENTER);
}
}
This is not an answer to the question, but a workaround that allows the desired behavior. This issue can be mitigated by invoking robot() for the comboBox().
Instead of
window.comboBox().pressAndReleaseKeys(KeyEvent.VK_S);
try doing
window.comboBox().robot().pressAndReleaseKeys(KeyEvent.VK_S);
I want to make a webcam capture software and a stream software using sarxos's webcam library. Wanting to understand the examples first i don't know what to change or add in order to go past this error at import us.sosia.
package us.sosia.video.stream.agent.ui does not exist
package us.sosia.video.stream.handler
Maybe i have to make a Marvin project and change the pow.xml file but i don't know how to do this and still add my sarxos library to the Marvin project using NetBeans.
first class is StreamServer:
package us.sosia.video.stream.agent;
import java.awt.Dimension;
import java.net.InetSocketAddress;
import com.github.sarxos.webcam.Webcam;
public class StreamServer {
/**
* #author kerr
* #param args
*/
public static void main(String[] args) {
Webcam.setAutoOpenMode(true);
Webcam webcam = Webcam.getDefault();
Dimension dimension = new Dimension(320, 240);
webcam.setViewSize(dimension);
StreamServerAgent serverAgent = new StreamServerAgent(webcam, dimension);
serverAgent.start(new InetSocketAddress("localhost", 20000));
}
}
Second class is StreamClient:
package us.sosia.video.stream.agent;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.net.InetSocketAddress;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import us.sosia.video.stream.agent.ui.SingleVideoDisplayWindow;
import us.sosia.video.stream.handler.StreamFrameListener;
public class StreamClient {
/**
* #author kerr
* */
private final static Dimension dimension = new Dimension(320,240);
private final static SingleVideoDisplayWindow displayWindow = new SingleVideoDisplayWindow("Stream example",dimension);
protected final static Logger logger = LoggerFactory.getLogger(StreamClient.class);
public static void main(String[] args) {
//setup the videoWindow
displayWindow.setVisible(true);
//setup the connection
logger.info("setup dimension :{}",dimension);
StreamClientAgent clientAgent = new StreamClientAgent(new StreamFrameListenerIMPL(),dimension);
clientAgent.connect(new InetSocketAddress("localhost", 20000));
}
protected static class StreamFrameListenerIMPL implements StreamFrameListener{
private volatile long count = 0;
#Override
public void onFrameReceived(BufferedImage image) {
logger.info("frame received :{}",count++);
displayWindow.updateImage(image);
}
}
}
I need a way to go past this error.
Thanks in advance.
your first 2 lines in both files are:
package us.sosia.video.stream.agent;
This means that these files should be in the following path
"/us/sosia/video/stream/agent/"
Remove this line from both files.
I am trying to make a program that uses JFrames and JPanels to construct a voting program. There is a file called voters.txt that is formatted like so:
1234:Herb Weaselman:false
9876:Marge Magnificent:false
4444:Ingmar Inglenook:false
8888:Hector Heroman:false
5678:Agnes Angular:false
In the beginning of my program, I have to ask the user for their voter ID and if their input does not match one of the IDs from the text file, then the program ends. I have managed to achieve this but now I need to overwrite this voters.txt file by changing the false element of whoever voted to true. For instance, if the user entered an ID of 1234, then I would need to change the word after Herb Weaselman to true instead of false. I am not sure how to do this. I know how to write to a file but am not sure how to change that one specific element. Here is the code I have currently:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Scanner;
import java.io.*;
import java.util.ArrayList;
public class Assig5 extends JFrame
{
public Assig5()
{
}
public static void main(String[] args) throws IOException
{
LoginWindow loginWindow = new LoginWindow();
loginWindow.fileReader();
if(!loginWindow.checkResult(loginWindow.result))
{
System.out.println("Invalid Voter ID");
System.exit(0);
}
System.out.println("Continue");
}
}
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Scanner;
import java.io.*;
import java.util.ArrayList;
public class LoginWindow extends JFrame
{
static ArrayList<String> list = new ArrayList<String>();
public String result;
public LoginWindow()
{
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
result = JOptionPane.showInputDialog(frame, "Enter voter ID:");
}
public static void fileReader() throws FileNotFoundException
{
Scanner s = new Scanner(new File("voters.txt"));
while (s.hasNextLine())
{
list.add(s.nextLine());
}
s.close();
}
public static boolean checkResult(String result)
{
for(int i = 0; i < list.size(); i++)
{
String[] retval = list.get(i).split(":");
if(retval[0].equals(result))
{
return true;
}
}
return false;
}
}
Any help would be appreciated. Thanks in advance.
Just change your array index from false to true when there is a match. Then rewrite the file with the data from the array. If there is not match, the file does not change.
Solution
if(retval[0].equals(result)){
retval[2] = true;
return true;
}
I am remaking part of a game in Java, and I need to know how to play the MIDI sound files. Preferably it would not involve importing any external libraries. It must also be runnable in a new thread, so that I can stack the individual sounds over the background song.
Thanks for your thoughts and time.
This code plays two MIDI tracks at the same time (the 2nd sequence starts as soon as the 1st dialog is dismissed). No threads are explicitly created, but I imagine it would work much the same if they were wrapped in a Thread object.
import java.net.URL;
import java.util.Locale;
import javax.sound.midi.MidiDevice;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Receiver;
import javax.sound.midi.Sequence;
import javax.sound.midi.Sequencer;
import javax.sound.midi.Transmitter;
import javax.swing.JOptionPane;
import org.apache.commons.lang.StringUtils;
class PlayMidi {
public static boolean useExternalSynth = false;
public static void main(String[] args) throws Exception {
MidiDevice receivingDevice = getReceivingDevice();
receivingDevice.open();
URL url1 = new URL("http://pscode.org/media/EverLove.mid");
Sequence sequence1 = MidiSystem.getSequence(url1);
Sequencer sequencer1 = MidiSystem.getSequencer(false);
Transmitter tx1 = sequencer1.getTransmitter();
Receiver rx1 = receivingDevice.getReceiver();
tx1.setReceiver(rx1);
sequencer1.open();
sequencer1.setSequence(sequence1);
URL url2 = new URL("http://pscode.org/media/AftrMdnt.mid");
Sequence sequence2 = MidiSystem.getSequence(url2);
Sequencer sequencer2 = MidiSystem.getSequencer(false);
Transmitter tx2 = sequencer2.getTransmitter();
Receiver rx2 = receivingDevice.getReceiver();
tx2.setReceiver(rx2);
sequencer2.open();
sequencer2.setSequence(sequence2);
sequencer1.start();
JOptionPane.showMessageDialog(null, "Everlasting Love");
sequencer2.start();
JOptionPane.showMessageDialog(null, "After Midnight");
}
private static MidiDevice getReceivingDevice()
throws MidiUnavailableException {
for (MidiDevice.Info mdi: MidiSystem.getMidiDeviceInfo()) {
MidiDevice dev = MidiSystem.getMidiDevice(mdi);
if (dev.getMaxReceivers() != 0) {
String lcName =
StringUtils.defaultString(mdi.getName())
.toLowerCase(Locale.ENGLISH);
if (lcName.contains(useExternalSynth? "usb": "java")) {
return dev;
}
}
}
return null;
}
}