Example usage for javafx.collections MapChangeListener MapChangeListener

List of usage examples for javafx.collections MapChangeListener MapChangeListener

Introduction

In this page you can find the example usage for javafx.collections MapChangeListener MapChangeListener.

Prototype

MapChangeListener

Source Link

Usage

From source file:Main.java

public static void main(String[] args) {
    Map<String, String> map = new HashMap<String, String>();
    ObservableMap<String, String> observableMap = FXCollections.observableMap(map);
    observableMap.addListener(new MapChangeListener() {
        @Override//from   ww w.j a va 2  s  .c  o m
        public void onChanged(MapChangeListener.Change change) {
            System.out.println("change! ");
        }
    });
    observableMap.put("key 1", "value 1");
    map.put("key 2", "value 2");

}

From source file:Main.java

private void createMedia() {
    try {//from ww w  .  j  ava  2  s .co m
        media = new Media("http://traffic.libsyn.com/dickwall/JavaPosse373.mp3");
        media.getMetadata().addListener(new MapChangeListener<String, Object>() {
            @Override
            public void onChanged(Change<? extends String, ? extends Object> ch) {
                if (ch.wasAdded()) {
                    handleMetadata(ch.getKey(), ch.getValueAdded());
                }
            }
        });

        mediaPlayer = new MediaPlayer(media);
        mediaPlayer.setOnError(new Runnable() {
            @Override
            public void run() {
                final String errorMessage = media.getError().getMessage();
                // Handle errors during playback
                System.out.println("MediaPlayer Error: " + errorMessage);
            }
        });

        mediaPlayer.play();

    } catch (RuntimeException re) {
        // Handle construction errors
        System.out.println("Caught Exception: " + re.getMessage());
    }
}

From source file:AudioPlayer3.java

private void initializeMedia(String url) {
    resetProperties();/*  ww w.  ja va2  s. c  om*/

    try {
        final Media media = new Media(url);
        media.getMetadata().addListener(new MapChangeListener<String, Object>() {
            @Override
            public void onChanged(Change<? extends String, ? extends Object> ch) {
                if (ch.wasAdded()) {
                    handleMetadata(ch.getKey(), ch.getValueAdded());
                }
            }
        });

        mediaPlayer.setValue(new MediaPlayer(media));
        mediaPlayer.get().setOnError(new Runnable() {
            @Override
            public void run() {
                String errorMessage = mediaPlayer.get().getError().getMessage();
                // Handle errors during playback
                System.out.println("MediaPlayer Error: " + errorMessage);
            }
        });
    } catch (RuntimeException re) {
        // Handle construction errors
        System.out.println("Caught Exception: " + re.getMessage());
    }
}