Opentok android Nativescript音频设备在发布时崩溃

问题描述 投票:0回答:1

使用Android SDK插件(Nativescript-opentok)时,Opentok当前出现错误。使用Maven的SDK版本为2.17。+,该插件来自NativeScript MarketPlace。

我能够进行连接,也可以订阅使用OpenTok JS 2.15.1的另一个供稿,但是当我使用Android手机进行发布时,OpenTok会向我返回一个发布者错误:协商超时,该错误不在OpenTok.Error对象列表,它永远不会被SDK本身抛出,而是仅在其网站上的Opentok Developer Inspector中可见。我可以授予我的摄像头和麦克风访问权限,因为当我连接到会话时,可以在发布者视图标签中看到自己的摄像头。

另外,我的音频使整个应用程序崩溃。

这是我的OpenTok Nativescript Angular代码:

 ngAfterViewInit(): void {


    this.publisher = <TNSOTPublisher>this.publisherView.nativeElement;
    this.subscriber = <TNSOTSubscriber>this.subscriberView.nativeElement;


    this.session = TNSOTSession.initWithApiKeySessionId(
        this._apiKey,
        this._videoChatRoomId
    );

    this.animation.clearAnimations();

    this.publisher.events.on("streamReceived", (data: any) => {
        this.subscriber.subscribe(this.session, data.object.stream);
        this.initPublisher();
    });

    this.session.events.on("streamReceived", (data: any) => {
        this.subscriber.subscribe(this.session, data.object.stream);
        console.log("WEB_JS: " +  data.object.stream.getConnection().getConnectionId());
        this.initPublisher();

    });

    this.session.events.on("streamDestroyed", (data: any) => {
        this.subscriber.unsubscribe(this.session);
    });

    this.publisher.events.on("streamCreated", (publisher:any, data: any) => {
    });


    this.session.events.on("sessionDidConnect", (data: any) => {
        this.isConnected = true;
        this.openTokService.onStartPublish.emit("");
        console.log("MOBILE : " + data.object.session.connection.getConnectionId());

    });

    this.session.events.on('sessionDidDisconnect', function (result) {
        this.isConnected = false;

    });

    this.session.events.on("didFailWithError", (data) => {

        const message = data.object.error.errorMessage;
        console.log(message);
        console.log(data.object.error.getErrorCode());
    });

    this.publisher.events.on("didFailWithError", (data: any) => {
        const message = data.object.error.errorMessage;
        console.log(message);
        console.log(data.object.error.getErrorCode());
    });

    setTimeout(()=> {
        this.publisher.publish(this.session, "", "HIGH", "30");
        this.session.connect(this._token);
    },10);

}

Publisher.JS(插件发布者对象类):

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
 var utils = require("tns-core-modules/utils/utils");
 var view_1 = require("tns-core-modules/ui/core/view");
 var observable_1 = require("tns-core-modules/data/observable");
