Click here to Skip to main content
15,888,181 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am working on windows phone app, In which i need to capture video using front camera. I am able to capture video using back camera but couldn't find a way to capture video with front camera using c#. Kindly Give me an idea that how can i achieve my task ,your help would be appreciated.
Thanks in Advance.

C#
public partial class Movies : PhoneApplicationPage
    {
        
        VideoBrush myvideobrush;      //for capturing video.
        CaptureSource myvideosource;  //source for capturing video.
        VideoCaptureDevice mydevice;  //device for capturing video.
        FileSink myfilesink;          //for storing the video.
        private string isoVideoFileName = "CameraMovie.mp4";
        private IsolatedStorageFileStream isoVideoFile;
        

        public Movies()
        {

            InitializeComponent();
            if (myvideosource == null)
            {
                myvideosource = new CaptureSource();
                myfilesink = new FileSink();
                mydevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
               
                //System.Collections.ObjectModel.ReadOnlyCollection<System.Windows.Media.VideoCaptureDevice> supportedcams = CaptureDeviceConfiguration.GetAvailableVideoCaptureDevices();
                //mydevice = supportedcams.ElementAt(0);
            }
            if (mydevice != null)
            {
                myvideobrush = new VideoBrush();

                myvideobrush.SetSource(myvideosource);
                viewFinderRectangle.Fill = myvideobrush;
                stop_btn.IsEnabled = false;
                myvideosource.Start();
            }

        }
        public void startReccording()
        {
            start_btn.IsEnabled = false;
            stop_btn.IsEnabled = true;


            if (myvideosource.VideoCaptureDevice != null && myvideosource.State == CaptureState.Started)
            {
                myvideosource.Stop();
                myfilesink.CaptureSource = myvideosource;
                myfilesink.IsolatedStorageFileName = isoVideoFileName;
            }
            if (myvideosource.VideoCaptureDevice != null && myvideosource.State == CaptureState.Stopped)
            {

                myvideosource.Start();
            }
        }
        public void stopRecording()
        {


            if (myvideosource.VideoCaptureDevice != null && myvideosource.State == CaptureState.Started)
            {
                myvideosource.Stop();

                myfilesink.CaptureSource = null;
                myfilesink.IsolatedStorageFileName = null;
                videoPriview();
            }



        }
        public void videoPriview()
        {

            if (isoVideoFile != null)
            {
                videoPlayer.Play();
            }
            else
            {
                myvideosource.Stop();
                viewFinderRectangle.Fill = null;
                isoVideoFile = new IsolatedStorageFileStream(isoVideoFileName, FileMode.Open, FileAccess.Read, IsolatedStorageFile.GetUserStoreForApplication());
                videoPlayer.SetSource(isoVideoFile);
                videoPlayer.Play();
            }
            start_btn.IsEnabled = true;
            stop_btn.IsEnabled = false;

        }


        private void movies_goback_btn_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.GoBack();
        }

        private void start_btn_Click(object sender, RoutedEventArgs e)
        {
            startReccording();
        }

        private void stop_btn_Click(object sender, RoutedEventArgs e)
        {
            stopRecording();
        }
    }
Posted
Updated 14-Jan-15 2:15am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900