Friday, April 26, 2019

Screen recorder by using Monte recorder

 package video;  
 import static org.monte.media.FormatKeys.EncodingKey;  
 import static org.monte.media.FormatKeys.FrameRateKey;  
 import static org.monte.media.FormatKeys.KeyFrameIntervalKey;  
 import static org.monte.media.FormatKeys.MIME_QUICKTIME;  
 import static org.monte.media.FormatKeys.MediaTypeKey;  
 import static org.monte.media.FormatKeys.MimeTypeKey;  
 import static org.monte.media.VideoFormatKeys.CompressorNameKey;  
 import static org.monte.media.VideoFormatKeys.DepthKey;  
 import static org.monte.media.VideoFormatKeys.ENCODING_QUICKTIME_JPEG;  
 import static org.monte.media.VideoFormatKeys.QualityKey;  
 import java.awt.Dimension;  
 import java.awt.GraphicsConfiguration;  
 import java.awt.GraphicsEnvironment;  
 import java.awt.Rectangle;  
 import java.awt.Toolkit;  
 import java.io.File;  
 import org.monte.media.Format;  
 import org.monte.media.FormatKeys.MediaType;  
 import org.monte.media.math.Rational;  
 import org.monte.screenrecorder.ScreenRecorder;  
 public class VedioOne {  
      private static ScreenRecorder screenRecorder;  
      public static final String USER_DIR = "user.dir";  
      public static final String DOWNLOADED_FILES_FOLDER = "videos";  
      public static void start() throws Exception{  
           File file = new File(System.getProperty(USER_DIR) + File.separator + DOWNLOADED_FILES_FOLDER);  
           Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();  
           int width = screenSize.width;  
           int height = screenSize.height;  
           Rectangle captureSize = new Rectangle(0, 0, width, height);  
           GraphicsConfiguration gc = GraphicsEnvironment  
                     .getLocalGraphicsEnvironment().getDefaultScreenDevice()  
                     .getDefaultConfiguration();  
                     // Create a instance of ScreenRecorder with the required configurations  
                     screenRecorder = new ScreenRecorder(gc,captureSize, new Format(MediaTypeKey,MediaType.FILE, MimeTypeKey, MIME_QUICKTIME),  
                     new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey,ENCODING_QUICKTIME_JPEG, CompressorNameKey,  
                     ENCODING_QUICKTIME_JPEG, DepthKey, (int) 24,FrameRateKey, Rational.valueOf(15), QualityKey, 1.0f,  
                     KeyFrameIntervalKey, (int) (15 * 60)),  
                     new Format(MediaTypeKey,MediaType.VIDEO, EncodingKey, "black", FrameRateKey,Rational.valueOf(30)),  
                     null,file);  
                     // Call the start method of ScreenRecorder to begin recording  
                     screenRecorder.start();  
      }  
      public static void stop() throws Exception{  
           screenRecorder.stop();  
      }  
 }  
 <dependency>  
   <groupId>com.github.stephenc.monte</groupId>  
   <artifactId>monte-screen-recorder</artifactId>  
   <version>0.7.7.0</version>  
 </dependency>  
 package seleniumWebdriver;  
 import java.awt.Robot;  
 import java.awt.event.KeyEvent;  
 import org.testng.annotations.Test;  
 import takescreenshot.BaseClass;  
 import video.VedioOne;  
 public class RobotExample extends BaseClass {  
      @Test  
      public void open() throws Exception{  
           //Start recorder  
           VedioOne.start();  
           driver.navigate().to("https://www.youtube.com/");  
           Robot robot=new Robot();  
           robot.keyPress(KeyEvent.VK_TAB);  
           Thread.sleep(2000);  
           robot.keyPress(KeyEvent.VK_TAB);  
           Thread.sleep(2000);  
           robot.keyPress(KeyEvent.VK_TAB);  
           Thread.sleep(2000);  
           robot.keyPress(KeyEvent.VK_TAB);  
           Thread.sleep(2000);  
           robot.keyPress(KeyEvent.VK_ENTER);  
           Thread.sleep(2000);  
           driver.close();  
           //Stop recorder  
           VedioOne.stop();  
      }  
 }  

No comments:

Post a Comment