nativescript:无法将对象转换为 Landroid/view/textureview/surfacetexturelistener

nativescript: cannot convert object to Landroid/view/textureview/surfacetexturelistener

我正在尝试在 nativescript 插件(typescript)中实现 java 接口 但是当我打电话给 view 它给了我这个错误。无法将对象转换为 Landroid/view/textureview/surfacetexturelistener

我假设我的打字稿 class 没有实现接口 SurfaceTextureListener。但是我添加了所有需要的 4 种方法。

这里正在工作 java 代码

public class FFmpegRecordActivity extends AppCompatActivity implements
        TextureView.SurfaceTextureListener, View.OnClickListener {
    ...
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPreview = (FixedRatioCroppedTextureView) findViewById(R.id.camera_preview);

        mCameraId = Camera.CameraInfo.CAMERA_FACING_FRONT;
        // Switch width and height
        mPreview.setPreviewSize(previewHeight, previewWidth);
        mPreview.setCroppedSizeWeight(videoWidth, videoHeight);
        mPreview.setSurfaceTextureListener(this);

    }
    @Override
    public void onSurfaceTextureAvailable(final SurfaceTexture surface, int width, int height) {
        startPreview(surface);
    }

    @Override
    public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
    }

    @Override
    public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
        return true;
    }

    @Override
    public void onSurfaceTextureUpdated(SurfaceTexture surface) {
    }
    ...
}

我正在尝试的 Typescript 代码

export class NumberPicker extends view.View {
  public _createUI() {
    // this._android = new android.widget.NumberPicker(this._context);
    this.mCameraId = android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT;

    this._android = new com.github.crazyorr.ffmpegrecorder.FixedRatioCroppedTextureView(this._context);

    this._android.setPreviewSize(100, 100);
    this._android.setCroppedSizeWeight(100, 100);
    this._android.setSurfaceTextureListener(this);
    console.log("my-plugin - Android : _createUI")
  };
  public onSurfaceTextureAvailable(surface, width, height) {
    this.startPreview(surface);
  }

  public onSurfaceTextureSizeChanged(surface, width, height) {
  }

  public onSurfaceTextureDestroyed(surface): Boolean {
    return true;
  }

  public onSurfaceTextureUpdated(surface) {
  }
}

我尝试添加

declare var android:any;
// @Interfaces([android.view.TextureView.SurfaceTextureListener]) /* the interfaces that will be inherited by the resulting MyVersatileCopyWriter class */
export class NumberPicker extends view.View implements  {
  // interfaces:[android.view.TextureView.SurfaceTextureListener]

但是在ts编译器中都出现了找不到android的错误

我认为您需要将 implements android.view.TextureView.SurfaceTextureListener 添加到您的组件