Examples of MediaPlayerFactory


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

    /**
     * Construct a media list player component.
     */
    public EmbeddedMediaListPlayerComponent() {
        // Create the native resources
        MediaPlayerFactory mediaPlayerFactory = getMediaPlayerFactory();
        mediaListPlayer = mediaPlayerFactory.newMediaListPlayer();
        mediaList = mediaPlayerFactory.newMediaList();
        mediaListPlayer.setMediaList(mediaList);
        mediaListPlayer.setMediaPlayer(getMediaPlayer());
        // Register listeners
        mediaListPlayer.addMediaListPlayerEventListener(this);
        // Sub-class initialisation
View Full Code Here

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

     * method.
     *
     * @return media player factory
     */
    protected MediaPlayerFactory onGetMediaPlayerFactory() {
        return new MediaPlayerFactory(onGetMediaPlayerFactoryArgs());
    }
View Full Code Here

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

     * method.
     *
     * @return media player factory
     */
    protected MediaPlayerFactory onGetMediaPlayerFactory() {
        return new MediaPlayerFactory(onGetMediaPlayerFactoryArgs());
    }
View Full Code Here

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

    /**
     * Construct a media list player component.
     */
    public AudioMediaListPlayerComponent() {
        // Create the native resources
        MediaPlayerFactory mediaPlayerFactory = getMediaPlayerFactory();
        mediaListPlayer = mediaPlayerFactory.newMediaListPlayer();
        mediaList = mediaPlayerFactory.newMediaList();
        mediaListPlayer.setMediaList(mediaList);
        mediaListPlayer.setMediaPlayer(getMediaPlayer());
        // Register listeners
        mediaListPlayer.addMediaListPlayerEventListener(this);
        // Sub-class initialisation
View Full Code Here

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

            System.exit(1);
        }

        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

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

        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

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

        if(args.length != 1) {
            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 + ")");
            }
View Full Code Here

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

            System.exit(1);
        }

        Logger.setLevel(Logger.Level.INFO);

        MediaPlayerFactory factory = new MediaPlayerFactory();

        List<File> files = new ArrayList<File>(400);
        for(String arg : args) {
            files.addAll(scan(new File(arg)));
        }

        // Dump out the meta
        for(File file : files) {
            String mrl = file.getAbsolutePath();
            MediaMeta meta = factory.getMediaMeta(mrl, true);
            Logger.info("{} -> {}", mrl, meta);
            meta.release();
        }

        // Dump out only the title and the length
        for(File file : files) {
            String mrl = file.getAbsolutePath();
            MediaMeta meta = factory.getMediaMeta(mrl, true);
            Logger.info("{} -> {}ms", meta.getTitle(), meta.getLength());
            meta.release();
        }

        factory.release();
    }
View Full Code Here

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

        frame.setContentPane(contentPane);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocation(50, 50);
        frame.setSize(800, 600);

        factory = new MediaPlayerFactory();
        mediaPlayer = factory.newEmbeddedMediaPlayer();

        videoSurface = factory.newVideoSurface(canvas);

        mediaPlayer.setVideoSurface(videoSurface);
View Full Code Here

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

        }

        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
TOP
Copyright © 2018 www.massapi.com. 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.