locked
PPL Task Creation is failing Metro App

    Question

  • I recording the video from USB web cam.When I hit Start video.it creates the file and when I try to open the file it says file in use that's means recoding started. when I press stop recording task creation is failing and files size shows 0 byte. I am PL task to start and start the recording.

    Please help me in this.

    auto _this = this;
    auto stopOp = m_MediaCaptureMgr->StopRecordAsync();
    task<void> t1(stopOp);/// it fails here

    void CameraMetroApp::BlankPage::StartRecording()
    {
     if (!m_recordState)
     {
      auto _this = this;
      auto videoLibrary = KnownFolders::VideosLibrary;
      auto createOp = videoLibrary->CreateFileAsync("cameraCapture.wmv", CreationCollisionOption::GenerateUniqueName);
      task<StorageFile^> t1(createOp);

      t1.then([_this](StorageFile^ resultOp)
      {
       _this->m_VideoStorage = resultOp;
       return _this->m_MediaCaptureMgr->StartRecordToStorageFileAsync(_this->m_EncodingProfile, _this->m_VideoStorage);
      }).then ([_this]()
      {
       _this->m_recordState = true;
       _this->btnRecording->Content = "Stop Recording";
      
      });
      
     }
    }

    void CameraMetroApp::BlankPage::StopRecording()
    {
     auto _this = this;
     auto stopOp = m_MediaCaptureMgr->StopRecordAsync();
     task<void> t1(stopOp);

     t1.then([_this]()
     {
      _this->m_recordState = false;
      _this->btnRecording->Content = "Start Recording";

      return _this->m_VideoStorage->OpenAsync(FileAccessMode::Read);
     }).then([_this](IRandomAccessStream^ streamOp)

    {

    _this->CapturedMedia->SetSource(streamOp, _this->m_VideoStorage->FileType);

    });}

    Here CapturedMedia is the control to show the recorded video.


    • Edited by chris_vr Friday, May 04, 2012 5:51 AM
    Friday, May 04, 2012 5:47 AM

Answers

  • Problem is resolved.

    • Marked as answer by chris_vr Thursday, May 10, 2012 11:30 AM
    Thursday, May 10, 2012 11:30 AM

All replies

  • Hello,

    I think you should follow these codes to record video to files:

      try{   
                IAsyncOperation<StorageFile^>^ op = safe_cast<IAsyncOperation<StorageFile^> ^>(e->Context);
                if(op->Status == AsyncStatus::Completed)
                {
                    ShowStatusMessage("Create record file successful");
                    this->m_recordStorageFile = op->GetResults();    
                    MediaEncodingProfile^ recordProfile= nullptr;
    				if(ScenarioList->SelectedIndex == 0 || ScenarioList->SelectedIndex == 1)
    				{
    					recordProfile = MediaEncodingProfile::CreateMp4(Windows::Media::MediaProperties::VideoEncodingQuality::Auto);
    				}
    				else
    				{
    					recordProfile = MediaEncodingProfile::CreateM4a(Windows::Media::MediaProperties::AudioEncodingQuality::Auto);
    				}
                
                    auto opStartRecord = m_mediaCaptureMgr->StartRecordToStorageFileAsync(recordProfile, this->m_recordStorageFile);                        
                    opStartRecord->Completed = ref new AsyncActionCompletedHandler(this, &MainPage::OnStartRecordCB);                
                }
                else
                {
                    EnableButton(true, "StartStopRecord");
                    ShowStatusMessage("Create record file error");
                }            
            }
            catch(Platform::Exception^ e)
            {
                EnableButton(true, "StartStopRecord");
                ShowExceptionMessage(e);
            }

    You can follow the sample code of Media capture using webcam sample

    http://code.msdn.microsoft.com/windowsapps/Media-Capture-Sample-adf87622

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, May 07, 2012 8:06 AM
  • Hello Chris,

    If you are still having problems with this please let us know. If you are still having problems after talking a look at the sample Jesse posted please forward the error that you are getting during task creation and we will do what we can to help.

    Thanks,

    James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Wednesday, May 09, 2012 1:01 AM
    Moderator
  • Problem is resolved.

    • Marked as answer by chris_vr Thursday, May 10, 2012 11:30 AM
    Thursday, May 10, 2012 11:30 AM