void Player_::HandleEvent(UINT_PTR pEventPtr) { MediaEventType meType = MEUnknown; IMFMediaEventPtr pEvent; // pEvent.Attach((IMFMediaEvent*)pEventPtr); pEvent.Attach(reinterpret_cast<IMFMediaEvent*>(pEventPtr)); if (!pEvent) { throw win32_error_exception(E_POINTER); } // Get the event type. THROW_IF_ERR(pEvent->GetType(&meType)); // Get the event status. If the operation that triggered the event // did not succeed, the status is a failure code. HRESULT hrStatus = S_OK; THROW_IF_ERR(pEvent->GetStatus(&hrStatus)); // Check if the async operation succeeded. THROW_IF_ERR(hrStatus); switch(meType) { case MESessionTopologyStatus: OnTopologyStatus(pEvent); break; case MEEndOfPresentation: OnPresentationEnded(pEvent); break; case MENewPresentation: OnNewPresentation(pEvent); break; default: OnSessionEvent(pEvent, meType); break; } }
HRESULT CPlayer::HandleEvent(UINT_PTR pUnkPtr) { HRESULT hr = S_OK; HRESULT hrStatus = S_OK; // Event status MediaEventType meType = MEUnknown; // Event type MF_TOPOSTATUS TopoStatus = MF_TOPOSTATUS_INVALID; // Used with MESessionTopologyStatus event. IUnknown *pUnk = NULL; IMFMediaEvent *pEvent = NULL; // pUnkPtr is really an IUnknown pointer. pUnk = (IUnknown*)pUnkPtr; if (pUnk == NULL) { return E_POINTER; } CHECK_HR(hr = pUnk->QueryInterface(__uuidof(IMFMediaEvent), (void**)&pEvent)); // Get the event type. CHECK_HR(hr = pEvent->GetType(&meType)); // Get the event status. If the operation that triggered the event did // not succeed, the status is a failure code. CHECK_HR(hr = pEvent->GetStatus(&hrStatus)); TRACE((L"Media event: %s\n", EventName(meType))); // Check if the async operation succeeded. if (SUCCEEDED(hrStatus)) { // Switch on the event type. Update the internal state of the CPlayer as needed. switch(meType) { case MESessionTopologyStatus: // Get the status code. CHECK_HR(hr = pEvent->GetUINT32(MF_EVENT_TOPOLOGY_STATUS, (UINT32*)&TopoStatus)); switch (TopoStatus) { case MF_TOPOSTATUS_READY: hr = OnTopologyReady(pEvent); break; default: // Nothing to do. break; } break; case MEEndOfPresentation: CHECK_HR(hr = OnPresentationEnded(pEvent)); break; } } else { hr = hrStatus; } done: SAFE_RELEASE(pUnk); SAFE_RELEASE(pEvent); return hr; }
HRESULT CPlayer::HandleEvent(UINT_PTR pEventPtr) { HRESULT hrStatus = S_OK; HRESULT hr = S_OK; MediaEventType meType = MEUnknown; IMFMediaEvent *pEvent = (IMFMediaEvent*)pEventPtr; if (pEvent == NULL) { return E_POINTER; } // Get the event type. CHECK_HR(hr = pEvent->GetType(&meType)); // Get the event status. If the operation that triggered the event // did not succeed, the status is a failure code. hr = pEvent->GetStatus(&hrStatus); // Check if the async operation succeeded. if (SUCCEEDED(hr) && FAILED(hrStatus)) { CHECK_HR(hr = hrStatus); } switch (meType) { case MESessionTopologyStatus: hr = OnTopologyStatus(pEvent); break; case MEEndOfPresentation: hr = OnPresentationEnded(pEvent); ofLogVerbose("ofxWMFVideoPlayer") << "Presentation Ended"; break; case MENewPresentation: hr = OnNewPresentation(pEvent); ofLogVerbose("ofxWMFVideoPlayer") << "New Presentation"; break; case MESessionTopologySet: IMFTopology * topology; GetEventObject<IMFTopology>(pEvent, &topology); WORD nodeCount; topology->GetNodeCount(&nodeCount); ofLogVerbose("ofxWMFVideoPlayer") << "Topo set and we have " << nodeCount << " nodes" << endl; SafeRelease(&topology); break; case MESessionStarted: ofLogVerbose("ofxWMFVideoPlayer") << "Starting Session"; case MEBufferingStarted: ofLogNotice("ofxWMFVideoPlayer") << "Buffering..."; break; case MEBufferingStopped: ofLogNotice("ofxWMFVideoPlayer") << "Finished Buffering..."; break; default: hr = OnSessionEvent(pEvent, meType); break; } done: SafeRelease(&pEvent); return hr; }