gpt4 book ai didi

android - 声明 session 时 Opentok 应用程序崩溃

转载 作者:太空狗 更新时间:2023-10-29 15:41:25 25 4
gpt4 key购买 nike

我正在尝试学习如何使用 TokBox SDK。我刚刚开始编写一个简单的应用程序来显示视频,这样我就可以了解它是如何工作的。我的代码基于 https://tokbox.com/opentok/tutorials/connect-session/android/#connecting 中的示例。但是,每次我初始化 Session 对象时,我的应用程序都会停止工作。我试过用 try/catch block 围绕它,但它仍然崩溃。我的代码如下:

package com.example.ben.toktest;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.RelativeLayout;

import com.opentok.android.Session;

public class MainActivity extends Activity{
private static final String API_KEY= "12345678"; //replaced api key with 12345678 for privacy purposes
RelativeLayout container;
Session session;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

container = (RelativeLayout) findViewById(R.id.main);

session = new Session(MainActivity.this, "12345678", "2_MX40NTEwMjczMn5-MTQxODAyMDUwMjgwMn5PTjdlRDBvSDVYOHBkelZjby80eGZuclN-fg"); //Crashes here
/*session.setSessionListener(new Session.SessionListener() {
@Override
public void onConnected(Session session) {

}

@Override
public void onDisconnected(Session session) {

}

@Override
public void onStreamReceived(Session session, Stream stream) {
mStreams.add(stream);
subscriber = new Subscriber(MainActivity.this, stream);
subscriber.setSubscriberListener(new SubscriberListener() {
@Override
public void onConnected(SubscriberKit subscriberKit) {
LayoutParams params = new LayoutParams(getResources().getDisplayMetrics().widthPixels, getResources().getDisplayMetrics().heightPixels);
container.addView(subscriberKit.getView(), params);
}

@Override
public void onDisconnected(SubscriberKit subscriberKit) {

}

@Override
public void onError(SubscriberKit subscriberKit, OpentokError opentokError) {

}
});
session.subscribe(subscriber);

}

@Override
public void onStreamDropped(Session session, Stream stream) {

}

@Override
public void onError(Session session, OpentokError opentokError) {

}
});*/

}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
}

我的 logcat 的输出是:

12-08 17:35:37.240  13677-13677/com.example.ben.toktest W/ActivityThread﹕ Application com.example.ben.toktest is waiting for the debugger on port 8100...
12-08 17:35:37.250 13677-13677/com.example.ben.toktest I/System.out﹕ Sending WAIT chunk
12-08 17:35:37.355 13677-13684/com.example.ben.toktest I/dalvikvm﹕ Debugger is active
12-08 17:35:37.455 13677-13677/com.example.ben.toktest I/System.out﹕ Debugger has connected
12-08 17:35:37.455 13677-13677/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle...
12-08 17:35:37.655 13677-13677/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle...
12-08 17:35:37.855 13677-13677/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle...
12-08 17:35:38.055 13677-13677/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle...
12-08 17:35:38.255 13677-13677/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle...
12-08 17:35:38.455 13677-13677/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle...
12-08 17:35:38.655 13677-13677/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle...
12-08 17:35:38.855 13677-13677/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle...
12-08 17:35:39.060 13677-13677/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle...
12-08 17:35:39.260 13677-13677/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle...
12-08 17:35:39.460 13677-13677/com.example.ben.toktest I/System.out﹕ debugger has settled (1374)
12-08 17:35:40.105 13677-13677/com.example.ben.toktest W/dalvikvm﹕ Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/opentok/android/Session;
12-08 17:35:40.105 13677-13677/com.example.ben.toktest D/AndroidRuntime﹕ Shutting down VM
12-08 17:35:40.105 13677-13677/com.example.ben.toktest W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40edb2a0)
12-08 17:35:40.205 13677-13677/com.example.ben.toktest E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
at com.example.ben.toktest.MainActivity.onCreate(MainActivity.java:22)
at android.app.Activity.performCreate(Activity.java:5206)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
at android.app.ActivityThread.access$600(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsatisfiedLinkError: Couldn't load opentok: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:365)
at java.lang.System.loadLibrary(System.java:535)
at com.opentok.android.Session.<clinit>(Session.java:46)
            at com.example.ben.toktest.MainActivity.onCreate(MainActivity.java:22)
            at android.app.Activity.performCreate(Activity.java:5206)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
            at android.app.ActivityThread.access$600(ActivityThread.java:140)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4898)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
            at dalvik.system.NativeStart.main(Native Method)
