Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.pojosontheweb.selenium;
  
  
  import java.awt.*;
 import java.io.File;
 import java.util.List;
 
 import static org.monte.media.AudioFormatKeys.*;
 import static org.monte.media.VideoFormatKeys.*;

Records the screen to a .mov file.
 
 public class ScreenRecordr {
 
     private ScreenRecorder screenRecorder = null;
 
     public ScreenRecordr start() {
 
         try {
 
             if ( == null) {
 
                 //Create a instance of GraphicsConfiguration to get the Graphics configuration
                 //of the Screen. This is needed for ScreenRecorder class.
                 GraphicsConfiguration gc = GraphicsEnvironment//
                         .getLocalGraphicsEnvironment()//
                         .getDefaultScreenDevice()//
                         .getDefaultConfiguration();
 
                 //Create a instance of ScreenRecorder with the required configurations
                  = new ScreenRecorder(
                         gc,
                         new Format(
                                 ,
                                 ..,
                                 ),
                         new Format(,
                                 ..,
                                 ,
                                 ,
                                 ,
                                 ,
 //                                COMPRESSOR_NAME_QUICKTIME_JPEG,
                                 ,
                                 24,
                                 ,
                                 Rational.valueOf(15),
                                 ,
                                 0.5f,
                                 ,
                                 15 * 60),
                         new Format(
                                 ,
                                 ..,
                                 ,
                                 "black",
                                 ,
                                 Rational.valueOf(30)),
                         null);
             }
 
             if (!.getState().equals(..)) {
                 .start();
             }
 
             Findr.logDebug("[ScreenRecordr] started video recording");
             return this;
 
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
     }
 
     public void stop() {
         if (==null) {
             return;
         }
         try {
             if (.getState()!=null && .getState().equals(..)) {
                 Findr.logDebug("[ScreenRecordr] stopping recorder");
                 .stop();
             }
             Findr.logDebug("[ScreenRecordr] stopped video recording. List of created files :");
             for (File f : getVideoFiles()) {
                 Findr.logDebug("[ScreenRecordr]  * " + f.getAbsolutePath());
             }
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
     }
 
    public List<FilegetVideoFiles() {
        if ( == null) {
            return Collections.emptyList();
        }
        return .getCreatedMovieFiles();
    }
    public ScreenRecordr moveVideoFilesTo(File destDirString filePrefix) {
        stop();
        List<Filefiles = getVideoFiles();
        Findr.logDebug("[ScreenRecordr] moving " + files.size() + " video files to " + destDir +
                " with filePrefix=" + filePrefix);
        int totalCount = 1;
        boolean needsCount = files.size()>1;
        for (File f : files) {
            if (f.exists()) {
                String fileName = filePrefix;
                if (needsCount) {
                    fileName += "-" + totalCount++;
                }
                fileName += ".mov";
                if (!destDir.exists()) {
                    destDir.mkdirs();
                }
                File vidFile = new File(destDirfileName);
                try {
                    Files.copy(fvidFile);
                    Findr.logDebug("[ScreenRecordr] " + f.getAbsolutePath() + " => " + vidFile.getAbsolutePath());
                } catch(IOException e) {
                    throw new RuntimeException(e);
                } finally {
                    f.delete();
                }
            }
        }
        return this;
    }
    public ScreenRecordr removeVideoFiles() {
        Findr.logDebug("[ScreenRecordr] removing video files");
        stop();
        List<Filefiles = getVideoFiles();
        for (File f : files) {
            f.delete();
        }
        return this;
    }
New to GrepCode? Check out our FAQ X