Package uk.co.caprica.vlcj.player

Examples of uk.co.caprica.vlcj.player.MediaPlayer


            System.err.println("Specify an MRL");
            System.exit(1);
        }

        MediaPlayerFactory factory = new MediaPlayerFactory();
        MediaPlayer mediaPlayer = factory.newEmbeddedMediaPlayer();
        mediaPlayer.addMediaPlayerEventListener(new MediaPlayerEventAdapter() {
            @Override
            public void snapshotTaken(MediaPlayer mediaPlayer, String filename) {
                System.out.println("snapshotTaken(filename=" + filename + ")");
            }
        });

        mediaPlayer.startMedia(args[0]);

        mediaPlayer.setPosition(0.25f);
        Thread.sleep(1000); // Don't do this, use events instead

        // I might get around to this some day
        // mediaPlayer.saveSnapshot();
        // mediaPlayer.saveSnapshot(200, 300);

        File file3 = new File("vlcj-snapshot1.png");
        file3.deleteOnExit();
        mediaPlayer.saveSnapshot(file3);
        BufferedImage image3 = ImageIO.read(file3);

        File file4 = new File("vlcj-snapshot2.png");
        file4.deleteOnExit();
        mediaPlayer.saveSnapshot(file4, 500, 0);
        BufferedImage image4 = ImageIO.read(file4);

        BufferedImage image5 = mediaPlayer.getSnapshot();
        BufferedImage image6 = mediaPlayer.getSnapshot(300, 600);

        show("Named file saveSnapshot", image3, 3);
        show("Named file sized saveSnapshot", image4, 4);
        show("Image getSnapshot", image5, 5);
        show("Image sized getSnapshot", image6, 6);

        mediaPlayer.stop();
    }
View Full Code Here


        String mrl = args[0];
        int imageWidth = Integer.parseInt(args[1]);
        File snapshotFile = new File(args[2]);

        MediaPlayerFactory factory = new MediaPlayerFactory(VLC_ARGS);
        MediaPlayer mediaPlayer = factory.newHeadlessMediaPlayer();

        final CountDownLatch inPositionLatch = new CountDownLatch(1);
        final CountDownLatch snapshotTakenLatch = new CountDownLatch(1);

        mediaPlayer.addMediaPlayerEventListener(new MediaPlayerEventAdapter() {

            @Override
            public void positionChanged(MediaPlayer mediaPlayer, float newPosition) {
                if(newPosition >= VLC_THUMBNAIL_POSITION * 0.9f) { /* 90% margin */
                    inPositionLatch.countDown();
                }
            }

            @Override
            public void snapshotTaken(MediaPlayer mediaPlayer, String filename) {
                System.out.println("snapshotTaken(filename=" + filename + ")");
                snapshotTakenLatch.countDown();
            }
        });

        if(mediaPlayer.startMedia(mrl)) {
            mediaPlayer.setPosition(VLC_THUMBNAIL_POSITION);
            inPositionLatch.await(); // Might wait forever if error

            mediaPlayer.saveSnapshot(snapshotFile, imageWidth, 0);
            snapshotTakenLatch.await(); // Might wait forever if error

            mediaPlayer.stop();
        }

        mediaPlayer.release();
        factory.release();
    }
View Full Code Here

        final String mrl = args[0];
        final int period = Integer.parseInt(args[1]) * 1000;

        MediaPlayerFactory factory = new MediaPlayerFactory(VLC_ARGS);
        MediaPlayer mediaPlayer = factory.newHeadlessMediaPlayer();

        mediaPlayer.setSnapshotDirectory(new File(".").getAbsolutePath());

        // The sequence for creating the snapshots is...
        //
        // Start the media
        // Wait until playing
        // Loop...
        //  Set the target time
        //  Wait until the target time is reached
        //  Pause the media player
        //  Wait until paused
        //  Save the snapshot
        //  Wait until snapshot taken
        //  Play the media player
        //
        // The media player must be playing or else the required time changed events
        // will not be fired.

        try {
            Condition<?> playingCondition = new PlayingCondition(mediaPlayer) {
                @Override
                protected boolean onBefore() {
                    // You do not have to use onBefore(), but sometimes it is very convenient, and guarantees
                    // that the required media player event listener is added before your condition is tested
                    mediaPlayer.startMedia(mrl);
                    return true;
                }
            };
            playingCondition.await();

            long time = period;

            for(int i = 0; ; i++) {

                // Some special cases here...
                //
                // 1. The duration may not be available yet, even if the media player is playing
                // 2. For some media types it is not possible to set the position past the end - this
                //    means that you would have to wait for playback to reach the end normally
                long duration = mediaPlayer.getLength();
                if(duration > 0 && time >= duration) {
                    break;
                }

                System.out.println("Snapshot " + i);

                Condition<?> timeReachedCondition = new TimeReachedCondition(mediaPlayer, time) {
                    @Override
                    protected boolean onBefore() {
                        mediaPlayer.setTime(targetTime);
                        return true;
                    }
                };
                timeReachedCondition.await();

                Condition<?> pausedCondition = new PausedCondition(mediaPlayer) {
                    @Override
                    protected boolean onBefore() {
                        mediaPlayer.pause();
                        return true;
                    }
                };
                pausedCondition.await();

                Condition<?> snapshotTakenCondition = new SnapshotTakenCondition(mediaPlayer) {
                    @Override
                    protected boolean onBefore() {
                        mediaPlayer.saveSnapshot();
                        return true;
                    }
                };
                snapshotTakenCondition.await();

                playingCondition = new PlayingCondition(mediaPlayer) {
                    @Override
                    protected boolean onBefore() {
                        mediaPlayer.play();
                        return true;
                    }
                };
                playingCondition.await();

                time += period;
            }
        }
        catch(UnexpectedErrorConditionException e) {
            System.out.println("ERROR!");
        }
        catch(UnexpectedFinishedConditionException e) {
            System.out.println("FINISHED!");
        }

        System.out.println("All done");

        mediaPlayer.release();
        factory.release();
    }