12-08 17:36:01.010 14367-14367/com.example.ben.toktest W/ActivityThread﹕ Application com.example.ben.toktest is waiting for the debugger on port 8100...
12-08 17:36:01.020 14367-14367/com.example.ben.toktest I/System.out﹕ Sending WAIT chunk
12-08 17:36:01.070 14367-14373/com.example.ben.toktest I/dalvikvm﹕ Debugger is active
12-08 17:36:01.220 14367-14367/com.example.ben.toktest I/System.out﹕ Debugger has connected
12-08 17:36:01.220 14367-14367/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle...
12-08 17:36:01.420 14367-14367/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle...
12-08 17:36:01.620 14367-14367/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle...
12-08 17:36:01.820 14367-14367/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle...
12-08 17:36:02.020 14367-14367/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle...
12-08 17:36:02.225 14367-14367/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle...
12-08 17:36:02.425 14367-14367/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle...
12-08 17:36:02.630 14367-14367/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle...
12-08 17:36:02.845 14367-14367/com.example.ben.toktest I/System.out﹕ waiting for debugger to settle...
12-08 17:36:03.045 14367-14367/com.example.ben.toktest I/System.out﹕ debugger has settled (1459)
12-08 17:36:03.395 14367-14367/com.example.ben.toktest W/dalvikvm﹕ Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/opentok/android/Session;
12-08 17:36:03.400 14367-14367/com.example.ben.toktest D/AndroidRuntime﹕ Shutting down VM
12-08 17:36:03.400 14367-14367/com.example.ben.toktest W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40edb2a0)
12-08 17:36:03.425 14367-14367/com.example.ben.toktest E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
at com.example.ben.toktest.MainActivity.onCreate(MainActivity.java:22)
at android.app.Activity.performCreate(Activity.java:5206)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
at android.app.ActivityThread.access$600(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsatisfiedLinkError: Couldn't load opentok: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:365)
at java.lang.System.loadLibrary(System.java:535)
at com.opentok.android.Session.<clinit>(Session.java:46)
            at com.example.ben.toktest.MainActivity.onCreate(MainActivity.java:22)
            at android.app.Activity.performCreate(Activity.java:5206)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
            at android.app.ActivityThread.access$600(ActivityThread.java:140)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4898)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
            at dalvik.system.NativeStart.main(Native Method)

有人可以告诉我为什么它总是崩溃吗?我不知道我做错了什么!

最佳答案

我在尝试使用 Android Studio 运行 OpenTok 示例应用程序时遇到了同样的问题。

试试这个:

1) 打开您的 app/build.gradle 文件并添加行

编译文件('libs/opentok-android-sdk-2.2.1.jar')

在依赖下。

2) 在您的应用程序文件夹下创建一个文件夹libs(如果它还不存在的话)

3) 将 OpenTok JAR 文件 (opentok-android-sdk-2.3.1.jar) 从 OpenTok SDK libs 文件夹复制到您的app/libs 文件夹

4) 在app/src/main/下创建文件夹jniLibs

5) 将文件夹 armeabix86 从 OpenTok SDK libs 文件夹复制到 jniLibs 文件夹,然后运行您的应用。

希望对您有所帮助!

关于android - 声明 session 时 Opentok 应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27352722/

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