how to play recorded video within same view after recording pause?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am using mediaRecorder to record video.
I am able to start , pause, resume and stop recording .
I want to play recorded video within same page instead of going back to SD card where it is saved.
Can Anyone help for this.
There are solutions where video is saved in sd card and playing by going SD card.
I am trying to play within app nly.
Here is Code
public class VideoPreview : Fragment, ISurfaceHolderCallback, IOnClickListener,MediaRecorder.IOnInfoListener
{
private VideoView videoView = null;
private MediaController mc = null;
private ISurfaceHolder surfaceHolder;
private SurfaceView surfaceView;
public MediaRecorder mediaRecorder = new MediaRecorder();
private Camera mCamera;
private Button btnStart;
private Button btnSubmit;
private Button btnRestart;
private IList<Camera.Size> mSupportedPreviewSizes;
private Camera.Size mPreviewSize;
Android.Hardware.Camera.CameraInfo cameraInfo;
public static VideoPreview videoPreview;
public static VideoPreview NewInstance()
{
if (videoPreview == null)
{
return videoPreview = new VideoPreview();
}
else
{
return videoPreview;
}
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
View root = inflater.Inflate(Resource.Layout.VideoRecordFragment, null);
surfaceView =(SurfaceView)root.FindViewById(Resource.Id.surfaceView);
//mCamera = Camera.Open();
int cameraCount = 0;
// Camera cam = null;
cameraInfo = new Android.Hardware.Camera.CameraInfo();
cameraCount = Android.Hardware.Camera.NumberOfCameras;
int orientation = CalculatePreviewOrientation(cameraInfo, Activity.WindowManager.DefaultDisplay.Rotation);
for (int camIdx = 0; camIdx < cameraCount; camIdx++)
{
Android.Hardware.Camera.GetCameraInfo(camIdx, cameraInfo);
if (cameraInfo.Facing == Android.Hardware.Camera.CameraInfo.CameraFacingFront)
{
try
{
mCamera = Android.Hardware.Camera.Open(camIdx);
mCamera.SetDisplayOrientation(90);
}
catch (Exception e)
{
//Log.Error(TAG, "Camera failed to open: " + e.Message);
}
}
}
// mCamera.setDisplayOrientation(90);
surfaceHolder = surfaceView.Holder;
surfaceHolder.AddCallback(this);
surfaceHolder.SetType(SurfaceType.PushBuffers);
btnStart = (Button)root.FindViewById(Resource.Id.btnStart);
btnSubmit = (Button)root.FindViewById(Resource.Id.btnSubmit);
btnRestart = (Button)root.FindViewById(Resource.Id.btnReset);
btnStart.SetOnClickListener(this);
btnSubmit.SetOnClickListener(this);
btnRestart.SetOnClickListener(this);
//return base.OnCreateView(inflater, container, savedInstanceState);
return root;
}
protected void startRecording()
{
int orientation;
if (mCamera == null)
{
int cameraCount = 0;
// Camera cam = null;
cameraInfo = new Android.Hardware.Camera.CameraInfo();
cameraCount = Android.Hardware.Camera.NumberOfCameras;
orientation = CalculatePreviewOrientation(cameraInfo, Activity.WindowManager.DefaultDisplay.Rotation);
for (int camIdx = 0; camIdx < cameraCount; camIdx++)
{
Android.Hardware.Camera.GetCameraInfo(camIdx, cameraInfo);
if (cameraInfo.Facing == Android.Hardware.Camera.CameraInfo.CameraFacingFront)
{
try
{
mCamera = Android.Hardware.Camera.Open(camIdx);
mCamera.SetDisplayOrientation(90);
}
catch (Exception e)
{
//Log.Error(TAG, "Camera failed to open: " + e.Message);
}
}
}
}
// mCamera = Camera.Open();
orientation = CalculatePreviewOrientation(cameraInfo, Activity.WindowManager.DefaultDisplay.Rotation);
File sdCard = Context.GetExternalFilesDir(Android.OS.Environment.DirectoryPictures);
File dir = new File(sdCard.AbsolutePath + "/SignIn/SignIn Videos");
if (!dir.Exists())
{
dir.Mkdirs();
}
Date date = new Date();
String fileName = "/rec" + date.ToString().Replace(" ", "_").Replace(":", "_") + ".mp4";
File file = new File(dir, fileName);
// mCamera.GetParameters().SetRotation(orientation);
mediaRecorder = new MediaRecorder();
mCamera.Lock();
mCamera.Unlock();
// Please maintain sequence of following code.
// If you change sequence it will not work.
mediaRecorder.SetCamera(mCamera);
mediaRecorder.SetVideoSource(VideoSource.Camera);
mediaRecorder.SetAudioSource(AudioSource.Camcorder);
// mediaRecorder.SetProfile(CamcorderProfile.Get(CamcorderQuality.High));
// mediaRecorder.SetProfile(CamcorderProfile.Get(CamcorderQuality.High));
mediaRecorder.SetOutputFormat(OutputFormat.Default);
mediaRecorder.SetVideoEncoder(VideoEncoder.Default);
mediaRecorder.SetAudioEncoder(AudioEncoder.Default);
mediaRecorder.SetOutputFile(dir + fileName);
mediaRecorder.SetMaxDuration(10000);
mediaRecorder.SetOnInfoListener(this);
mediaRecorder.SetPreviewDisplay(surfaceHolder.Surface);
mediaRecorder.SetOrientationHint(270);
mediaRecorder.Prepare();
mediaRecorder.Start();
refreshGallery(file);
}
private void refreshGallery(File file)
{
Intent mediaScanIntent = new Intent(
Intent.ActionMediaScannerScanFile);
mediaScanIntent.SetData(Android.Net.Uri.FromFile(file));
Activity.SendBroadcast(mediaScanIntent);
}
protected void stopRecording()
{
if (mediaRecorder != null)
{
mediaRecorder.Stop();
mediaRecorder.Release();
releaseCamera();
// mCamera.lock();
}
}
private void releaseMediaRecorder()
{
if (mediaRecorder != null)
{
mediaRecorder.Reset(); // clear recorder configuration
mediaRecorder.Release(); // release the recorder object
}
}
private void releaseCamera()
{
if (mCamera != null)
{
mCamera.Release(); // release the camera for other applications
mCamera = null;
}
}
public void SurfaceChanged(ISurfaceHolder holder, [GeneratedEnum] Android.Graphics.Format format, int width, int height)
{
// throw new NotImplementedException();
}
public void SurfaceCreated(ISurfaceHolder holder)
{
//throw new NotImplementedException();
if (mCamera != null)
{
//Parameters param = mCamera.GetParameters();
//mCamera.SetParameters(param);
//mCamera.SetDisplayOrientation(90);
//Log.i("Surface", "Created");
}
else
{
Toast.MakeText(Activity, "Camera not available!",
ToastLength.Long).Show();
// Finish();
}
}
public void SurfaceDestroyed(ISurfaceHolder holder)
{
mCamera.StopPreview();
releaseCamera();
}
public void OnClick(View v)
{
switch (v.Id)
{
case Resource.Id.btnStart:
if (btnStart.Text.ToLower().ToString().Equals("start"))
{
btnStart.SetText("Pause", TextView.BufferType.Normal);
btnSubmit.Visibility = ViewStates.Visible;
btnRestart.Visibility = ViewStates.Visible;
try
{
startRecording();
}
catch (IOException e)
{
// String message = e.getMessage();
// Log.i(null, "Problem " + message);
mediaRecorder.Release();
// e.printStackTrace();
}
}
else if (btnStart.Text.ToLower().ToString().Equals("pause"))
{
btnStart.SetText("Resume", TextView.BufferType.Normal);
try
{
mediaRecorder.Pause();
}
catch (IOException e)
{
// String message = e.getMessage();
// Log.i(null, "Problem " + message);
mediaRecorder.Release();
// e.printStackTrace();
}
}
else if (btnStart.Text.ToLower().ToString().Equals("resume"))
{
btnStart.SetText("Pause", TextView.BufferType.Normal);
try
{
mediaRecorder.Resume();
}
catch (IOException e)
{
// String message = e.getMessage();
// Log.i(null, "Problem " + message);
mediaRecorder.Release();
// e.printStackTrace();
}
}
break;
case Resource.Id.btnSubmit:
try
{
btnStart.SetText("Start", TextView.BufferType.Normal);
btnStart.Visibility = ViewStates.Visible;
btnSubmit.Visibility = ViewStates.Gone;
btnRestart.Visibility = ViewStates.Gone;
mediaRecorder.Stop();
mediaRecorder.Release();
mediaRecorder = null;
}
catch(Exception ex)
{
mediaRecorder.Release();
}
break;
case Resource.Id.btnReset:
try
{
btnStart.SetText("Pause", TextView.BufferType.Normal);
mediaRecorder.Reset();
}
catch (Exception ex)
{
mediaRecorder.Release();
}
break;
default:
break;
}
}
public static int CalculatePreviewOrientation(Camera.CameraInfo info, SurfaceOrientation rotation)
{
int degrees = 0;
switch (rotation)
{
case SurfaceOrientation.Rotation0:
degrees = 0;
break;
case SurfaceOrientation.Rotation90:
degrees = 90;
break;
case SurfaceOrientation.Rotation180:
degrees = 180;
break;
case SurfaceOrientation.Rotation270:
degrees = 270;
break;
}
int result;
if (info.Facing == CameraFacing.Front)
{
result = (info.Orientation + degrees) % 360;
result = (360 - result) % 360; // compensate the mirror
}
else
{ // back-facing
result = (info.Orientation - degrees + 360) % 360;
}
return result;
}
public void OnInfo(MediaRecorder mr, [GeneratedEnum] MediaRecorderInfo what, int extra)
{
mediaRecorder.Pause();
btnSubmit.Visibility = ViewStates.Visible;
btnRestart.Visibility = ViewStates.Visible;
btnStart.Visibility = ViewStates.Gone;
//if (what. == MediaRecorder)
//{
// Log.v("VIDEOCAPTURE", "Maximum Duration Reached");
// mr.stop();
//}
}
}
|
show 3 more comments
I am using mediaRecorder to record video.
I am able to start , pause, resume and stop recording .
I want to play recorded video within same page instead of going back to SD card where it is saved.
Can Anyone help for this.
There are solutions where video is saved in sd card and playing by going SD card.
I am trying to play within app nly.
Here is Code
public class VideoPreview : Fragment, ISurfaceHolderCallback, IOnClickListener,MediaRecorder.IOnInfoListener
{
private VideoView videoView = null;
private MediaController mc = null;
private ISurfaceHolder surfaceHolder;
private SurfaceView surfaceView;
public MediaRecorder mediaRecorder = new MediaRecorder();
private Camera mCamera;
private Button btnStart;
private Button btnSubmit;
private Button btnRestart;
private IList<Camera.Size> mSupportedPreviewSizes;
private Camera.Size mPreviewSize;
Android.Hardware.Camera.CameraInfo cameraInfo;
public static VideoPreview videoPreview;
public static VideoPreview NewInstance()
{
if (videoPreview == null)
{
return videoPreview = new VideoPreview();
}
else
{
return videoPreview;
}
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
View root = inflater.Inflate(Resource.Layout.VideoRecordFragment, null);
surfaceView =(SurfaceView)root.FindViewById(Resource.Id.surfaceView);
//mCamera = Camera.Open();
int cameraCount = 0;
// Camera cam = null;
cameraInfo = new Android.Hardware.Camera.CameraInfo();
cameraCount = Android.Hardware.Camera.NumberOfCameras;
int orientation = CalculatePreviewOrientation(cameraInfo, Activity.WindowManager.DefaultDisplay.Rotation);
for (int camIdx = 0; camIdx < cameraCount; camIdx++)
{
Android.Hardware.Camera.GetCameraInfo(camIdx, cameraInfo);
if (cameraInfo.Facing == Android.Hardware.Camera.CameraInfo.CameraFacingFront)
{
try
{
mCamera = Android.Hardware.Camera.Open(camIdx);
mCamera.SetDisplayOrientation(90);
}
catch (Exception e)
{
//Log.Error(TAG, "Camera failed to open: " + e.Message);
}
}
}
// mCamera.setDisplayOrientation(90);
surfaceHolder = surfaceView.Holder;
surfaceHolder.AddCallback(this);
surfaceHolder.SetType(SurfaceType.PushBuffers);
btnStart = (Button)root.FindViewById(Resource.Id.btnStart);
btnSubmit = (Button)root.FindViewById(Resource.Id.btnSubmit);
btnRestart = (Button)root.FindViewById(Resource.Id.btnReset);
btnStart.SetOnClickListener(this);
btnSubmit.SetOnClickListener(this);
btnRestart.SetOnClickListener(this);
//return base.OnCreateView(inflater, container, savedInstanceState);
return root;
}
protected void startRecording()
{
int orientation;
if (mCamera == null)
{
int cameraCount = 0;
// Camera cam = null;
cameraInfo = new Android.Hardware.Camera.CameraInfo();
cameraCount = Android.Hardware.Camera.NumberOfCameras;
orientation = CalculatePreviewOrientation(cameraInfo, Activity.WindowManager.DefaultDisplay.Rotation);
for (int camIdx = 0; camIdx < cameraCount; camIdx++)
{
Android.Hardware.Camera.GetCameraInfo(camIdx, cameraInfo);
if (cameraInfo.Facing == Android.Hardware.Camera.CameraInfo.CameraFacingFront)
{
try
{
mCamera = Android.Hardware.Camera.Open(camIdx);
mCamera.SetDisplayOrientation(90);
}
catch (Exception e)
{
//Log.Error(TAG, "Camera failed to open: " + e.Message);
}
}
}
}
// mCamera = Camera.Open();
orientation = CalculatePreviewOrientation(cameraInfo, Activity.WindowManager.DefaultDisplay.Rotation);
File sdCard = Context.GetExternalFilesDir(Android.OS.Environment.DirectoryPictures);
File dir = new File(sdCard.AbsolutePath + "/SignIn/SignIn Videos");
if (!dir.Exists())
{
dir.Mkdirs();
}
Date date = new Date();
String fileName = "/rec" + date.ToString().Replace(" ", "_").Replace(":", "_") + ".mp4";
File file = new File(dir, fileName);
// mCamera.GetParameters().SetRotation(orientation);
mediaRecorder = new MediaRecorder();
mCamera.Lock();
mCamera.Unlock();
// Please maintain sequence of following code.
// If you change sequence it will not work.
mediaRecorder.SetCamera(mCamera);
mediaRecorder.SetVideoSource(VideoSource.Camera);
mediaRecorder.SetAudioSource(AudioSource.Camcorder);
// mediaRecorder.SetProfile(CamcorderProfile.Get(CamcorderQuality.High));
// mediaRecorder.SetProfile(CamcorderProfile.Get(CamcorderQuality.High));
mediaRecorder.SetOutputFormat(OutputFormat.Default);
mediaRecorder.SetVideoEncoder(VideoEncoder.Default);
mediaRecorder.SetAudioEncoder(AudioEncoder.Default);
mediaRecorder.SetOutputFile(dir + fileName);
mediaRecorder.SetMaxDuration(10000);
mediaRecorder.SetOnInfoListener(this);
mediaRecorder.SetPreviewDisplay(surfaceHolder.Surface);
mediaRecorder.SetOrientationHint(270);
mediaRecorder.Prepare();
mediaRecorder.Start();
refreshGallery(file);
}
private void refreshGallery(File file)
{
Intent mediaScanIntent = new Intent(
Intent.ActionMediaScannerScanFile);
mediaScanIntent.SetData(Android.Net.Uri.FromFile(file));
Activity.SendBroadcast(mediaScanIntent);
}
protected void stopRecording()
{
if (mediaRecorder != null)
{
mediaRecorder.Stop();
mediaRecorder.Release();
releaseCamera();
// mCamera.lock();
}
}
private void releaseMediaRecorder()
{
if (mediaRecorder != null)
{
mediaRecorder.Reset(); // clear recorder configuration
mediaRecorder.Release(); // release the recorder object
}
}
private void releaseCamera()
{
if (mCamera != null)
{
mCamera.Release(); // release the camera for other applications
mCamera = null;
}
}
public void SurfaceChanged(ISurfaceHolder holder, [GeneratedEnum] Android.Graphics.Format format, int width, int height)
{
// throw new NotImplementedException();
}
public void SurfaceCreated(ISurfaceHolder holder)
{
//throw new NotImplementedException();
if (mCamera != null)
{
//Parameters param = mCamera.GetParameters();
//mCamera.SetParameters(param);
//mCamera.SetDisplayOrientation(90);
//Log.i("Surface", "Created");
}
else
{
Toast.MakeText(Activity, "Camera not available!",
ToastLength.Long).Show();
// Finish();
}
}
public void SurfaceDestroyed(ISurfaceHolder holder)
{
mCamera.StopPreview();
releaseCamera();
}
public void OnClick(View v)
{
switch (v.Id)
{
case Resource.Id.btnStart:
if (btnStart.Text.ToLower().ToString().Equals("start"))
{
btnStart.SetText("Pause", TextView.BufferType.Normal);
btnSubmit.Visibility = ViewStates.Visible;
btnRestart.Visibility = ViewStates.Visible;
try
{
startRecording();
}
catch (IOException e)
{
// String message = e.getMessage();
// Log.i(null, "Problem " + message);
mediaRecorder.Release();
// e.printStackTrace();
}
}
else if (btnStart.Text.ToLower().ToString().Equals("pause"))
{
btnStart.SetText("Resume", TextView.BufferType.Normal);
try
{
mediaRecorder.Pause();
}
catch (IOException e)
{
// String message = e.getMessage();
// Log.i(null, "Problem " + message);
mediaRecorder.Release();
// e.printStackTrace();
}
}
else if (btnStart.Text.ToLower().ToString().Equals("resume"))
{
btnStart.SetText("Pause", TextView.BufferType.Normal);
try
{
mediaRecorder.Resume();
}
catch (IOException e)
{
// String message = e.getMessage();
// Log.i(null, "Problem " + message);
mediaRecorder.Release();
// e.printStackTrace();
}
}
break;
case Resource.Id.btnSubmit:
try
{
btnStart.SetText("Start", TextView.BufferType.Normal);
btnStart.Visibility = ViewStates.Visible;
btnSubmit.Visibility = ViewStates.Gone;
btnRestart.Visibility = ViewStates.Gone;
mediaRecorder.Stop();
mediaRecorder.Release();
mediaRecorder = null;
}
catch(Exception ex)
{
mediaRecorder.Release();
}
break;
case Resource.Id.btnReset:
try
{
btnStart.SetText("Pause", TextView.BufferType.Normal);
mediaRecorder.Reset();
}
catch (Exception ex)
{
mediaRecorder.Release();
}
break;
default:
break;
}
}
public static int CalculatePreviewOrientation(Camera.CameraInfo info, SurfaceOrientation rotation)
{
int degrees = 0;
switch (rotation)
{
case SurfaceOrientation.Rotation0:
degrees = 0;
break;
case SurfaceOrientation.Rotation90:
degrees = 90;
break;
case SurfaceOrientation.Rotation180:
degrees = 180;
break;
case SurfaceOrientation.Rotation270:
degrees = 270;
break;
}
int result;
if (info.Facing == CameraFacing.Front)
{
result = (info.Orientation + degrees) % 360;
result = (360 - result) % 360; // compensate the mirror
}
else
{ // back-facing
result = (info.Orientation - degrees + 360) % 360;
}
return result;
}
public void OnInfo(MediaRecorder mr, [GeneratedEnum] MediaRecorderInfo what, int extra)
{
mediaRecorder.Pause();
btnSubmit.Visibility = ViewStates.Visible;
btnRestart.Visibility = ViewStates.Visible;
btnStart.Visibility = ViewStates.Gone;
//if (what. == MediaRecorder)
//{
// Log.v("VIDEOCAPTURE", "Maximum Duration Reached");
// mr.stop();
//}
}
}
What do you mean by within the app only do you have the data as service response or what?
– G.hakim
Nov 29 '18 at 6:07
Hi @G.hakim ..Thanks for replying ...within app means on same page ..I am showing camera and using mediaRecorder i am recording video.So if i want to replay that recorded video then how i can do that?In short i want to see the recorded video before saving or submit.
– nitu
Nov 29 '18 at 9:08
You are using Android camera API for recording video which is now deprecated, I would suggest you first port it to Camera2, Also if you want to preview the video you will have to implement a video view and after you are done with the video capture you will have to store that data in an object rather than the device memory and then pass it to the video view
– G.hakim
Nov 29 '18 at 10:13
ok @G.hakim .thanks for your reply and help.i will try this one.
– nitu
Nov 29 '18 at 10:15
Sure no problem in case of issues feel free to get back
– G.hakim
Nov 29 '18 at 10:25
|
show 3 more comments
I am using mediaRecorder to record video.
I am able to start , pause, resume and stop recording .
I want to play recorded video within same page instead of going back to SD card where it is saved.
Can Anyone help for this.
There are solutions where video is saved in sd card and playing by going SD card.
I am trying to play within app nly.
Here is Code
public class VideoPreview : Fragment, ISurfaceHolderCallback, IOnClickListener,MediaRecorder.IOnInfoListener
{
private VideoView videoView = null;
private MediaController mc = null;
private ISurfaceHolder surfaceHolder;
private SurfaceView surfaceView;
public MediaRecorder mediaRecorder = new MediaRecorder();
private Camera mCamera;
private Button btnStart;
private Button btnSubmit;
private Button btnRestart;
private IList<Camera.Size> mSupportedPreviewSizes;
private Camera.Size mPreviewSize;
Android.Hardware.Camera.CameraInfo cameraInfo;
public static VideoPreview videoPreview;
public static VideoPreview NewInstance()
{
if (videoPreview == null)
{
return videoPreview = new VideoPreview();
}
else
{
return videoPreview;
}
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
View root = inflater.Inflate(Resource.Layout.VideoRecordFragment, null);
surfaceView =(SurfaceView)root.FindViewById(Resource.Id.surfaceView);
//mCamera = Camera.Open();
int cameraCount = 0;
// Camera cam = null;
cameraInfo = new Android.Hardware.Camera.CameraInfo();
cameraCount = Android.Hardware.Camera.NumberOfCameras;
int orientation = CalculatePreviewOrientation(cameraInfo, Activity.WindowManager.DefaultDisplay.Rotation);
for (int camIdx = 0; camIdx < cameraCount; camIdx++)
{
Android.Hardware.Camera.GetCameraInfo(camIdx, cameraInfo);
if (cameraInfo.Facing == Android.Hardware.Camera.CameraInfo.CameraFacingFront)
{
try
{
mCamera = Android.Hardware.Camera.Open(camIdx);
mCamera.SetDisplayOrientation(90);
}
catch (Exception e)
{
//Log.Error(TAG, "Camera failed to open: " + e.Message);
}
}
}
// mCamera.setDisplayOrientation(90);
surfaceHolder = surfaceView.Holder;
surfaceHolder.AddCallback(this);
surfaceHolder.SetType(SurfaceType.PushBuffers);
btnStart = (Button)root.FindViewById(Resource.Id.btnStart);
btnSubmit = (Button)root.FindViewById(Resource.Id.btnSubmit);
btnRestart = (Button)root.FindViewById(Resource.Id.btnReset);
btnStart.SetOnClickListener(this);
btnSubmit.SetOnClickListener(this);
btnRestart.SetOnClickListener(this);
//return base.OnCreateView(inflater, container, savedInstanceState);
return root;
}
protected void startRecording()
{
int orientation;
if (mCamera == null)
{
int cameraCount = 0;
// Camera cam = null;
cameraInfo = new Android.Hardware.Camera.CameraInfo();
cameraCount = Android.Hardware.Camera.NumberOfCameras;
orientation = CalculatePreviewOrientation(cameraInfo, Activity.WindowManager.DefaultDisplay.Rotation);
for (int camIdx = 0; camIdx < cameraCount; camIdx++)
{
Android.Hardware.Camera.GetCameraInfo(camIdx, cameraInfo);
if (cameraInfo.Facing == Android.Hardware.Camera.CameraInfo.CameraFacingFront)
{
try
{
mCamera = Android.Hardware.Camera.Open(camIdx);
mCamera.SetDisplayOrientation(90);
}
catch (Exception e)
{
//Log.Error(TAG, "Camera failed to open: " + e.Message);
}
}
}
}
// mCamera = Camera.Open();
orientation = CalculatePreviewOrientation(cameraInfo, Activity.WindowManager.DefaultDisplay.Rotation);
File sdCard = Context.GetExternalFilesDir(Android.OS.Environment.DirectoryPictures);
File dir = new File(sdCard.AbsolutePath + "/SignIn/SignIn Videos");
if (!dir.Exists())
{
dir.Mkdirs();
}
Date date = new Date();
String fileName = "/rec" + date.ToString().Replace(" ", "_").Replace(":", "_") + ".mp4";
File file = new File(dir, fileName);
// mCamera.GetParameters().SetRotation(orientation);
mediaRecorder = new MediaRecorder();
mCamera.Lock();
mCamera.Unlock();
// Please maintain sequence of following code.
// If you change sequence it will not work.
mediaRecorder.SetCamera(mCamera);
mediaRecorder.SetVideoSource(VideoSource.Camera);
mediaRecorder.SetAudioSource(AudioSource.Camcorder);
// mediaRecorder.SetProfile(CamcorderProfile.Get(CamcorderQuality.High));
// mediaRecorder.SetProfile(CamcorderProfile.Get(CamcorderQuality.High));
mediaRecorder.SetOutputFormat(OutputFormat.Default);
mediaRecorder.SetVideoEncoder(VideoEncoder.Default);
mediaRecorder.SetAudioEncoder(AudioEncoder.Default);
mediaRecorder.SetOutputFile(dir + fileName);
mediaRecorder.SetMaxDuration(10000);
mediaRecorder.SetOnInfoListener(this);
mediaRecorder.SetPreviewDisplay(surfaceHolder.Surface);
mediaRecorder.SetOrientationHint(270);
mediaRecorder.Prepare();
mediaRecorder.Start();
refreshGallery(file);
}
private void refreshGallery(File file)
{
Intent mediaScanIntent = new Intent(
Intent.ActionMediaScannerScanFile);
mediaScanIntent.SetData(Android.Net.Uri.FromFile(file));
Activity.SendBroadcast(mediaScanIntent);
}
protected void stopRecording()
{
if (mediaRecorder != null)
{
mediaRecorder.Stop();
mediaRecorder.Release();
releaseCamera();
// mCamera.lock();
}
}
private void releaseMediaRecorder()
{
if (mediaRecorder != null)
{
mediaRecorder.Reset(); // clear recorder configuration
mediaRecorder.Release(); // release the recorder object
}
}
private void releaseCamera()
{
if (mCamera != null)
{
mCamera.Release(); // release the camera for other applications
mCamera = null;
}
}
public void SurfaceChanged(ISurfaceHolder holder, [GeneratedEnum] Android.Graphics.Format format, int width, int height)
{
// throw new NotImplementedException();
}
public void SurfaceCreated(ISurfaceHolder holder)
{
//throw new NotImplementedException();
if (mCamera != null)
{
//Parameters param = mCamera.GetParameters();
//mCamera.SetParameters(param);
//mCamera.SetDisplayOrientation(90);
//Log.i("Surface", "Created");
}
else
{
Toast.MakeText(Activity, "Camera not available!",
ToastLength.Long).Show();
// Finish();
}
}
public void SurfaceDestroyed(ISurfaceHolder holder)
{
mCamera.StopPreview();
releaseCamera();
}
public void OnClick(View v)
{
switch (v.Id)
{
case Resource.Id.btnStart:
if (btnStart.Text.ToLower().ToString().Equals("start"))
{
btnStart.SetText("Pause", TextView.BufferType.Normal);
btnSubmit.Visibility = ViewStates.Visible;
btnRestart.Visibility = ViewStates.Visible;
try
{
startRecording();
}
catch (IOException e)
{
// String message = e.getMessage();
// Log.i(null, "Problem " + message);
mediaRecorder.Release();
// e.printStackTrace();
}
}
else if (btnStart.Text.ToLower().ToString().Equals("pause"))
{
btnStart.SetText("Resume", TextView.BufferType.Normal);
try
{
mediaRecorder.Pause();
}
catch (IOException e)
{
// String message = e.getMessage();
// Log.i(null, "Problem " + message);
mediaRecorder.Release();
// e.printStackTrace();
}
}
else if (btnStart.Text.ToLower().ToString().Equals("resume"))
{
btnStart.SetText("Pause", TextView.BufferType.Normal);
try
{
mediaRecorder.Resume();
}
catch (IOException e)
{
// String message = e.getMessage();
// Log.i(null, "Problem " + message);
mediaRecorder.Release();
// e.printStackTrace();
}
}
break;
case Resource.Id.btnSubmit:
try
{
btnStart.SetText("Start", TextView.BufferType.Normal);
btnStart.Visibility = ViewStates.Visible;
btnSubmit.Visibility = ViewStates.Gone;
btnRestart.Visibility = ViewStates.Gone;
mediaRecorder.Stop();
mediaRecorder.Release();
mediaRecorder = null;
}
catch(Exception ex)
{
mediaRecorder.Release();
}
break;
case Resource.Id.btnReset:
try
{
btnStart.SetText("Pause", TextView.BufferType.Normal);
mediaRecorder.Reset();
}
catch (Exception ex)
{
mediaRecorder.Release();
}
break;
default:
break;
}
}
public static int CalculatePreviewOrientation(Camera.CameraInfo info, SurfaceOrientation rotation)
{
int degrees = 0;
switch (rotation)
{
case SurfaceOrientation.Rotation0:
degrees = 0;
break;
case SurfaceOrientation.Rotation90:
degrees = 90;
break;
case SurfaceOrientation.Rotation180:
degrees = 180;
break;
case SurfaceOrientation.Rotation270:
degrees = 270;
break;
}
int result;
if (info.Facing == CameraFacing.Front)
{
result = (info.Orientation + degrees) % 360;
result = (360 - result) % 360; // compensate the mirror
}
else
{ // back-facing
result = (info.Orientation - degrees + 360) % 360;
}
return result;
}
public void OnInfo(MediaRecorder mr, [GeneratedEnum] MediaRecorderInfo what, int extra)
{
mediaRecorder.Pause();
btnSubmit.Visibility = ViewStates.Visible;
btnRestart.Visibility = ViewStates.Visible;
btnStart.Visibility = ViewStates.Gone;
//if (what. == MediaRecorder)
//{
// Log.v("VIDEOCAPTURE", "Maximum Duration Reached");
// mr.stop();
//}
}
}
I am using mediaRecorder to record video.
I am able to start , pause, resume and stop recording .
I want to play recorded video within same page instead of going back to SD card where it is saved.
Can Anyone help for this.
There are solutions where video is saved in sd card and playing by going SD card.
I am trying to play within app nly.
Here is Code
public class VideoPreview : Fragment, ISurfaceHolderCallback, IOnClickListener,MediaRecorder.IOnInfoListener
{
private VideoView videoView = null;
private MediaController mc = null;
private ISurfaceHolder surfaceHolder;
private SurfaceView surfaceView;
public MediaRecorder mediaRecorder = new MediaRecorder();
private Camera mCamera;
private Button btnStart;
private Button btnSubmit;
private Button btnRestart;
private IList<Camera.Size> mSupportedPreviewSizes;
private Camera.Size mPreviewSize;
Android.Hardware.Camera.CameraInfo cameraInfo;
public static VideoPreview videoPreview;
public static VideoPreview NewInstance()
{
if (videoPreview == null)
{
return videoPreview = new VideoPreview();
}
else
{
return videoPreview;
}
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
View root = inflater.Inflate(Resource.Layout.VideoRecordFragment, null);
surfaceView =(SurfaceView)root.FindViewById(Resource.Id.surfaceView);
//mCamera = Camera.Open();
int cameraCount = 0;
// Camera cam = null;
cameraInfo = new Android.Hardware.Camera.CameraInfo();
cameraCount = Android.Hardware.Camera.NumberOfCameras;
int orientation = CalculatePreviewOrientation(cameraInfo, Activity.WindowManager.DefaultDisplay.Rotation);
for (int camIdx = 0; camIdx < cameraCount; camIdx++)
{
Android.Hardware.Camera.GetCameraInfo(camIdx, cameraInfo);
if (cameraInfo.Facing == Android.Hardware.Camera.CameraInfo.CameraFacingFront)
{
try
{
mCamera = Android.Hardware.Camera.Open(camIdx);
mCamera.SetDisplayOrientation(90);
}
catch (Exception e)
{
//Log.Error(TAG, "Camera failed to open: " + e.Message);
}
}
}
// mCamera.setDisplayOrientation(90);
surfaceHolder = surfaceView.Holder;
surfaceHolder.AddCallback(this);
surfaceHolder.SetType(SurfaceType.PushBuffers);
btnStart = (Button)root.FindViewById(Resource.Id.btnStart);
btnSubmit = (Button)root.FindViewById(Resource.Id.btnSubmit);
btnRestart = (Button)root.FindViewById(Resource.Id.btnReset);
btnStart.SetOnClickListener(this);
btnSubmit.SetOnClickListener(this);
btnRestart.SetOnClickListener(this);
//return base.OnCreateView(inflater, container, savedInstanceState);
return root;
}
protected void startRecording()
{
int orientation;
if (mCamera == null)
{
int cameraCount = 0;
// Camera cam = null;
cameraInfo = new Android.Hardware.Camera.CameraInfo();
cameraCount = Android.Hardware.Camera.NumberOfCameras;
orientation = CalculatePreviewOrientation(cameraInfo, Activity.WindowManager.DefaultDisplay.Rotation);
for (int camIdx = 0; camIdx < cameraCount; camIdx++)
{
Android.Hardware.Camera.GetCameraInfo(camIdx, cameraInfo);
if (cameraInfo.Facing == Android.Hardware.Camera.CameraInfo.CameraFacingFront)
{
try
{
mCamera = Android.Hardware.Camera.Open(camIdx);
mCamera.SetDisplayOrientation(90);
}
catch (Exception e)
{
//Log.Error(TAG, "Camera failed to open: " + e.Message);
}
}
}
}
// mCamera = Camera.Open();
orientation = CalculatePreviewOrientation(cameraInfo, Activity.WindowManager.DefaultDisplay.Rotation);
File sdCard = Context.GetExternalFilesDir(Android.OS.Environment.DirectoryPictures);
File dir = new File(sdCard.AbsolutePath + "/SignIn/SignIn Videos");
if (!dir.Exists())
{
dir.Mkdirs();
}
Date date = new Date();
String fileName = "/rec" + date.ToString().Replace(" ", "_").Replace(":", "_") + ".mp4";
File file = new File(dir, fileName);
// mCamera.GetParameters().SetRotation(orientation);
mediaRecorder = new MediaRecorder();
mCamera.Lock();
mCamera.Unlock();
// Please maintain sequence of following code.
// If you change sequence it will not work.
mediaRecorder.SetCamera(mCamera);
mediaRecorder.SetVideoSource(VideoSource.Camera);
mediaRecorder.SetAudioSource(AudioSource.Camcorder);
// mediaRecorder.SetProfile(CamcorderProfile.Get(CamcorderQuality.High));
// mediaRecorder.SetProfile(CamcorderProfile.Get(CamcorderQuality.High));
mediaRecorder.SetOutputFormat(OutputFormat.Default);
mediaRecorder.SetVideoEncoder(VideoEncoder.Default);
mediaRecorder.SetAudioEncoder(AudioEncoder.Default);
mediaRecorder.SetOutputFile(dir + fileName);
mediaRecorder.SetMaxDuration(10000);
mediaRecorder.SetOnInfoListener(this);
mediaRecorder.SetPreviewDisplay(surfaceHolder.Surface);
mediaRecorder.SetOrientationHint(270);
mediaRecorder.Prepare();
mediaRecorder.Start();
refreshGallery(file);
}
private void refreshGallery(File file)
{
Intent mediaScanIntent = new Intent(
Intent.ActionMediaScannerScanFile);
mediaScanIntent.SetData(Android.Net.Uri.FromFile(file));
Activity.SendBroadcast(mediaScanIntent);
}
protected void stopRecording()
{
if (mediaRecorder != null)
{
mediaRecorder.Stop();
mediaRecorder.Release();
releaseCamera();
// mCamera.lock();
}
}
private void releaseMediaRecorder()
{
if (mediaRecorder != null)
{
mediaRecorder.Reset(); // clear recorder configuration
mediaRecorder.Release(); // release the recorder object
}
}
private void releaseCamera()
{
if (mCamera != null)
{
mCamera.Release(); // release the camera for other applications
mCamera = null;
}
}
public void SurfaceChanged(ISurfaceHolder holder, [GeneratedEnum] Android.Graphics.Format format, int width, int height)
{
// throw new NotImplementedException();
}
public void SurfaceCreated(ISurfaceHolder holder)
{
//throw new NotImplementedException();
if (mCamera != null)
{
//Parameters param = mCamera.GetParameters();
//mCamera.SetParameters(param);
//mCamera.SetDisplayOrientation(90);
//Log.i("Surface", "Created");
}
else
{
Toast.MakeText(Activity, "Camera not available!",
ToastLength.Long).Show();
// Finish();
}
}
public void SurfaceDestroyed(ISurfaceHolder holder)
{
mCamera.StopPreview();
releaseCamera();
}
public void OnClick(View v)
{
switch (v.Id)
{
case Resource.Id.btnStart:
if (btnStart.Text.ToLower().ToString().Equals("start"))
{
btnStart.SetText("Pause", TextView.BufferType.Normal);
btnSubmit.Visibility = ViewStates.Visible;
btnRestart.Visibility = ViewStates.Visible;
try
{
startRecording();
}
catch (IOException e)
{
// String message = e.getMessage();
// Log.i(null, "Problem " + message);
mediaRecorder.Release();
// e.printStackTrace();
}
}
else if (btnStart.Text.ToLower().ToString().Equals("pause"))
{
btnStart.SetText("Resume", TextView.BufferType.Normal);
try
{
mediaRecorder.Pause();
}
catch (IOException e)
{
// String message = e.getMessage();
// Log.i(null, "Problem " + message);
mediaRecorder.Release();
// e.printStackTrace();
}
}
else if (btnStart.Text.ToLower().ToString().Equals("resume"))
{
btnStart.SetText("Pause", TextView.BufferType.Normal);
try
{
mediaRecorder.Resume();
}
catch (IOException e)
{
// String message = e.getMessage();
// Log.i(null, "Problem " + message);
mediaRecorder.Release();
// e.printStackTrace();
}
}
break;
case Resource.Id.btnSubmit:
try
{
btnStart.SetText("Start", TextView.BufferType.Normal);
btnStart.Visibility = ViewStates.Visible;
btnSubmit.Visibility = ViewStates.Gone;
btnRestart.Visibility = ViewStates.Gone;
mediaRecorder.Stop();
mediaRecorder.Release();
mediaRecorder = null;
}
catch(Exception ex)
{
mediaRecorder.Release();
}
break;
case Resource.Id.btnReset:
try
{
btnStart.SetText("Pause", TextView.BufferType.Normal);
mediaRecorder.Reset();
}
catch (Exception ex)
{
mediaRecorder.Release();
}
break;
default:
break;
}
}
public static int CalculatePreviewOrientation(Camera.CameraInfo info, SurfaceOrientation rotation)
{
int degrees = 0;
switch (rotation)
{
case SurfaceOrientation.Rotation0:
degrees = 0;
break;
case SurfaceOrientation.Rotation90:
degrees = 90;
break;
case SurfaceOrientation.Rotation180:
degrees = 180;
break;
case SurfaceOrientation.Rotation270:
degrees = 270;
break;
}
int result;
if (info.Facing == CameraFacing.Front)
{
result = (info.Orientation + degrees) % 360;
result = (360 - result) % 360; // compensate the mirror
}
else
{ // back-facing
result = (info.Orientation - degrees + 360) % 360;
}
return result;
}
public void OnInfo(MediaRecorder mr, [GeneratedEnum] MediaRecorderInfo what, int extra)
{
mediaRecorder.Pause();
btnSubmit.Visibility = ViewStates.Visible;
btnRestart.Visibility = ViewStates.Visible;
btnStart.Visibility = ViewStates.Gone;
//if (what. == MediaRecorder)
//{
// Log.v("VIDEOCAPTURE", "Maximum Duration Reached");
// mr.stop();
//}
}
}
asked Nov 29 '18 at 5:22
nitunitu
133114
133114
What do you mean by within the app only do you have the data as service response or what?
– G.hakim
Nov 29 '18 at 6:07
Hi @G.hakim ..Thanks for replying ...within app means on same page ..I am showing camera and using mediaRecorder i am recording video.So if i want to replay that recorded video then how i can do that?In short i want to see the recorded video before saving or submit.
– nitu
Nov 29 '18 at 9:08
You are using Android camera API for recording video which is now deprecated, I would suggest you first port it to Camera2, Also if you want to preview the video you will have to implement a video view and after you are done with the video capture you will have to store that data in an object rather than the device memory and then pass it to the video view
– G.hakim
Nov 29 '18 at 10:13
ok @G.hakim .thanks for your reply and help.i will try this one.
– nitu
Nov 29 '18 at 10:15
Sure no problem in case of issues feel free to get back
– G.hakim
Nov 29 '18 at 10:25
|
show 3 more comments
What do you mean by within the app only do you have the data as service response or what?
– G.hakim
Nov 29 '18 at 6:07
Hi @G.hakim ..Thanks for replying ...within app means on same page ..I am showing camera and using mediaRecorder i am recording video.So if i want to replay that recorded video then how i can do that?In short i want to see the recorded video before saving or submit.
– nitu
Nov 29 '18 at 9:08
You are using Android camera API for recording video which is now deprecated, I would suggest you first port it to Camera2, Also if you want to preview the video you will have to implement a video view and after you are done with the video capture you will have to store that data in an object rather than the device memory and then pass it to the video view
– G.hakim
Nov 29 '18 at 10:13
ok @G.hakim .thanks for your reply and help.i will try this one.
– nitu
Nov 29 '18 at 10:15
Sure no problem in case of issues feel free to get back
– G.hakim
Nov 29 '18 at 10:25
What do you mean by within the app only do you have the data as service response or what?
– G.hakim
Nov 29 '18 at 6:07
What do you mean by within the app only do you have the data as service response or what?
– G.hakim
Nov 29 '18 at 6:07
Hi @G.hakim ..Thanks for replying ...within app means on same page ..I am showing camera and using mediaRecorder i am recording video.So if i want to replay that recorded video then how i can do that?In short i want to see the recorded video before saving or submit.
– nitu
Nov 29 '18 at 9:08
Hi @G.hakim ..Thanks for replying ...within app means on same page ..I am showing camera and using mediaRecorder i am recording video.So if i want to replay that recorded video then how i can do that?In short i want to see the recorded video before saving or submit.
– nitu
Nov 29 '18 at 9:08
You are using Android camera API for recording video which is now deprecated, I would suggest you first port it to Camera2, Also if you want to preview the video you will have to implement a video view and after you are done with the video capture you will have to store that data in an object rather than the device memory and then pass it to the video view
– G.hakim
Nov 29 '18 at 10:13
You are using Android camera API for recording video which is now deprecated, I would suggest you first port it to Camera2, Also if you want to preview the video you will have to implement a video view and after you are done with the video capture you will have to store that data in an object rather than the device memory and then pass it to the video view
– G.hakim
Nov 29 '18 at 10:13
ok @G.hakim .thanks for your reply and help.i will try this one.
– nitu
Nov 29 '18 at 10:15
ok @G.hakim .thanks for your reply and help.i will try this one.
– nitu
Nov 29 '18 at 10:15
Sure no problem in case of issues feel free to get back
– G.hakim
Nov 29 '18 at 10:25
Sure no problem in case of issues feel free to get back
– G.hakim
Nov 29 '18 at 10:25
|
show 3 more comments
2 Answers
2
active
oldest
votes
You can use the video view for this in android :
Add a global field like this :
VideoView mVideoView;
Find the reference for the same something like this:
mVideoView=this.FindViewById<VideoView>(Resource.Id.mvidId); //Activity init
mVideoView=View.FindViewById<VideoView>(Resource.Id.mvidId); //Fragment init
Play video something like this:
private void playVideo(object sender, EventArgs e)
{
try
{
mVideoView.SetVideoPath(**VideoPath**);
mVideoView.SetMediaController(new MediaController(Activity));
mVideoView.RequestFocus();
mVideoView.Start();
}
catch (IOException ex)
{
StopTimer();
mediaRecorder.Release();
}
}
add a comment |
VideoView mVideoView;
private void playVideo(object sender, EventArgs e)
{
try
{
mVideoView.SetVideoPath(dir + "/rec" + videoFileName + ".mp4");
mVideoView.SetMediaController(new MediaController(Activity));
mVideoView.RequestFocus();
mVideoView.Start();
//StopTimer();
//CreateTimer();
}
catch (IOException ex)
{
// String message = e.getMessage();
// Log.i(null, "Problem " + message);
StopTimer();
mediaRecorder.Release();
// e.printStackTrace();
}
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53532356%2fhow-to-play-recorded-video-within-same-view-after-recording-pause%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use the video view for this in android :
Add a global field like this :
VideoView mVideoView;
Find the reference for the same something like this:
mVideoView=this.FindViewById<VideoView>(Resource.Id.mvidId); //Activity init
mVideoView=View.FindViewById<VideoView>(Resource.Id.mvidId); //Fragment init
Play video something like this:
private void playVideo(object sender, EventArgs e)
{
try
{
mVideoView.SetVideoPath(**VideoPath**);
mVideoView.SetMediaController(new MediaController(Activity));
mVideoView.RequestFocus();
mVideoView.Start();
}
catch (IOException ex)
{
StopTimer();
mediaRecorder.Release();
}
}
add a comment |
You can use the video view for this in android :
Add a global field like this :
VideoView mVideoView;
Find the reference for the same something like this:
mVideoView=this.FindViewById<VideoView>(Resource.Id.mvidId); //Activity init
mVideoView=View.FindViewById<VideoView>(Resource.Id.mvidId); //Fragment init
Play video something like this:
private void playVideo(object sender, EventArgs e)
{
try
{
mVideoView.SetVideoPath(**VideoPath**);
mVideoView.SetMediaController(new MediaController(Activity));
mVideoView.RequestFocus();
mVideoView.Start();
}
catch (IOException ex)
{
StopTimer();
mediaRecorder.Release();
}
}
add a comment |
You can use the video view for this in android :
Add a global field like this :
VideoView mVideoView;
Find the reference for the same something like this:
mVideoView=this.FindViewById<VideoView>(Resource.Id.mvidId); //Activity init
mVideoView=View.FindViewById<VideoView>(Resource.Id.mvidId); //Fragment init
Play video something like this:
private void playVideo(object sender, EventArgs e)
{
try
{
mVideoView.SetVideoPath(**VideoPath**);
mVideoView.SetMediaController(new MediaController(Activity));
mVideoView.RequestFocus();
mVideoView.Start();
}
catch (IOException ex)
{
StopTimer();
mediaRecorder.Release();
}
}
You can use the video view for this in android :
Add a global field like this :
VideoView mVideoView;
Find the reference for the same something like this:
mVideoView=this.FindViewById<VideoView>(Resource.Id.mvidId); //Activity init
mVideoView=View.FindViewById<VideoView>(Resource.Id.mvidId); //Fragment init
Play video something like this:
private void playVideo(object sender, EventArgs e)
{
try
{
mVideoView.SetVideoPath(**VideoPath**);
mVideoView.SetMediaController(new MediaController(Activity));
mVideoView.RequestFocus();
mVideoView.Start();
}
catch (IOException ex)
{
StopTimer();
mediaRecorder.Release();
}
}
answered Dec 3 '18 at 6:00
G.hakimG.hakim
5,27211136
5,27211136
add a comment |
add a comment |
VideoView mVideoView;
private void playVideo(object sender, EventArgs e)
{
try
{
mVideoView.SetVideoPath(dir + "/rec" + videoFileName + ".mp4");
mVideoView.SetMediaController(new MediaController(Activity));
mVideoView.RequestFocus();
mVideoView.Start();
//StopTimer();
//CreateTimer();
}
catch (IOException ex)
{
// String message = e.getMessage();
// Log.i(null, "Problem " + message);
StopTimer();
mediaRecorder.Release();
// e.printStackTrace();
}
}
add a comment |
VideoView mVideoView;
private void playVideo(object sender, EventArgs e)
{
try
{
mVideoView.SetVideoPath(dir + "/rec" + videoFileName + ".mp4");
mVideoView.SetMediaController(new MediaController(Activity));
mVideoView.RequestFocus();
mVideoView.Start();
//StopTimer();
//CreateTimer();
}
catch (IOException ex)
{
// String message = e.getMessage();
// Log.i(null, "Problem " + message);
StopTimer();
mediaRecorder.Release();
// e.printStackTrace();
}
}
add a comment |
VideoView mVideoView;
private void playVideo(object sender, EventArgs e)
{
try
{
mVideoView.SetVideoPath(dir + "/rec" + videoFileName + ".mp4");
mVideoView.SetMediaController(new MediaController(Activity));
mVideoView.RequestFocus();
mVideoView.Start();
//StopTimer();
//CreateTimer();
}
catch (IOException ex)
{
// String message = e.getMessage();
// Log.i(null, "Problem " + message);
StopTimer();
mediaRecorder.Release();
// e.printStackTrace();
}
}
VideoView mVideoView;
private void playVideo(object sender, EventArgs e)
{
try
{
mVideoView.SetVideoPath(dir + "/rec" + videoFileName + ".mp4");
mVideoView.SetMediaController(new MediaController(Activity));
mVideoView.RequestFocus();
mVideoView.Start();
//StopTimer();
//CreateTimer();
}
catch (IOException ex)
{
// String message = e.getMessage();
// Log.i(null, "Problem " + message);
StopTimer();
mediaRecorder.Release();
// e.printStackTrace();
}
}
answered Dec 3 '18 at 3:40
nitunitu
133114
133114
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53532356%2fhow-to-play-recorded-video-within-same-view-after-recording-pause%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What do you mean by within the app only do you have the data as service response or what?
– G.hakim
Nov 29 '18 at 6:07
Hi @G.hakim ..Thanks for replying ...within app means on same page ..I am showing camera and using mediaRecorder i am recording video.So if i want to replay that recorded video then how i can do that?In short i want to see the recorded video before saving or submit.
– nitu
Nov 29 '18 at 9:08
You are using Android camera API for recording video which is now deprecated, I would suggest you first port it to Camera2, Also if you want to preview the video you will have to implement a video view and after you are done with the video capture you will have to store that data in an object rather than the device memory and then pass it to the video view
– G.hakim
Nov 29 '18 at 10:13
ok @G.hakim .thanks for your reply and help.i will try this one.
– nitu
Nov 29 '18 at 10:15
Sure no problem in case of issues feel free to get back
– G.hakim
Nov 29 '18 at 10:25