Bug 12977 - TakeVideoAsync does not work when user switches between rear to front facing camera
Summary: TakeVideoAsync does not work when user switches between rear to front facing ...
Status: NEEDINFO
Alias: None
Product: Mobile API (Preview)
Classification: Xamarin
Component: Xamarin.Android ()
Version: Preview 0.6.3
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bill Holmes
URL:
Depends on:
Blocks:
 
Reported: 2013-07-01 10:21 UTC by pascal
Modified: 2017-05-17 14:19 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 12977 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEEDINFO

Description pascal 2013-07-01 10:21:23 UTC
Hi

Hardware:
HTC Sensation XE with Beats Audio

I've put below the code which I'm running but here are the steps to reproduce:
1. Run the app
2. Click to start capturing a video (calling TakeVideo method below)
3. The phone's Camera shows up
4. Switch from rear to front facing camera (or vice versa)
5. Touch the Camera record button
=> The recording gets cancelled straight away and user cannot record a video.

Anything I need to do to prevent this from happening?

Thanks for the help.

Note that on this particular model, the rear facing camera always seems to be picked up regardless of whether CameraDevice.Front or CameraDevice.Rear is specified.

[Activity (Label = "MediaPickerSample", MainLauncher = true)]
public class MainActivity : Activity
{
    int count = 1;

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

        // Set our view from the "main" layout resource
        SetContentView (Resource.Layout.Main);

        // Get our button from the layout resource,
        // and attach an event to it
        Button button = FindViewById<Button> (Resource.Id.myButton);
        
        button.Click += delegate {
            TakeVideo();
        };
    }

    private void TakeVideo(){

        var picker = new MediaPicker(this);
        if (!picker.IsCameraAvailable)
            return;
        VideoView videoView = FindViewById<VideoView> (Resource.Id.videoView1);
        picker.TakeVideoAsync (new StoreVideoOptions
                               {
            Directory = "Xamovies",
            DefaultCamera = CameraDevice.Front,
            DesiredLength = TimeSpan.FromMinutes (5)
        })
            .ContinueWith (t =>
                           {
                if (t.IsCanceled)
                {
                    // IsCanceled always returns true when 
                    // following the steps above.
                    return;                
                }
                
                if (t.IsFaulted) // error
                    return;

                videoView.SetVideoPath (t.Result.Path);
            });
    }
}
Comment 1 Eric Maupin 2013-07-09 17:06:40 UTC
> Note that on this particular model, the rear facing camera always seems to be
picked up regardless of whether CameraDevice.Front or CameraDevice.Rear is
specified.

As per the API remarks (http://componentsapi.xamarin.com/?link=P%3aXamarin.Media.StoreCameraMediaOptions.DefaultCamera), DefaultCamera is only a hint. As you're seeing here, Android ignores this setting.

I was unable to reproduce this on my local device. Are you using the default camera app on this device or some other app?
Comment 2 pascal 2013-07-10 05:22:39 UTC
Hi Eric,

Yes I am using the default camera app on the device. I looked at the settings but could not see anything specific related to front/rear camera.

Not sure whether that helps but as a test, I ran something like the code below in my app instead of the one from Xamarin.Mobile:

var intent = new Intent(MediaStore.ActionVideoCapture);
StartActivityForResult(intent, 12345678);

This opens the camera app (same one as when I use Xamarin.Mobile). I can switch to the front facing camera and start recording without any problem.

If you don't think there's anyway to track down this bug, let me know; I'll just have to bypass the component and implement the above in my app.

Thanks again for your prompt response
Pascal
Comment 3 Eric Maupin 2013-07-10 12:54:58 UTC
(In reply to comment #2)

> Not sure whether that helps but as a test, I ran something like the code below
> in my app instead of the one from Xamarin.Mobile

Possibly, MediaPicker does this same thing internally, but with some extra proeprties. Can you try adding:

intent.PutExtra (MediaStore.ExtraDurationLimit, 300);
intent.PutExtra (MediaStore.ExtraVideoQuality, 2);

> If you don't think there's anyway to track down this bug, let me know; I'll
> just have to bypass the component and implement the above in my app.

I don't think we're there yet, but based on your feature requests, you may have to anyway.
Comment 4 pascal 2013-07-11 05:10:21 UTC
Yep. That's the problem. So if I set the Quality to Low then it all works fine. My next question then is whether there's a way to find the 'best available' video quality for the front facing camera _before_ I set it in the StoreVideoOptions?

This works:

picker.TakeVideoAsync(
        new StoreVideoOptions
            {
                    Name = this.RecordVideoResponseViewModel.VideoFileName, 
                    Directory = string.Empty, 
                    DefaultCamera = CameraDevice.Front, 
                    Quality = VideoQuality.Low, 
                    DesiredLength = seconds
            });
Comment 5 Eric Maupin 2013-07-11 12:11:26 UTC
(In reply to comment #4)

> My next question then is whether there's a way to find the 'best available'
> video quality for the front facing camera _before_ I set it in the
> StoreVideoOptions?

Not in Xamarin.Mobile specifically, this is the first report of this issue. You might try http://developer.android.com/reference/android/media/CamcorderProfile.html#hasProfile(int, int) . If it works for you, please let me know.