![]()
![How to Record a Video Using Angular]()
Here I recorded a video using MediaRecorder in Angular, So for that follow the below steps for a practical example.
Step 1
Install the @types/dom-mediacapture-record using below npm command
No need to import this package into the app.module.ts file, We can directly use in our component.
Step 2
Add the below code to your tsconfig.json file for avoiding some elements-related errors.
tsconfig.json
If you have already added then avoid it.
Step 3
Now need to import some basic packages from @angular/core and declare the MediaRecorder variable into the component where you want to use it.
Here I am using the app.component.ts file
Let's share the whole ts file code, Please refer to the below app.component.ts file code
Put the same code in your component and verify once it is the correct one.
Here I have created some functions regarding our video recording functionality, and If you want to try other mime types then you can use them according to your requirement,
Refer to the below support mime types:
Step 4
Put the HTML code as shown below
app.component,html
If you want to get a better UI then please add the below script to your main index.html, Here I am sharing the whole index.html code you can use only CSS and js.
index.html
Let's save and run the app, Browser asks for your camera access give them.
Output
![How to Record a Video Using Angular]()
It looks like this and then click on Start Recording to start and Stop Recording to stop it. Once your recorder has done your recorded video show on right side, See below screenshot
![How to Record a Video Using Angular]()
You can play your recorded video by clicking on the play/pause icon.
Here I have attached the source code of this app so you can download it and for more blogs/articles follow my blog website which is mentioned in my C# Corner Profile.