我有一个视频字节数组格式,我如何在android 2.2中的surfaceViewer上绘制?一世
我正在尝试视频聊天.我使用onPreviewFrame,我有一个字节[]我将发送到服务器,而不是服务器发送到其他客户端,而另一个客户端将有一个字节[],我的问题是:我怎么画这个(字节[ ])在客户端?
最佳答案
这里是你的应用程序的所有代码,我的意思是这里是你的视频聊天或部分:),我没有在Android 2.2上尝试我的代码,但它适用于Android 2.3.3,它的工作原理是这样的,你设置一些在editText中设备本地IP地址,然后你必须按下聊天视频按钮,所以其他部分,你设置的IP地址,将看到你的前置摄像头的视频
原文链接:https://www.f2er.com/android/430615.html这是java代码
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.ImageFormat;
import android.graphics.Rect;
import android.graphics.YuvImage;
import android.hardware.Camera;
import android.hardware.Camera.ErrorCallback;
import android.hardware.Camera.Size;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
public class MainActivity extends Activity implements OnClickListener {
private ImageView m_VideCaptureBitmap;
Camera mCamera;
Button m_StartVideoChat;
Button m_close_camera;
EditText IPAdresse;
private SurfaceView m_VideoCaptureView;
private static final int TIMEOUT_MS = 10000;
private static final int server_port = 13011;
byte[] m_buffer ;
@SuppressLint({ "NewApi","NewApi","NewApi" })
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
m_VideoCaptureView = (SurfaceView) findViewById(R.id.imgSentView);
m_close_camera = (Button) findViewById(R.id.btnCameraClose);
m_close_camera.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mCamera.release();
}
});
m_VideCaptureBitmap = (ImageView) findViewById(R.id.videoView);
IPAdresse = (EditText) findViewById(R.id.etIPAdresse);
IPAdresse.setText("192.168.2.32");
m_StartVideoChat = (Button) findViewById(R.id.btnStartVideo);
m_StartVideoChat.setOnClickListener(this);
new Thread(new Runnable() {
@Override
public void run() {
byte[] buffer = new byte [2048];
DatagramSocket s;
try {
s= new DatagramSocket(server_port);
s.setSoTimeout(TIMEOUT_MS);
while(true){
try {
final DatagramPacket p = new DatagramPacket(buffer,buffer.length);
s.receive(p);
m_buffer= buffer.clone();
runOnUiThread(new Runnable() {
@Override
public void run() {
frameToBuffer(p.getData());
}
});
}
catch(Exception e) {
e.printStackTrace();
}
}
} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
//rstep.setText("fail socket create");
}
}
}).start();
}
public void onClick(View arg0) {
switch(arg0.getId()){
case R.id.btnStartVideo:
startVideo();
}
}
private Camera openFrontFacingCameraGingerbread(Camera cam)
{
int cameraCount = 0;
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
cameraCount = Camera.getNumberOfCameras();
for ( int camIdx = 0; camIdx < cameraCount; camIdx++ ) {
Camera.getCameraInfo( camIdx,cameraInfo );
if ( cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT ) {
try {
cam = Camera.open( camIdx );
} catch (RuntimeException e) {
e.printStackTrace();
}
}
}
return cam;
}
private void startVideo() {
if(mCamera != null) return;
SurfaceHolder videoCaptureViewHolder = null;
try {
//openFrontFacingCameraGingerbread(mCamera);
int camId = Camera.CameraInfo.CAMERA_FACING_BACK;
if (Camera.getNumberOfCameras() > 1 && camId < Camera.getNumberOfCameras() - 1) {
int i = 1 + camId ;
mCamera = Camera.open(i);
}
//mCamera = Camera.open();
} catch (RuntimeException e) {
Log.e("CameraTest","Camera Open filed");
return;
}
mCamera.setErrorCallback(new ErrorCallback() {
public void onError(int error,Camera camera) {
}
});
Camera.Parameters parameters = mCamera.getParameters();
parameters.setPictureSize(10,10);
parameters.setPreviewFrameRate(5);
List
这是xml
尝试它;),不要忘记upvote :),也不要忘记在manifest.xml中添加这些行
required="false" />
问候