简体   繁体   中英

Xamarin.Android : How to use facing camera in Xamarin receipe

I am working on an app based on this receipe from Xamarin. The only problem I faced that I can't overcome seems pretty basic but still, I can't find any clue about it.

This is the receipe I use: https://developer.xamarin.com/recipes/android/media/video/record_video/

I would like to switch from back to face camera.

Can someone help me out with this?

Here's my code:

        protected override void OnCreate (Bundle bundle)
    {
        base.OnCreate (bundle);

        SetContentView (Resource.Layout.Main);

        string path = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/test.mp4";

        var record = FindViewById<Button> (Resource.Id.Record);
        var stop = FindViewById<Button> (Resource.Id.Stop);
        var play = FindViewById<Button> (Resource.Id.Play);       
        var video = FindViewById<VideoView> (Resource.Id.SampleVideoView);

        _player = MediaPlayer.Create(this, Resource.Raw.Non_Mots_1);



        record.Click += delegate {

            video.StopPlayback ();
            _player.Start ();
            recorder = new MediaRecorder ();
            recorder.SetVideoSource (VideoSource.Camera); 
            recorder.SetAudioSource (AudioSource.Mic);              
            recorder.SetOutputFormat (OutputFormat.Default);
            recorder.SetVideoEncoder (VideoEncoder.Default); 
            recorder.SetAudioEncoder (AudioEncoder.Default);      
            recorder.SetOutputFile (path);       
            recorder.SetPreviewDisplay (video.Holder.Surface);         
            recorder.Prepare ();
            recorder.Start ();      
        };

        stop.Click += delegate {

            if (recorder != null) {
                recorder.Stop ();
                _player.Stop();
                recorder.Release ();
            }
        };

        play.Click += delegate {

            var uri = Android.Net.Uri.Parse (path);        
            video.SetVideoURI (uri);
            video.Start ();   
        };
    }

    protected override void OnDestroy ()
    {
        base.OnDestroy ();

        if (recorder != null) {
            recorder.Release ();
            recorder.Dispose ();
            recorder = null;
        }
    }

}

}

尝试使用VideoSource.Surface而不是VideoSource.Camera

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM