Skip to main content

Welcome to Geoff Hayward's Weblog

Commenting on Java, JavaFX, Java EE, Joomla, and IoT.

I have been trying to get the JavaFX MediaPlayer to play MP3s. Each of the MP3s, that I have been trying to play, are being retrieved over HTTPS. The java javafx.scene.media.Media class does not support the HTTPS protocol.

To workaround this problem meant temporarily storing the MP3 on the local disk. And then playing the MP3 from the temporary disk location.

URL url = new URL("https://resource.track.mp3");
        
Path mp3 = Files.createTempFile("now-playing", ".mp3");
        
try (InputStream stream = url.openStream()) {
        Files.copy(stream, mp3, StandardCopyOption.REPLACE_EXISTING);
}

Media media = new Media(mp3.toFile().toURI().toString());
MediaPlayer mediaPlayer = new MediaPlayer(media);
mediaPlayer.play();

Do you know of a better solution or workaround that will skip the need to write to disk when the media file is retrieved over HTTPS? Leave a comment if you do.



Read

I have been keen to use Java on the Intel Edison since hearing that the Edison supports Java. At the time of writing this, I could not find much information on how to use Java with the Edison. So I decided to try and get a simple LED blink program going. While a blink program is very simple, the hello world of hardware, it thought me the important bits about using the Edison with Java.

Here is the blink program in action:

And here is the blink program's code:

import mraa.Gpio;

public class EdisonTest {

    static {
        try {
            System.loadLibrary("mraajava");
        } catch (UnsatisfiedLinkError e) {
            System.err.println("Native code library failed to load.");
            System.exit(1);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Gpio gpio = new Gpio(11);
        gpio.dir(Dir.DIR_OUT);
        int state = 1;

        while (true){
            gpio.write(state);
            state = (state==1?0:1); 
            Thread.sleep(1000);
        }
    } 

}

The command to run the program is java -Djava.library.path=/usr/lib/java/ -jar EdisonTest.jar. I used WinSCP to put the EdisonTest.jar and its lib folder into /home/root/ (where I ran the program from).

If you get any problems check that your manifest file includes the lib folder. And that the lib folder includes the mraa.jar. You can download the mraa.jar and UPM jars from Intel.



Read

During this coming Thursday's Edison Hackathon, at the FabLab, I am hoping to control a robot car by voice. In preparation I have made a JavaFX voice controller UI. And I have put together a 4-wheel drive robot car chassis kit.

The voice controller uses the IBM Watson Speech to Text service. Since recording the video below I have tried commands with context such as "turn left", "reverse the car ". This has had better results. Using phrases, I added regex (word matching) to pull out the commanding verb from the phrase. The commands are then sent as HTTP GET request to whatever IP address and port is given. The Edison will be on the car processing the GET requests via WIFI and acting upon them.



The video below is the running 4-wheel drive robot car chassis kit. To get it working I used an Arduino. I will, of course, swap the Arduino for the Edison before Thursday. The motors are powered by battery, I think the Edison will still be powered by mains (but I am going to seek advice on the day).



As you can see I am all set ready for the FabLab Edison Hackathon: very excited.



Read

Intel have announced that the Edison board now supports Java. This is good news for Java developers.



Read

Here are the photos I took at Devoxx Poland Java conference this year.

 



Read

Mailing List


Responsive Media

With the ResponsiveMedia plugin for Joomla it is easy to add 3rd party content from YouTube, Vimeo, and Instagram right in to any Joomla! article.

ResponsiveMedia