Mobile App Development
Name: Abdullah Hashmi
Roll Number: BSSE-E2-20-30
Submitted to: Sir M. Yousuf
Assignment No:03
Media Recorder:
Make a new activity with help of android studio name of file is media class use
Kotin Language in itb and design with help of xml page add 2 button with start and
stop recording phase. Here is a basic Android Application code in Kotlin using
Media Recorder to record video with microphone and camera.
Main activity code of recorder media application with access of microphone
and camera.
import [Link]. MediaRecorder
import [Link]
Import [Link]
[Link] import [Link]
import [Link] class MainActivity: AppCompatActivity()
{ private var mediaRecorder:MediaRecorder?=null private var isRecording-false
onCreate(savedinstanceState: Bundle?){
override fn [Link](savedInstanceState)
setContentView([Link].activity_main)
val startButton= findViewById<Button>
([Link].start_buutton) val
stopButton= findViewById<Button>([Link].stop_button)
[Link]{
if(!IsRecording){
stopRecording()
privatefun startRecording(){
media Recorder=MediaRecorder().apply{
setAudioSource(MediaRecorder. [Link])
setVideoSource(MediaRecorder. [Link])
setOutputFormat([Link].MPEG_4)
setAudioEncoder([Link])
set Video Recoder(MediaRecorder. VideoEncoder.H264)
setOutputFile(File(getExternalFilesDir(null), "recorded_
video.mp4").absolutePath)
prepare()
start()
IsRecordeing-true
[Link](this, "Recoding started", Toast.Length_Short).show()
}
private fun stopRecording(){ mediaRecorder?.apply{
stop()
release()
media Recorder=null
isRecording-false
[Link](this, "Recording
stopped", Toast.(Length_Short).show()
Note: This code requires necessary permission of the microphone and a camera.
Add the following to your [Link] file