var CameraListener = com.opentok.android.Publisher.CameraListener;
var PublisherListener = com.opentok.android.PublisherKit.PublisherListener;
var Publisher = com.opentok.android.Publisher;
var BaseVideoRenderer = com.opentok.android.BaseVideoRenderer;
var AbsoluteLayout = android.widget.AbsoluteLayout;
var RelativeLayout = android.widget.RelativeLayout;
var renderStyle = new view_1.CssProperty({
name: 'renderStyle',
cssName: 'render-style',
defaultValue: 'fill',
valueConverter: function (v) { return String(v); }
 });
 var TNSOTPublisher = (function (_super) {
__extends(TNSOTPublisher, _super);
function TNSOTPublisher() {
    var _this = _super.call(this) || this;
    _this._events = observable_1.fromObject({});
    return _this;
}
Object.defineProperty(TNSOTPublisher.prototype, "android", {
    get: function () {
        return this.nativeView;
    },
    enumerable: true,
    configurable: true
   });
  TNSOTPublisher.prototype.createNativeView = function () {
    return new android.widget.LinearLayout(this._context);
   };
   TNSOTPublisher.prototype.publish = function (session, name, cameraResolution, cameraFrameRate) {

    var that = new WeakRef(this);
    this._publisher = new com.opentok.android.Publisher(utils.ad.getApplicationContext(), name ? name 
    : '', TNSOTPublisher.getCameraResolution(cameraResolution), 
   TNSOTPublisher.getCameraFrameRate(cameraFrameRate));
    var pub = this._publisher.getView();
    this.nativeView.addView(pub);
    this.renderStyle = this._renderStyle;
    this._publisher.setPublisherListener(new PublisherListener({
        owner: that.get(),
        onError: function (publisher, error) {
            if (this.owner._events) {
                this.owner._events.notify({
                    eventName: 'didFailWithError',
                    object: observable_1.fromObject({
                        publisher: publisher,
                        error: error
                    })
                });
            }
        },
        onStreamCreated: function (publisher, stream) {
            if (this.owner._events) {
                this.owner._events.notify({
                    eventName: 'streamCreated',
                    object: observable_1.fromObject({
                        publisher: publisher,
                        stream: stream
                    })
                });
            }
        },
        onStreamDestroyed: function (publisher, stream) {
            if (this.owner._events) {
                this.owner._events.notify({
                    eventName: 'streamDestroyed',
                    object: observable_1.fromObject({
                        publisher: publisher,
                        stream: stream
                    })
                });
            }
        }
      }));
      this._publisher.setCameraListener(new CameraListener({
        owner: that.get(),
        onCameraChanged: function (publisher, newCameraId) {
            if (this.owner._events) {
                this.owner._events.notify({
                    eventName: 'cameraChanged',
                    object: observable_1.fromObject({
                        publisher: publisher,
                        cameraId: newCameraId
                    })
                });
            }
        }, onCameraError: function (publisher, error) {
            if (this.owner._events) {
                this.owner._events.notify({
                    eventName: 'cameraError',
                    object: observable_1.fromObject({
                        publisher: publisher,
                        error: error
                    })
                });
            }
        }
      }));
     var _this = this;
     session.events.on('sessionDidConnect',function(event){
        try{
            session.session.publish(_this._publisher);
          } catch {
              console.log('error');
          }
    });

    };
   TNSOTPublisher.getCameraResolution = function (cameraResolution) {
    if (cameraResolution) {
        switch (cameraResolution.toString().toUpperCase()) {
            case 'LOW':
                return com.opentok.android.Publisher.CameraCaptureResolution.LOW;
            case 'MEDIUM':
                return com.opentok.android.Publisher.CameraCaptureResolution.MEDIUM;
            case 'HIGH':
                return com.opentok.android.Publisher.CameraCaptureResolution.HIGH;
        }
    }
    return com.opentok.android.Publisher.CameraCaptureResolution.MEDIUM;
   };
   TNSOTPublisher.getCameraFrameRate = function (cameraFrameRate) {
    if (cameraFrameRate) {
        switch (Number(cameraFrameRate)) {
            case 30:
                return com.opentok.android.Publisher.CameraCaptureFrameRate.FPS_30;
            case 15:
                return com.opentok.android.Publisher.CameraCaptureFrameRate.FPS_15;
            case 7:
                return com.opentok.android.Publisher.CameraCaptureFrameRate.FPS_7;
            case 1:
                return com.opentok.android.Publisher.CameraCaptureFrameRate.FPS_1;
        }
    }
    return com.opentok.android.Publisher.CameraCaptureFrameRate.FPS_30;
};
TNSOTPublisher.prototype[renderStyle.setNative] = function (value) {
    this._renderStyle = value;
    switch (value) {
        case 'fill':

 this._publisher.getRenderer().setStyle(com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_SCALE, 
 com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_FILL);
            break;
        case 'scale':

 this._publisher.getRenderer().setStyle(com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_SCALE, 
 com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_SCALE);
            break;
        default:

 this._publisher.getRenderer().setStyle(com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_SCALE, 
  com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_FIT);
             break;
    }
  };
Object.defineProperty(TNSOTPublisher.prototype, "publisher", {
    get: function () {
        return this._publisher;
    },
    enumerable: true,
    configurable: true
});
Object.defineProperty(TNSOTPublisher.prototype, "events", {
    get: function () {
        return this._events;
    },
    enumerable: true,
    configurable: true
});
TNSOTPublisher.prototype.toggleCamera = function () {
    this.publishVideo = !this.publishVideo;
};
TNSOTPublisher.prototype.toggleVideo = function () {
    this.publishVideo = !this.publishVideo;
};
TNSOTPublisher.prototype.toggleMute = function () {
    this.publishAudio = !this.publishAudio;
};
Object.defineProperty(TNSOTPublisher.prototype, "publishVideo", {
    get: function () {
        return this._publisher.getPublishVideo();
    },
    set: function (state) {
        this._publisher.setPublishVideo(state);
    },
    enumerable: true,
    configurable: true
});
Object.defineProperty(TNSOTPublisher.prototype, "publishAudio", {
    get: function () {
        return this._publisher.getPublishAudio();
    },
    set: function (state) {
        this._publisher.setPublishAudio(state);
    },
    enumerable: true,
    configurable: true
});
TNSOTPublisher.prototype.cycleCamera = function () {
    this._publisher.cycleCamera();
};
TNSOTPublisher.prototype.instance = function () {
    return this._publisher;
};
TNSOTPublisher.prototype.unpublish = function (session) {
    session.session.unpublish(this._publisher);
};
return TNSOTPublisher;
}(view_1.View));
TNSOTPublisher.toggleVideoEvent = "toggleVideo";
TNSOTPublisher.toggleAudioEvent = "toggleAudio";
exports.TNSOTPublisher = TNSOTPublisher;
renderStyle.register(view_1.Style);
//# sourceMappingURL=publisher.js.map

