基于android的ipcamera编程,IP Camera实时视频监控(android 源码)

本文档介绍了一个基于Android的IP Camera编程示例,演示了如何使用网络摄像机的基本功能。核心代码涉及到SurfaceView、SurfaceHolder、手势识别等,用于接收和显示视频流,并提供了设置参数、控制摄像头的接口。通过NativeCaller调用SO库实现与硬件的交互,实现了视频的播放和控制功能。
摘要由CSDN通过智能技术生成

【实例简介】

Demo程序提供的是网络摄像机的基础功能演示,所需要的so文件请到IPCamerDemo\libs\armeabi 目录下提取;

此外调用so文件时包名一定为:object.p2pipcam.nativecaller 否则调用无效。

【实例截图】

6aaf182079d921e590b3e052735719ce.png

【核心代码】

package com.ipcamer.demo;

import java.nio.ByteBuffer;

import java.text.SimpleDateFormat;

import java.util.Date;

import vstc2.nativecaller.NativeCaller;

import android.app.Activity;

import android.app.AlertDialog;

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.DialogInterface;

import android.content.Intent;

import android.content.IntentFilter;

import android.content.SharedPreferences;

import android.content.SharedPreferences.Editor;

import android.content.res.Configuration;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.graphics.Matrix;

import android.graphics.PixelFormat;

import android.graphics.PointF;

import android.graphics.Shader.TileMode;

import android.graphics.drawable.BitmapDrawable;

import android.graphics.drawable.ColorDrawable;

import android.graphics.drawable.Drawable;

import android.opengl.GLSurfaceView;

import android.os.Bundle;

import android.os.Environment;

import android.os.Handler;

import android.os.Message;

import android.util.DisplayMetrics;

import android.util.FloatMath;

import android.util.Log;

import android.view.GestureDetector;

import android.view.GestureDetector.OnGestureListener;

import android.view.Gravity;

import android.view.KeyEvent;

import android.view.LayoutInflater;

import android.view.MotionEvent;

import android.view.SurfaceHolder;

import android.view.SurfaceView;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.View.OnTouchListener;

import android.view.Window;

import android.view.WindowManager;

import android.view.animation.Animation;

import android.view.animation.AnimationUtils;

import android.widget.Button;

import android.widget.FrameLayout;

import android.widget.ImageButton;

import android.widget.ImageView;

import android.widget.LinearLayout;

import android.widget.PopupWindow;

import android.widget.RelativeLayout;

import android.widget.SeekBar;

import android.widget.SeekBar.OnSeekBarChangeListener;

import android.widget.TextView;

import android.widget.Toast;

import com.ipcamer.demo.BridgeService.PlayInterface;

public class PlayActivity extends Activity implements OnTouchListener,

