Advertisement
TermSpar

Screen Recorder Implemented

Dec 8th, 2018
6,036
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Diagnostics;
  11.  
  12. namespace BenScreenRecorder
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         public Form1()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         // Filing variables:
  22.         string outputPath = "";
  23.         bool pathSelected = false;
  24.         string finalVidName = "FinalVideo.mp4";
  25.  
  26.         // Screen recorder object:
  27.         ScreenRecorder screenRec = new ScreenRecorder(new Rectangle(), "");
  28.  
  29.         private void button4_Click(object sender, EventArgs e)
  30.         {
  31.             //Create output path:
  32.             FolderBrowserDialog folderBrowser = new FolderBrowserDialog();
  33.             folderBrowser.Description = "Select an Output Folder";
  34.  
  35.             if (folderBrowser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  36.             {
  37.                 outputPath = @folderBrowser.SelectedPath;
  38.                 pathSelected = true;
  39.  
  40.                 //Finish screen recorder object:
  41.                 Rectangle bounds = Screen.FromControl(this).Bounds;
  42.                 screenRec = new ScreenRecorder(bounds, outputPath);
  43.             }
  44.             else
  45.             {
  46.                 MessageBox.Show("Please select an output folder.", "Error");
  47.             }
  48.         }
  49.  
  50.         private void button1_Click(object sender, EventArgs e)
  51.         {
  52.             bool containsMP4 = finalVidName.Contains(".mp4");
  53.  
  54.             if (pathSelected && containsMP4)
  55.             {
  56.                 screenRec.setVideoName(finalVidName);
  57.                 tmrRecord.Start();
  58.                 pbRec.Show();
  59.             }
  60.             else if(!pathSelected && containsMP4)
  61.             {
  62.                 MessageBox.Show("You must select an output path first", "Error");
  63.             }
  64.             else if(pathSelected && !containsMP4)
  65.             {
  66.                 MessageBox.Show("You must select video name that ends in '.mp4'", "Error");
  67.                 txtSetName.Text = "FinalVideo.mp4";
  68.                 finalVidName = "FinalVideo.mp4";
  69.             }
  70.             else
  71.             {
  72.                 MessageBox.Show("You must select video name that ends in '.mp4' " +
  73.                     "and you must select an output path", "Error");
  74.                 txtSetName.Text = "FinalVideo.mp4";
  75.                 finalVidName = "FinalVideo.mp4";
  76.             }
  77.         }
  78.  
  79.         private void tmrRecord_Tick(object sender, EventArgs e)
  80.         {
  81.             screenRec.RecordVideo();
  82.             screenRec.RecordAudio();
  83.             lblTimer.Text = screenRec.getElapsed();
  84.         }
  85.  
  86.         private void Form1_Load(object sender, EventArgs e)
  87.         {
  88.             pbRec.Hide();
  89.         }
  90.  
  91.         private void button2_Click(object sender, EventArgs e)
  92.         {
  93.             tmrRecord.Stop();
  94.             screenRec.Stop();
  95.             pbRec.Hide();
  96.             Application.Restart();
  97.         }
  98.  
  99.         private void txtSetName_TextChanged(object sender, EventArgs e)
  100.         {
  101.             finalVidName = txtSetName.Text;
  102.         }
  103.  
  104.         private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  105.         {
  106.             screenRec.cleanUp();
  107.         }
  108.  
  109.     }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement