locked
using mediacapture in c++

    Question

  • void MainPage::CameraInit()
    {
    	preview->Source = nullptr;
    	try
    	{
    		auto mediacapture = ref new Windows::Media::Capture::MediaCapture();
    		m_mediacapturemgr = mediacapture;
    		create_task(m_mediacapturemgr->InitializeAsync()).then([this](task<void> initTask)
    		{
    			try
    			{
    				initTask.get();
    				auto mediacapture = m_mediacapturemgr.Get();
    			}
    			catch (Exception^ e)
    			{ 
    			}
    		});
    	}
    	catch (Exception^ e)
    	{
    		preview->Source = nullptr;
    	}
    }
    
    void MainPage::CameraPreview()
    {
    	try
    	{
    		auto mediacapture = m_mediacapturemgr.Get();
    		preview->Source = mediacapture;
    		create_task(mediacapture->StartPreviewAsync()).then([this](task<void> previewTask)
    		{
    			try
    			{
    				previewTask.get();
    				auto mediaCapture = m_mediacapturemgr.Get();
    			}
    			catch (Exception^ e)
    			{
    				preview->Source = nullptr;
    			}
    		});
    	}
    	catch (Exception^ e)
    	{
    		preview->Source = nullptr;
    	}
    }

    Here is my code following the example of the MediaCapture from MSDN.

    I have reduced a lot of code which is unnecessary for me into this and I am getting an error of "HRESULT:0xC00D36B6 This object needs to be initialized before the requested operation can be carried out" which the pointer points at the preview->Source = mediacapture; at the CameraPreview and I have searched on internet and still have no idea what is wrong with it.

    namespace App4
    {
    	/// <summary>
    	/// An empty page that can be used on its own or navigated to within a Frame.
    	/// </summary>
    	public ref class MainPage sealed
    	{
    	public:
    		MainPage();
    	private:
    		void CameraInit();
    		void CameraPreview();
    		Platform::Agile<Windows::Media::Capture::MediaCapture> m_mediacapturemgr;
    	};
    }

    and here is my .h file

    Thanks in advance

    Saturday, April 18, 2015 10:27 PM

Answers

  • Hi smallfishy,

    HRESULT:0xC00D36B6 This object needs to be initialized before the requested operation can be carried out.

    Sounds like you do not have the camera initialized before trying to use it, you could ref to this sample for the code snippet: https://code.msdn.microsoft.com/windowsapps/Media-Capture-Sample-adf87622

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 20, 2015 9:48 AM
    Moderator