View Full Code Here

            System.out.println("Specify a channels.conf file");
            System.exit(1);
        }

        final MediaPlayerFactory factory = new MediaPlayerFactory();
        final MediaPlayer mediaPlayer = factory.newHeadlessMediaPlayer();

        mediaPlayer.addMediaPlayerEventListener(new MediaPlayerEventAdapter() {
            @Override
            public void finished(MediaPlayer mediaPlayer) {
                int subItemCount = mediaPlayer.subItemCount();
                System.out.println("subItemCount=" + subItemCount);

                System.out.println("Getting sub-items...");

                List<String> subItems = mediaPlayer.subItems();
                for(String subItem : subItems) {
                    System.out.println(subItem);
                }

                System.out.println("Getting sub-item meta data...");

                List<MediaMeta> metas = mediaPlayer.getSubItemMediaMeta();
                for(MediaMeta meta : metas) {
                    System.out.println("title -> " + meta.getTitle());
                }

                System.out.println("Done.");

                mediaPlayer.release();
                factory.release();
                System.exit(0);
            }
        });

        mediaPlayer.playMedia(args[0]);

        Thread.currentThread().join();
    }
View Full Code Here

            System.out.println("Specify an MRL");
            System.exit(1);
        }

        MediaPlayerFactory factory = new MediaPlayerFactory();
        MediaPlayer mediaPlayer = factory.newHeadlessMediaPlayer();

        mediaPlayer.addMediaPlayerEventListener(new MediaPlayerEventAdapter() {
            @Override
            public void videoOutput(MediaPlayer mediaPlayer, int newCount) {
                System.out.println("     Track Information: " + mediaPlayer.getTrackInfo());
                System.out.println("    Title Descriptions: " + mediaPlayer.getTitleDescriptions());
                System.out.println("    Video Descriptions: " + mediaPlayer.getVideoDescriptions());
                System.out.println("    Audio Descriptions: " + mediaPlayer.getAudioDescriptions());
                for(int i = 0; i < mediaPlayer.getTitleDescriptions().size(); i ++ ) {
                    System.out.println("Chapter Descriptions " + i + ": " + mediaPlayer.getChapterDescriptions(i));
                }
            }
        });

        mediaPlayer.prepareMedia(args[0]);

        mediaPlayer.parseMedia();

        mediaPlayer.start();

        try {
            Thread.sleep(3000);
        }
        catch(InterruptedException e) {
        }

        System.out.println("Track Information before end: " + mediaPlayer.getTrackInfo());

        System.out.println("    UNKNOWN: " +  mediaPlayer.getTrackInfo(TrackType.UNKNOWN));
        System.out.println("      AUDIO: " +  mediaPlayer.getTrackInfo(TrackType.AUDIO));
        System.out.println("      VIDEO: " +  mediaPlayer.getTrackInfo(TrackType.VIDEO));
        System.out.println("       TEXT: " +  mediaPlayer.getTrackInfo(TrackType.TEXT));
        System.out.println("AUDIO+VIDEO: " +  mediaPlayer.getTrackInfo(TrackType.AUDIO, TrackType.VIDEO));

        mediaPlayer.stop();

        mediaPlayer.release();
        factory.release();
    }
View Full Code Here

        }

        final String mrl = args[0];

        MediaPlayerFactory factory = new MediaPlayerFactory(VLC_ARGS);
        MediaPlayer mediaPlayer = factory.newHeadlessMediaPlayer();

        mediaPlayer.setSnapshotDirectory(new File(".").getAbsolutePath());

        // The sequence for getting the meta is...
        //
        // Start the media and wait for it to play
        // Wait for parsed condition
        //
        // There is a small overhead of actually having to start the media - but
        // to mitigate this the media player factory configuration has disabled
        // audio and video outputs so there will be no visible/audible sign of
        // the media playing

        Condition<Integer> parsedCondition = new ParsedCondition(mediaPlayer) {
            @Override
            protected boolean onBefore() {
                // Some media, such as mpg, must be played before all meta data (e.g. duration) is available
                mediaPlayer.startMedia(mrl); // "start" waits until the media is playing before returning
                mediaPlayer.requestParseMedia(); // asynchronous invocation
                return true;
            }

            @Override
            protected void onAfter(Integer result) {
                mediaPlayer.stop();
            }
        };
        parsedCondition.await();

        // This is functionally equivalent to the simpler synchronous version:
        /*
        mediaPlayer.startMedia(mrl);  // "start" waits until the media is playing before returning
        mediaPlayer.parseMedia(); // synchronous invocation
        mediaPlayer.stop();
        */

        System.out.println(mediaPlayer.getMediaMeta());

        mediaPlayer.release();
        factory.release();
    }
View Full Code Here

TOP

Related Classes of uk.co.caprica.vlcj.player.MediaPlayer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.