Example usage for javafx.scene.media Media errorProperty

List of usage examples for javafx.scene.media Media errorProperty

Introduction

In this page you can find the example usage for javafx.scene.media Media errorProperty.

Prototype

public ReadOnlyObjectProperty<MediaException> errorProperty() 

Source Link

Usage

From source file:com.tesshu.subsonic.client.sample4_music_andmovie.StreamPlayApplication.java

@Override
public void start(Stage stage) throws Exception {

    Search2Controller search2 = context.getBean(Search2Controller.class);

    StreamController streamController = context.getBean(StreamController.class);

    SuccessObserver callback = context.getBean(SuccessObserver.class);

    SearchResult2 result2 = search2.get("t", null, null, null, null, 1, null, null);

    Child song = result2.getSongs().get(0);

    final IRequestUriObserver uriCallBack = (subject, uri) -> {
        uriStr = uri.toString();/*from  w w  w. java 2 s  .c o  m*/
    };

    streamController.stream(song, 128, // maxBitRate
            format, // format
            null, // timeOffset
            null, // size(Do not use it for video)
            true, // estimateContentLength
            null, // converted(Do not use it for video)
            null, // streamCallback
            uriCallBack, callback);

    Group root = new Group();
    Scene scene = new Scene(root, 640, 480);
    Media media = new Media(uriStr);
    media.errorProperty().addListener((observable, old, cur) -> {
        LOG.info(cur + " : " + uriStr);
    });

    MediaPlayer player = new MediaPlayer(media);
    player.statusProperty().addListener((observable, old, cur) -> {
        LOG.info(cur + " : " + uriStr);
    });

    MediaView view = new MediaView(player);
    ((Group) scene.getRoot()).getChildren().add(view);
    stage.setScene(scene);
    stage.show();
    player.play();

}

From source file:com.tesshu.subsonic.client.sample4_music_andmovie.StreamPlayMovieApplication.java

@Override
public void start(Stage stage) throws Exception {

    Search2Controller search2 = context.getBean(Search2Controller.class);

    StreamController streamController = context.getBean(StreamController.class);

    SuccessObserver callback = context.getBean(SuccessObserver.class);

    SearchResult2 result2 = search2.get("CORPSE BRIDE", // query, required = true
            0, // artistCount, required = false
            null, // artistOffset, required = false
            0, // albumCount, required = false
            null, // albumOffset, required = false
            10, // songCount, required = false
            null, // songOffset, required = false
            null // musicFolderId, required = false
    );// ww  w. ja v  a  2  s.  c om

    Child movie = result2.getSongs().stream().filter(child -> MediaType.VIDEO == child.getType())
            .filter(child -> format.equals(child.getSuffix())).collect(Collectors.toSet()).iterator().next();

    LOG.info(ToStringBuilder.reflectionToString(movie, ToStringStyle.MULTI_LINE_STYLE));

    // not valid?(Perhaps, I have not done convert setting on the server side)
    @SuppressWarnings("unused")
    String size = Integer.toString(movie.getOriginalWidth()) + "x"
            + Integer.toString(movie.getOriginalHeight());

    final IRequestUriObserver uriCallBack = (subject, uri) -> {
        uriStr = uri.toString();
    };

    streamController.stream(

            movie, // id
            null, // maxBitRate
            format, // format
            null, // timeOffset
            null, // size
            true, // estimateContentLength
            false, // converted
            null, // streamCallback
            uriCallBack, callback);

    Group root = new Group();
    Scene scene = new Scene(root, movie.getOriginalWidth(), movie.getOriginalHeight());
    Media media = new Media(uriStr);
    media.errorProperty().addListener((observable, old, cur) -> {
        LOG.info(cur + " : " + uriStr);
    });

    MediaPlayer player = new MediaPlayer(media);
    player.statusProperty().addListener((observable, old, cur) -> {
        LOG.info(cur + " : " + uriStr);
    });

    MediaView view = new MediaView(player);
    ((Group) scene.getRoot()).getChildren().add(view);
    stage.setScene(scene);
    stage.show();
    player.play();

}

From source file:com.tesshu.subsonic.client.sample4_music_andmovie.StreamDownloadAndPlayWithThreadApplication.java

@Override
public void start(Stage stage) throws Exception {

    Search2Controller search2 = context.getBean(Search2Controller.class);

    StreamController streamController = context.getBean(StreamController.class);

    SuccessObserver callback = context.getBean(SuccessObserver.class);

    SearchResult2 result2 = search2.get("e", null, null, null, null, 1, null, null);

    List<Child> songs = result2.getSongs();

    File tmpDirectory = new File(tmpPath);
    tmpDirectory.mkdir();//ww  w  .  j  a v  a  2  s  . com

    int maxBitRate = 256;

    Child song = songs.get(0);

    new Thread(new Runnable() {
        public void run() {
            try {

                streamController.stream(song, maxBitRate, format, null, null, null, null,

                        (subject, inputStream, contentLength) -> {

                            File dir = new File(
                                    tmpPath + "/" + song.getPath().replaceAll("([^/]+?)?$", StringUtils.EMPTY));
                            dir.mkdirs();

                            file = new File(tmpPath + "/"
                                    + song.getPath().replaceAll("([^.]+?)?$", StringUtils.EMPTY) + format);

                            try {

                                FileOutputStream fos = new FileOutputStream(file);
                                BufferedInputStream reader = new BufferedInputStream(inputStream);

                                byte buf[] = new byte[256];
                                int len;
                                while ((len = reader.read(buf)) != -1) {
                                    fos.write(buf, 0, len);
                                }
                                fos.flush();
                                fos.close();
                                reader.close();
                                inputStream.close();

                                LOG.info("download finished");

                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }, callback);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }).start();

    LOG.info("download thread start");

    new Thread(new Runnable() {
        public void run() {
            while (file == null || file.getPath() == null) {
                LOG.info("wait file writing.");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                String path = Paths.get(file.getPath()).toUri().toString();
                Group root = new Group();
                Scene scene = new Scene(root, 640, 480);
                Media media = new Media(path);
                MediaPlayer player = new MediaPlayer(media);
                new Thread(new Runnable() {
                    public void run() {
                        try {
                            while (MediaPlayer.Status.READY != player.getStatus()) {
                                LOG.info(player.getStatus() + " : " + path);
                                LOG.info(media.errorProperty());
                                Thread.sleep(1000);
                                if (MediaPlayer.Status.PLAYING == player.getStatus()) {
                                    LOG.info(player.getStatus() + " : " + path);
                                    break;
                                }
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }).start();

                MediaView view = new MediaView(player);
                ((Group) scene.getRoot()).getChildren().add(view);

                Platform.runLater(() -> {
                    stage.setScene(scene);
                    stage.show();
                    player.play();
                });

            }
        }
    }).start();

}