我正在尝试在nativescript插件中实现java接口(typescript) 但是当我调用视图时它会给我这个错误。无法将对象转换为Landroid / view / textureview / surfacetexturelistener
我假设我的typescript类没有实现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编译器中找到android
答案 0 :(得分:0)
我认为您需要将implements android.view.TextureView.SurfaceTextureListener
添加到您的组件