OnGestureListener, OnClickListener, PlayInterface {

private static final String LOG_TAG = "PlayActivity";

private static final int FULLSCREEN = 0;

private static final int STANDARD = 1;

private static final int MAGNIFY = 2;

private int playmode = 1;

private static final int AUDIO_BUFFER_START_CODE = 0xff00ff;

private SurfaceView playSurface = null;

private SurfaceHolder playHolder = null;

private byte[] videodata = null;

private int videoDataLen = 0;

private int nVideoWidth = 0;

private int nVideoHeight = 0;

public int nVideoWidths = 0;

//public byte[] videodatas = null;

public int nVideoHeights = 0;

private View progressView = null;

private boolean bProgress = true;

private GestureDetector gt = new GestureDetector(this);

@SuppressWarnings("unused")

private int nSurfaceHeight = 0;

private int nResolution = 0;

private int nBrightness = 0;

private int nContrast = 0;

@SuppressWarnings("unused")

private int nMode = 0;

@SuppressWarnings("unused")

private int nFlip = 0;

@SuppressWarnings("unused")

private int nFramerate = 0;

private boolean bInitCameraParam = false;

private boolean bManualExit = false;

private TextView textosd = null;

private String strName = null;;

private String strDID = null;;

private int streamType = ContentCommon.MJPEG_SUB_STREAM;

private PopupWindow popupWindow_about = null;

private View osdView = null;

private boolean bDisplayFinished = true;

private surfaceCallback videoCallback = new surfaceCallback();

private int nPlayCount = 0;

private CustomBuffer AudioBuffer = null;

private AudioPlayer audioPlayer = null;

private boolean bAudioStart = false;

private int nStreamCodecType;

private int nP2PMode = ContentCommon.PPPP_MODE_P2P_NORMAL;

private TextView textTimeoutTextView = null;

private boolean bTimeoutStarted = false;

private int nTimeoutRemain = 180;

private boolean isTakeVideo = false;

private boolean isLeftRight = false;

private boolean isUpDown = false;

private PopupWindow mPopupWindowProgress;

private final int BRIGHT = 1;

private final int CONTRAST = 2;

private boolean isHorizontalMirror = false;

private boolean isVerticalMirror = false;

private boolean isUpDownPressed = false;

private boolean isShowtoping = false;

private ImageView vidoeView;

private ImageView videoViewStandard;

private ImageButton ptzAudio;

private ImageButton ptzPlayMode;

private Button ptzResolutoin;

private Animation showAnim;

private boolean isTakepic = false;

private boolean isMcriophone = false;

private boolean isExit = false;

private PopupWindow resolutionPopWindow;

private Animation dismissAnim;

private View ptzOtherSetAnimView;

private int timeTag = 0;

private int timeOne = 0;

private int timeTwo = 0;

private ImageButton button_back;

private BitmapDrawable drawable = null;

// private LinkedList bs = null;

private MyBrodCast brodCast = null;

class MyBrodCast extends BroadcastReceiver {

@Override

public void onReceive(Context arg0, Intent arg1) {

if (arg1.getIntExtra("ifdrop", 2) != 2) {

PPPPMsgHandler.sendEmptyMessage(1004);

}

}

}

/**

* 在UI线程中刷新界面状态

* **/

private Handler PPPPMsgHandler = new Handler() {

public void handleMessage(Message msg) {

switch (msg.what) {

case 1004:

Toast.makeText(PlayActivity.this, "相机断线", 0).show();

PlayActivity.this.finish();

break;

default:

break;

}

}

};

private class surfaceCallback implements SurfaceHolder.Callback {

public void surfaceChanged(SurfaceHolder holder, int format, int width,

int height) {

if (holder == playHolder) {

streamType = 10;

NativeCaller.StartPPPPLivestream(strDID, streamType);

}

}

public void surfaceCreated(SurfaceHolder holder) {

}

public void surfaceDestroyed(SurfaceHolder holder) {

// finish();

}

}

@Override

public boolean onKeyDown(int keyCode, KeyEvent event) {

if (mPopupWindowProgress != null && mPopupWindowProgress.isShowing()) {

mPopupWindowProgress.dismiss();

}

if (resolutionPopWindow != null && resolutionPopWindow.isShowing()) {

resolutionPopWindow.dismiss();

}

if (keyCode == KeyEvent.KEYCODE_BACK) {

if (!bProgress) {

Date date = new Date();

if (timeTag == 0) {

timeOne = date.getSeconds();

timeTag = 1;

Toast.makeText(PlayActivity.this, R.string.main_show_back,

0).show();

} else if (timeTag == 1) {

timeTwo = date.getSeconds();

if (timeTwo - timeOne <= 3) {

Intent intent = new Intent("finish");

sendBroadcast(intent);

PlayActivity.this.finish();

timeTag = 0;

} else {

timeTag = 1;

Toast.makeText(PlayActivity.this,

R.string.main_show_back, 0).show();

}

}

} else {

showSureDialog1();

}

return true;

}

if (keyCode == KeyEvent.KEYCODE_MENU) {

if (!bProgress) {

showTop();

showBottom();

} else {

showSureDialog1();

}

}

return super.onKeyDown(keyCode, event);

}

/****

* 退出确定dialog

* */

public void showSureDialog1() {

AlertDialog.Builder builder = new AlertDialog.Builder(this);

builder.setIcon(R.drawable.app);

builder.setTitle(getResources().getString(R.string.exit)

getResources().getString(R.string.app_name));

builder.setMessage(R.string.exit_alert);

builder.setPositiveButton(R.string.str_ok,

new DialogInterface.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值