private void recording() { View view = LayoutInflater.Inflate(Resource.Layout.audio_recorder, null); Android.App.AlertDialog builder = new Android.App.AlertDialog.Builder(Activity).Create(); builder.SetView(view); builder.Window.SetLayout(600, 600); builder.SetCanceledOnTouchOutside(false); recordbtn = view.FindViewById <Button>(Resource.Id.recordbtn); stopbtn = view.FindViewById <ImageView>(Resource.Id.stopbtn); playbtn = view.FindViewById <ImageView>(Resource.Id.playbtn); Timer = view.FindViewById <TextView>(Resource.Id.timerbtn); seekBar = view.FindViewById <SeekBar>(Resource.Id.seek_bar); Done_Btn = view.FindViewById <Button>(Resource.Id.donebtn); Done_Btn.Click += delegate { TaskFileMapping_Model attachmentModel = new TaskFileMapping_Model(); long size3 = fileaudioPath.Length() / 1024 * 1024; string audiosize = size3.ToString(); attachmentModel.Path = AudioSavePathInDevice; attachmentModel.FileType = "Audio"; attachmentModel.FileName = audioname; attachmentModel.localtaskId = task_id_to_send; // attachmentModel.file_format = Utility.audiotype; attachmentModel.FileSize = audiosize; // attachmentModel.GeoLocation = geolocation; // attachmentModel.max_numbers = audio_max.ToString(); // db.InsertCreateAttachData(attachmentModel); // comp_AttachmentModels.Add(attachmentModel); listmapping.Add(attachmentModel); //imagelist.AddRange(comp_AttachmentModels.Where(p => p.Attachment_Type == "Image" )); // audio_list = db.GetCreateAttachmentData("Audio", licenceidmodel[0].taskid.ToString()); for (int i = 0; i < listmapping.Count; i++) { if (listmapping[i].FileType.Equals("Audio")) { audio_list.Add(listmapping[i]); } } adapter_3 = new GridAudioCreateTask(Activity, audio_list); Gridview_3.Adapter = adapter_3; Gridview_3.setExpanded(true); Gridview_3.ChoiceMode = (ChoiceMode)AbsListViewChoiceMode.MultipleModal; Gridview_3.SetMultiChoiceModeListener(new MultiChoiceModeListener3(Activity)); audioCount++; builder.Dismiss(); }; recordbtn.Click += delegate { MediaRecorderReady(); try { timer = new Timer(); timer.Interval = 1000; // 1 second timer.Elapsed += Timer_Elapsed; timer.Start(); mediaRecorder.Prepare(); mediaRecorder.Start(); } catch (Exception e) { // TODO Auto-generated catch block //e.printStackTrace(); } Toast.MakeText(Activity, "Recording started", ToastLength.Long).Show(); }; stopbtn.Click += delegate { try { mediaRecorder.Stop(); Timer.Text = "00:00:00"; timer.Stop(); timer = null; } catch (Exception ex) { } //stoprecorder(); //btn2.Enabled=false; //buttonPlayLastRecordAudio.setEnabled(true); //buttonStart.setEnabled(true); //buttonStopPlayingRecording.setEnabled(false); Toast.MakeText(Activity, "Recording completed", ToastLength.Long).Show(); }; //pausebtn.Click += delegate //{ // //OnPause(); // mediaRecorder.Pause(); // timer.Dispose(); //}; playbtn.Click += delegate { mediaPlayer = new MediaPlayer(); mediaPlayer.SetDataSource(AudioSavePathInDevice); mediaPlayer.Prepare(); mediaPlayer.Start(); //mediaPlayer = MediaPlayer.Create(this, Resource.Raw.AudioSavePathInDevice); seekBar.Max = mediaPlayer.Duration; run(); }; //resumebtn.Click += delegate // { // mediaRecorder.Resume(); // timer.Start(); // }; //savebtn.Click += delegate // { // Java.IO.File path = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures); // audiofile = new Java.IO.File(path, "TaskApp"); // if (!audiofile.Exists()) // { // audiofile.Mkdirs(); // } // audioname = Utility.fileName1(); // fileImagePath = new Java.IO.File(audiofile, string.Format(audioname, Guid.NewGuid())); // AudioSavePathInDevice = fileImagePath.AbsolutePath; // mediaRecorder.SetOutputFile(AudioSavePathInDevice); // builder.Dismiss(); // }; builder.Show(); }
public override void OnActivityResult(int requestCode, int resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if (requestCode == Camera && resultCode == (int)Android.App.Result.Ok) { if (!imageURL.Equals("")) { Bitmap bitmap; //Converstion Image Size int height = Resources.DisplayMetrics.HeightPixels; int width = Resources.DisplayMetrics.WidthPixels; using (bitmap = fileImagePath.Path.LoadAndResizeBitmap(width / 4, height / 4)) { } long size1 = fileImagePath.Length() / 1024 * 1024; string imgsize = size1.ToString(); TaskFileMapping_Model attachmentModel = new TaskFileMapping_Model(); attachmentModel.Path = imageURL; attachmentModel.FileType = "Image"; attachmentModel.FileName = imageName; //attachmentModel.localtaskId = licenceidmodel[licenceidmodel.Count - 1].taskid.ToString(); // attachmentModel.file_format = Utility.imagetype; attachmentModel.FileSize = imgsize; // attachmentModel.GeoLocation = geolocation; // attachmentModel.max_numbers = image_max.ToString(); listmapping.Add(attachmentModel); //comp_AttachmentModels.Add(attachmentModel); //imagelist.AddRange(comp_AttachmentModels.Where(p => p.Attachment_Type == "Image" )); //image_list = db.GetCreateAttachmentData("Image", licenceidmodel[licenceidmodel.Count - 1].taskid.ToString()); //for (int i = 0; i < image_list.Count; i++) //{ //} for (int i = 0; i < listmapping.Count; i++) { if (listmapping[i].FileType.Equals("Image")) { image_list.Add(listmapping[i]); } } adapter_1 = new GridImageAdapterCreatetask(Activity, image_list); Gridview_1.Adapter = adapter_1; Gridview_1.setExpanded(true); Gridview_1.ChoiceMode = (ChoiceMode)AbsListViewChoiceMode.MultipleModal; Gridview_1.SetMultiChoiceModeListener(new MultiChoiceModeListener1(Activity)); imageCount++; } } if (requestCode == Video) { if (requestCode == Video && resultCode == (int)Android.App.Result.Ok) { long size2 = fileVideoPath.Length() / 1024; string videosize = size2.ToString(); TaskFileMapping_Model attachmentModel = new TaskFileMapping_Model(); // attachmentModel.Path = videoURL; attachmentModel.FileType = "Video"; attachmentModel.FileName = videoName; attachmentModel.localtaskId = task_id_to_send; attachmentModel.localPath = videoURL; // attachmentModel.file_format = Utility.videotype; attachmentModel.FileSize = videosize; // attachmentModel.GeoLocation = geolocation; // attachmentModel.max_numbers = video_max.ToString(); // db.InsertCreateAttachData(attachmentModel); listmapping.Add(attachmentModel); //comp_AttachmentModels.Add(attachmentModel); for (int i = 0; i < listmapping.Count; i++) { if (listmapping[i].FileType.Equals("Video")) { video_list.Add(listmapping[i]); } } //imagelist.AddRange(comp_AttachmentModels.Where(p => p.Attachment_Type == "Image" )); //video_list = db.GetCreateAttachmentData("Video",licenceidmodel[0].taskid.ToString()); adapter_2 = new GridVideoAdapterCreateTask(Activity, video_list); Gridview_2.Adapter = adapter_2; Gridview_2.setExpanded(true); Gridview_2.ChoiceMode = (ChoiceMode)AbsListViewChoiceMode.MultipleModal; Gridview_2.SetMultiChoiceModeListener(new MultiChoiceModeListener2(Activity)); videoCount++; } } if (requestCode == fileattachment && resultCode == (int)Android.App.Result.Ok) { string filepath = data.Data.Path; String fileName = filepath.Substring(filepath.LastIndexOf("/") + 1); TaskFileMapping_Model attachmentmodel = new TaskFileMapping_Model(); attachmentmodel.Path = filepath; attachmentmodel.FileType = "Attachment"; attachmentmodel.FileName = fileName; listmapping.Add(attachmentmodel); forCreate = new GridAttachmentForCreate(Activity, listmapping); Grid_attach.Adapter = forCreate; Grid_attach.setExpanded(true); } //if (requestCode == Video && resultCode == (int)Android.App.Result.Ok) //{ // if (!videoURL.Equals("")) // { // long size2 = fileVideoPath.Length() / 1024; // string videosize = size2.ToString(); // for (int i = 0; i < listmapping.Count; i++) // { // if (listmapping[i].FileType.Equals("Video")) // { // video_list.Add(listmapping[i]); // } // } // TaskFileMapping_Model attachmentModel = new TaskFileMapping_Model(); // attachmentModel.Path = videoURL; // attachmentModel.FileType = "Video"; // attachmentModel.FileName = audioname; // attachmentModel.localtaskId = task_id_to_send; // attachmentModel.localPath = videoURL; // // attachmentModel.file_format = Utility.videotype; // attachmentModel.FileSize = videosize; // // attachmentModel.GeoLocation = geolocation; // // attachmentModel.max_numbers = video_max.ToString(); // // db.InsertCreateAttachData(attachmentModel); // listmapping.Add(attachmentModel); // // //comp_AttachmentModels.Add(attachmentModel); // //comp_AttachmentModels.Add(attachmentModel); // //imagelist.AddRange(comp_AttachmentModels.Where(p => p.Attachment_Type == "Image" )); // adapter_2 = new GridVideoAdapterCreateTask(Activity, video_list); // Gridview_2.Adapter = adapter_2; // Gridview_2.setExpanded(true); // Gridview_2.ChoiceMode = (ChoiceMode)AbsListViewChoiceMode.MultipleModal; // Gridview_2.SetMultiChoiceModeListener(new MultiChoiceModeListener2(Activity)); // videoCount++; // } //} }