我正在尝试在我的Android应用中实现Web Rtc进行视频聊天,但是出现了错误。
E/rtc: #
# Fatal error in ../../webrtc/modules/audio_device/android/audio_manager.cc, line 77
# Check failed: HasDeviceObjects()
#
#
我在build.gradle和NDK支持中添加了依赖项。
编译'io.pristine:libjingle:9127 @ aar'
ndk {
moduleName "my-module-name"
cFlags "-std=c++11 -fexceptions"
ldLibs "log"
stl "gnustl_shared"
abiFilter "armeabi-v7a"
}
这是代码
public class MainActivity extends AppCompatActivity {
Button cam1;
VideoRenderer videoRenderer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cam1=(Button)findViewById(R.id.button1);
final PeerConnectionFactory peerConnectionFactory=new PeerConnectionFactory();
PeerConnectionFactory.initializeAndroidGlobals(this, true, true, true, true);
//Acquiring source info
int no_of_cams = VideoCapturerAndroid.getDeviceCount(); // no of sources
final String sec_cam = VideoCapturerAndroid.getNameOfFrontFacingDevice(); // sec_cam name
final String pri_cam = VideoCapturerAndroid.getNameOfBackFacingDevice(); // pri_cam name
final VideoCapturer capturer1 = VideoCapturerAndroid.create(sec_cam); //capturer for sec_cam
final MediaConstraints videoConstraints = new MediaConstraints();
final MediaConstraints audioConstraints = new MediaConstraints();
//creating GLSurface
GLSurfaceView glSurfaceView=(GLSurfaceView)findViewById(R.id.gl);
//video renderer gui
VideoRendererGui.setView(glSurfaceView,null);
try {
videoRenderer=VideoRendererGui.createGui(0,0,100,100,
VideoRendererGui.ScalingType.SCALE_ASPECT_FILL,false);
} catch (Exception e) {
e.printStackTrace();
}
// Front Cam Action
cam1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// setting up tracks from sources
VideoSource videoSource = peerConnectionFactory.createVideoSource(capturer1,videoConstraints);
VideoTrack videoTrack = peerConnectionFactory.createVideoTrack(sec_cam, videoSource);
AudioSource audioSource = peerConnectionFactory.createAudioSource(audioConstraints);
AudioTrack audioTrack = peerConnectionFactory.createAudioTrack(sec_cam,audioSource);
// adding video to renderer
videoTrack.addRenderer(videoRenderer);
MediaStream mediaStream=peerConnectionFactory.createLocalMediaStream(sec_cam);
mediaStream.addTrack(videoTrack);
mediaStream.addTrack(audioTrack);
}
});}}
答案 0 :(得分:0)
首先调用initializeAndroidGlobals。
PeerConnectionFactory.initializeAndroidGlobals(this, true, true, true, true);
final PeerConnectionFactory peerConnectionFactory=new PeerConnectionFactory();