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