gpt4 book ai didi

c# - Xamarin Android Visualizer SetDataCaptureListener 抛出 InvalidCastException

转载 作者:搜寻专家 更新时间:2023-11-01 08:28:33 26 4
gpt4 key购买 nike

基于 the answer of this questionthis example我已经使用 Xamarin 实现了一个 Visualizer

myVisualizer = new Visualizer(0);
myVisualizer.SetEnabled(false);
myVisualizer.SetCaptureSize(Visualizer.GetCaptureSizeRange()[1]);
myVisualizer.SetDataCaptureListener(new VisualizerCapturer(), Visualizer.MaxCaptureRate, true, false);

代码一直有效,直到我调用 myVisualizer.SetDataCaptureListener(...) 和异常

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidCastException: Specified cast is not valid. at Android.Media.Audiofx.Visualizer.SetDataCaptureListener (Android.Media.Audiofx.Visualizer+IOnDataCaptureListener listener, System.Int32 rate, System.Boolean waveform, System.Boolean fft) [0x0000b] in /Users/builder/data/lanes/4009/9578cdcd/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Media.Audiofx.Visualizer.cs:811

被抛出。我的 IOnDataCaptureListener 实现没有任何代码(我在方法内部设置了断点,在抛出异常之前没有调用任何方法)

public class VisualizerCapturer : Visualizer.IOnDataCaptureListener
{
public IntPtr Handle
{
get
{
throw new NotImplementedException();
}
}

public void Dispose()
{
throw new NotImplementedException();
}

public void OnFftDataCapture(Visualizer visualizer, byte[] fft, int samplingRate)
{
throw new NotImplementedException();
}

public void OnWaveFormDataCapture(Visualizer visualizer, byte[] waveform, int samplingRate)
{
throw new NotImplementedException();
}
}

我完全不知道我的问题是什么,我希望任何人都可以帮助我解决我的问题。

最佳答案

Visualizer.IOnDataCaptureListener 的实现不继承自 Java.Lang.Object 因此它是一个普通的 C# 类而不是 Android 可调用包装器(ACW ) 基于类,因此您的 VisualizerCapturer 对象无法在 C# 和 Java 运行时之间传递。

Java.Lang.Object 继承您的 VisualizerCapturer 并实现 Visualizer.IOnDataCaptureListener 方法,您将没事的:

public class VisualizerCapturer : Java.Lang.Object, Visualizer.IOnDataCaptureListener
{
~~~~
}

关于c# - Xamarin Android Visualizer SetDataCaptureListener 抛出 InvalidCastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42629257/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com