过去有人收到此错误吗?如果是这样,您是否会知道为什么会有超时?

谢谢!

android nativescript opentok tokbox
1个回答
0
投票

我添加了一个答案以使问题更清晰,这与设备上的音频权限有关吗?

Adb logcat崩溃报告:

05-26 12:16:40.157  1604  1747 F atrCompanionAp: java_vm_ext.cc:570] JNI DETECTED ERROR IN APPLICATION: JNI GetObjectClass called with pending exception java.lang.RuntimeException: Audio capture is not initialized 44100
05-26 12:16:40.157  1604  1747 F atrCompanionAp: java_vm_ext.cc:570]   at boolean com.opentok.android.DefaultAudioDevice.initCapturer() ((null):-1)

...之间的堆栈跟踪

05-26 12:16:40.292  1604  1747 F atrCompanionAp: runtime.cc:630]   native: #28 pc 000000000043c9d8  /apex/com.android.runtime/lib64/libart.so (art::Method_invoke(_JNIEnv*, _jobject*, _jobject*, _jobjectArray*)+52)
05-26 12:16:40.292  1604  1747 F atrCompanionAp: runtime.cc:630]   native: #00 pc 000000000008033c  /apex/com.android.runtime/lib64/bionic/libc.so (syscall+28)
05-26 12:16:40.292  1604  1747 F atrCompanionAp: runtime.cc:630]   | held mutexes=
05-26 12:16:40.292  1604  1747 F atrCompanionAp: runtime.cc:630]   at java.lang.Object.wait(Object.java:442)
05-26 12:16:40.292  1604  1747 F atrCompanionAp: runtime.cc:630]   native: #05 pc 00000000001db8d4  /data/app/org.nativescript.AvatrCompanionApp-vK0zREAM_BobIo-Eksgn2Q==/lib/arm64/libopentok.so (???)
05-26 12:16:40.292  1604  1747 F atrCompanionAp: runtime.cc:630]   (no managed stack frames)
05-26 12:16:40.293  1604  1747 F atrCompanionAp: runtime.cc:630]   (no managed stack frames)
05-26 12:16:40.293  1604  1747 F atrCompanionAp: runtime.cc:630]   native: #10 pc 00000000003582bc  /apex/com.android.runtime/lib64/libart.so (art::(anonymous namespace)::CheckJNI::GetObjectClass(_JNIEnv*, _jobject*)+668)
05-26 12:16:40.293  1604  1747 F atrCompanionAp: runtime.cc:630]   native: #23 pc 0000000000084b6c  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64)
05-26 12:16:40.293  1604  1747 F atrCompanionAp: runtime.cc:638] JNI DETECTED ERROR IN APPLICATION: JNI GetObjectClass called with pending exception java.lang.RuntimeException: Audio capture is not initialized 44100
© www.soinside.com 2019 - 2024. All rights reserved.