【问题标题】:nativescript: cannot convert object to Landroid/view/textureview/surfacetexturelistenernativescript:无法将对象转换为 Landroid/view/textureview/surfacetexturelistener
【发布时间】:2017-03-04 12:02:51
【问题描述】:

我正在尝试在 nativescript 插件(打字稿)中实现 java 接口 但是当我调用视图时,它给了我这个错误。无法将对象转换为 Landroid/view/textureview/surfacetexturelistener

我假设我的打字稿类没有实现接口 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) {
    }
    ...
}

我正在尝试的打字稿代码

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编译器中都出现了cant find android的错误

【问题讨论】:

    标签: nativescript


    【解决方案1】:

    我相信您需要将implements android.view.TextureView.SurfaceTextureListener 添加到您的组件中

    【讨论】:

    • 看来我必须在 ts 中重写这个。我停止使用界面。在实现此接口的 android studio 项目中创建了新类。然后从 nativescript 调用该类
    猜你喜欢
    • 1970-01-01
    • 2020-08-27
    • 1970-01-01
    • 2015-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-24
    相关资源
    最近更新 更多