gpt4 book ai didi

java - 在Android应用程序中实现webrtc

转载 作者:行者123 更新时间:2023-12-01 12:48:56 26 4
gpt4 key购买 nike

package fr.pchab.AndroidRTC;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Point;
import android.os.Bundle;
import android.view.Window;
import android.widget.Toast;
import org.json.JSONException;
import org.webrtc.MediaStream;
import org.webrtc.PeerConnectionFactory;
import org.webrtc.VideoRenderer;

import java.util.List;

public class RTCActivity extends Activity implements WebRtcClient.RTCListener{
private final static int VIDEO_CALL_SENT = 666;
private VideoStreamsView vsv;
private WebRtcClient client;
private String mSocketAddress;
private String callerId;


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
mSocketAddress = "http://" + getResources().getString(R.string.host);
mSocketAddress += (":"+getResources().getString(R.string.port)+"/");
PeerConnectionFactory.initializeAndroidGlobals(this);
// Camera display view
Point displaySize = new Point();
getWindowManager().getDefaultDisplay().getSize(displaySize);
vsv = new VideoStreamsView(this, displaySize);
client = new WebRtcClient(this, mSocketAddress);

final Intent intent = getIntent();
final String action = intent.getAction();

if (Intent.ACTION_VIEW.equals(action)) {
final List<String> segments = intent.getData().getPathSegments();
callerId = segments.get(0);
}
}

public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}

@Override
public void onPause() {
super.onPause();
vsv.onPause();
}

@Override
public void onResume() {
super.onResume();
vsv.onResume();
}

@Override
public void onCallReady(String callId) {
if(callerId != null) {
try {
answer(callerId);
} catch (JSONException e) {
e.printStackTrace();
}
} else {
call(callId);
}
}

public void answer(String callerId) throws JSONException {
client.sendMessage(callerId, "init", null);
startCam();
}

public void call(String callId) {
Intent msg = new Intent(Intent.ACTION_SEND);
msg.putExtra(Intent.EXTRA_TEXT, mSocketAddress + callId);
msg.setType("text/plain");
startActivityForResult(Intent.createChooser(msg, "Call someone :"), VIDEO_CALL_SENT);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == VIDEO_CALL_SENT) {
startCam();
}
}

public void startCam() {
setContentView(vsv);
// Camera settings
client.setCamera("front", "640", "480");
client.start("android_test", true);
}

@Override
public void onStatusChanged(final String newStatus) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), newStatus, Toast.LENGTH_SHORT).show();
}
});
}

@Override
public void onLocalStream(MediaStream localStream) {
localStream.videoTracks.get(0).addRenderer(new VideoRenderer(new VideoCallbacks(vsv, 0)));
}

@Override
public void onAddRemoteStream(MediaStream remoteStream, int endPoint) {
remoteStream.videoTracks.get(0).addRenderer(new VideoRenderer(new VideoCallbacks(vsv, endPoint)));
vsv.shouldDraw[endPoint] = true;
}

@Override
public void onRemoveRemoteStream(MediaStream remoteStream, int endPoint) {
remoteStream.videoTracks.get(0).dispose();
vsv.shouldDraw[endPoint] = false;
}

// Implementation detail: bridge the VideoRenderer.Callbacks interface to the
// VideoStreamsView implementation.
private class VideoCallbacks implements VideoRenderer.Callbacks {
private final VideoStreamsView view;
private final int stream;

public VideoCallbacks(VideoStreamsView view, int stream) {
this.view = view;
this.stream = stream;
}

@Override
public void setSize(final int width, final int height) {
view.queueEvent(new Runnable() {
public void run() {
view.setSize(stream, width, height);
}
});
}

@Override
public void renderFrame(VideoRenderer.I420Frame frame) {
view.queueFrame(stream, frame);
}
}
}

I want to use webrtc in my android app.
https://github.com/pchab/AndroidRTC
after import project from this site video calling or voice calling or chatting is not working.
how can i use websocket library send data and receive for video or voice chatting?
can we interface WEBRTC API with webview.
or how can we do voice chatting and display view in chrom in any control of android.
now i am using webrtc in a native app but it is not working.
if u have any other code or project for webrtc in android than send me link.

我想在我的 Android 应用程序中使用 webrtc。 https://github.com/pchab/AndroidRTC 从该网站导入项目后,视频通话、语音通话或聊天无法正常工作。 我如何使用 websocket 库发送数据并接收视频或语音聊天? 我们可以将 WEBRTC API 与 webview 接口(interface)吗?

最佳答案

要使该应用程序正常工作,您需要一个服务器端来完成信号发送工作。如果您不想自己开发,可以从同一项目安装node.js 服务器及其桌面客户端(只需按照 AndroidRTC 的操作说明和 ProjectRTC 的安装说明进行操作):

https://github.com/pchab/ProjectRTC

希望有帮助。

关于java - 在Android应用程序中实现webrtc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24406433/

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