【实例简介】
Demo程序提供的是网络摄像机的基础功能演示,所需要的so文件请到IPCamerDemo\libs\armeabi 目录下提取;
此外调用so文件时包名一定为:object.p2pipcam.nativecaller 否则调用无效。
【实例截图】
【核心代码】
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.