2012-03-23 6 views
0

Я создал класс, который происходит от System.Windows.Media.AudioSink, чтобы обеспечить возможности записи. Для того, чтобы проверить состояние моей конкретной раковины я следующее:InvalidOperationException при проверке CaptureSource.State

public class MyViewModel 
{ 
    private readonly MyAudioSink _myAudioSink; // this field is ensured in the ctor 
    public bool IsRecording 
    { 
     get 
     { 
      if (this._myAudioSink == null) 
      { 
       return false; // I know that `false` is wrong ... 
      } 
      return this._myAudioSink.CaptureSource.State == CaptureState.Started; 
     } 
    } 
} 

Иногда, когда я запрашиваю против proprety IsRecording, я получаю следующее исключение:

{System.InvalidOperationException: Capture source is not stopped 
    at MS.Internal.XcpImports.CheckHResult(UInt32 hr) 
    at MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty property, DependencyObject doh) 
    at System.Windows.DependencyObject.SetValue(DependencyProperty property, DependencyObject doh) 
    at System.Windows.Media.CaptureSource..ctor() 
    at MS.Internal.CoreTypes.GetCoreWrapper(UInt32 typeId) 
    at MS.Internal.ManagedPeerTable.EnsureManagedPeer(IntPtr unmanagedPointer, Int32 typeIndex, Type type, Boolean preserveManagedObjectReference) 
    at MS.Internal.XcpImports.ConvertDO(IntPtr doPointer, Int32 typeIndex, Boolean releaseObjectReference) 
    at MS.Internal.XcpImports.ConvertType(CValue outVal, Int32 typeIndex, Boolean releaseObjectReference, Boolean deleteBuffer, IManagedPeerBase fromObject) 
    at MS.Internal.XcpImports.AudioSink_GetSource(AudioSink Sink) 
    at System.Windows.Media.AudioSink.get_CaptureSource() 
    at MyViewModel.get_IsRecording() 

Иногда, когда я this._myAudioSink.Stop(), я получаю следующее (подобное) исключение:

{System.InvalidOperationException: Capture source is not stopped 
    at MS.Internal.XcpImports.CheckHResult(UInt32 hr) 
    at MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty property, DependencyObject doh) 
    at System.Windows.DependencyObject.SetValue(DependencyProperty property, DependencyObject doh) 
    at System.Windows.Media.CaptureSource..ctor() 
    at MS.Internal.CoreTypes.GetCoreWrapper(UInt32 typeId) 
    at MS.Internal.ManagedPeerTable.EnsureManagedPeer(IntPtr unmanagedPointer, Int32 typeIndex, Type type, Boolean preserveManagedObjectReference) 
    at MS.Internal.XcpImports.ConvertDO(IntPtr doPointer, Int32 typeIndex, Boolean releaseObjectReference) 
    at MS.Internal.XcpImports.ConvertType(CValue outVal, Int32 typeIndex, Boolean releaseObjectReference, Boolean deleteBuffer, IManagedPeerBase fromObject) 
    at MS.Internal.XcpImports.AudioSink_GetSource(AudioSink Sink) 
    at System.Windows.Media.AudioSink.get_CaptureSource() 

Итак ... в чем причина? Как я могу предотвратить это исключение (кроме введения моего собственного поля и установить его в переопределениях OnCaptureStarted и OnCaptureStopped)?

Единственная тема по этой проблеме я нашел в сети является here ...

ответ

0

Я закончил с перекрывая определенные команды (OnCaptureStopped, OnCaptureStarted, ..), чтобы инкапсулировать состояние в моей модели И инкапсулировал captureSource внутри моего конкретного аудио-приемника в отдельном поле.

Очевидно, что это трюк, и у меня больше не было проблем.

PS: Я где-то читал, что инкапсуляции captureSource должно быть достаточно - atm Я не могу предоставить ссылку ... это где-то там, sry!

Смежные вопросы