locked
MEPlayerNative-OpenFile Modification-Unhandled Exception in C-runtime

    Question

  • I wanted to modify MEPlayerNative sample to return to the file picker when the selected clip finished playing.  A call to OpenFile() was placed in "MEPlayer::OnMediaEngineEvent" in "case MF_MEDIA_ENGINE_EVENT_ENDED:" to call the file picker, shown below. 

    case MF_MEDIA_ENGINE_EVENT_ENDED:

            if(m_spMediaEngine->HasVideo())
              {
                StopTimer();
              }
            m_fEOS = TRUE;

            OpenFile();

            break;

    When the OpenFile executes when the clip ends, there is an unhandled exception when the task "m_pickFileTask" aka PickSingleFileAsync() executes. 

    Here's the call stack for the failure.

    (1)  MEPlaybackNative.exe!MEPlayer::OpenFile() Line 424 C++

    (2)  MEPlaybackNative.exe Windows::Storage::Pickers::FileOpenPicker::Windows::Storage::Pickers::IFileOpenPicker]::PickSingleFileAsync() C++

    (3)  MEPlaybackNative.exe!__abi_ThrowIfFailed(long hr) Line 57 C++

    (4)  MEPlaybackNative.exe!__abi_WinRTraiseException(long hr) Line 953 C++

    (5)  vccorlib110d.dll!__abi_WinRTraiseCOMException(long hr) Line 282 C++

    (6)  msvcr110d.dll!_CxxThrowException(void * pExceptionObject, const _s__ThrowInfo * pThrowInfo) Line 141 C++

    Unhandled exception at at 0x759156C4 in MEPlaybackNative.exe: Microsoft C++ exception: Platform::COMException ^ at memory location 0x1030F128.

    It seems like this should have worked.  What's causing the unhandled exception?




    • Edited by michaeldvz Sunday, May 6, 2012 9:08 PM
    Sunday, May 6, 2012 8:59 PM

All replies

  •   Hello,

     

    OpenFile function can not be used in Metro Style app.

     

    You should use file pickers instead of it. Please follow this document

    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/Hh771180(v=win.10).aspx

     

    Best regards,

    Jesse


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

    Monday, May 7, 2012 11:34 AM
  • Sorry, I should have been more specific on my question.

    MEPlayerNative project is a sample C++ Metro application that I downloaded from the Metro developer's site.  OpenFile is a method in MEPlayer class of the project.  MEPlayer::OpenFile uses the FileOpenPicker class.  Here's the code.

    void MEPlayer::OpenFile()

    {

    ......some condition detection for initialization, playing, and EOS....

        FileOpenPicker^ getVidFile = ref new FileOpenPicker();

        getVidFile->SuggestedStartLocation = PickerLocationId::VideosLibrary;
        getVidFile->ViewMode = PickerViewMode::Thumbnail;

        getVidFile->FileTypeFilter->Clear();
        getVidFile->FileTypeFilter->Append(".mp4");
        getVidFile->FileTypeFilter->Append(".m4v");
        getVidFile->FileTypeFilter->Append(".mts");
        getVidFile->FileTypeFilter->Append(".mov");
        getVidFile->FileTypeFilter->Append(".wmv");
        getVidFile->FileTypeFilter->Append(".wma");
        getVidFile->FileTypeFilter->Append(".avi");
        getVidFile->FileTypeFilter->Append(".wav");
        getVidFile->FileTypeFilter->Append(".mp3");
        getVidFile->FileTypeFilter->Append(".m4a");
        getVidFile->FileTypeFilter->Append(".asf");

        m_pickFileTask = task<StorageFile^>(getVidFile->PickSingleFileAsync(), m_tcs.get_token());

     *m_pickFileTask.then([this](StorageFile^ fileHandle)

       .....Opens fileHandle as a random access stream for read.

    The place where it calls into the runtime and gets the unhandled exception is in bold and underlined.  It looks like it makes a concurrency task with PickSingleFileAsync().  It executes m_pickFileTask followed by a lambda expression to open the file.  From the call stack (line 2), it looks like PickSingleFileAsync() calls into the runtime and gets the unhandled exception. 

    The call to MEPlayer::OpenFile() did not seem that much different than calling it on a right-click from VideoView.  I have tried using the cancellation token to cancel the m_pickFileTask thinking that it may still be in play, and the exception is the result of trying to run another one.  I placed a call to "m_tcs.cancel()" before the call to MEPlayer::OpenFile(), but it did not help. 


    Michaeldvz

    Monday, May 7, 2012 2:19 PM
  • Hello Michaeldvz,

    I think that you are going to need to check the threading context of the "OnMediaEngineEvent" callback. My guess is that you are executing on a thread other than the UI thread for this callback. To call "PickSingleFileAsync" you are likely going to need to marshal back to the UI thread. Please verify if my assumption is correct. If you need additional help let me know.

    I hope this helps,

    James


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

    Tuesday, May 8, 2012 12:51 AM
    Moderator
  • James,

    I don't understand what you mean by threading context or how to check it.  Do you have a reference on threading context? 

    The other calls to OpenFile() are from the VideoView class.  Is that what you mean by UI thread, the VideoView class?

    "OnMediaEgineEvent" and "OpenFile" are both methods in the MEPlayer class.  In "OnMediaEngineEvent", other case clauses call methods in the MEPlayer class, Play() or StopTimer(), with good results which provided the model of calling OpenFile() from the ME callback function.  When "MF_Media_Event_Ended" occurs, the call to "OpenFile" is successful, and executes up to where it creates m_pickFileTask which is a task containing PickSingleFileAsync() method of the getVidFile class created from the Windows::Storage::Picker::OpenFilePicker class.  This and nested lambda expressions are the main differences between the other methods called from "OnMediaEngineEvent".

    It looks like the exception is taken when the m_pickFileTask is being created.  The exception type falls through to the default of the exception detection and becomes an unhandled exception.  I had assumed that once the file is picked and OpenFile() returns all the resources where released.  Is it possible that the exception is caused by trying to create m_pickFileTask when the previous task still exists? 

    Michael


    Michaeldvz

    Wednesday, May 9, 2012 1:37 PM
  • Hello Michaeldvz,

    It is very likely that the "MEPlayer::OnMediaEngineEvent" is being called by the ME on a thread other than the UI thread. In other words, don't call "OpenFile" from within the "MEPlayer::OnMediaEngineEvent" callback. Marshal the event back to your UI thread and then call "OpenFile" from there.

    I hope this is more clear,

    James


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

    Wednesday, May 9, 2012 11:08 PM
    Moderator