基于android的ipcamera编程,spydroid-ipcamera-master完整实现源码
【实例简介】
android实现spydroid-ipcamera-master,h264进行硬编译,rstp进行传输,在电脑端成功播放
【实例截图】
public class SpydroidActivity extends FragmentActivity {
static final public String TAG = "SpydroidActivity";
public final int HANDSET = 0x01;
public final int TABLET = 0x02;
// We assume that the device is a phone
public int device = HANDSET;
private ViewPager mViewPager;
private PowerManager.WakeLock mWakeLock;
private SectionsPagerAdapter mAdapter;
private SurfaceView mSurfaceView;
private SpydroidApplication mApplication;
private CustomHttpServer mHttpServer;
private RtspServer mRtspServer;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mApplication = (SpydroidApplication) getApplication();
setContentView(R.layout.spydroid);
if (findViewById(R.id.handset_pager) != null) {
// Handset detected !
mAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.handset_pager);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
mSurfaceView = (SurfaceView)findViewById(R.id.handset_camera_view);
SessionBuilder.getInstance().setSurfaceView(mSurfaceView);
SessionBuilder.getInstance().setPreviewOrientation(90);
} else {
// Tablet detected !
device = TABLET;
mAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.tablet_pager);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
SessionBuilder.getInstance().setPreviewOrientation(0);
}
mViewPager.setAdapter(mAdapter);
// Remove the ads if this is the donate version of the app.
if (mApplication.DONATE_VERSION) {
((LinearLayout)findViewById(R.id.adcontainer)).removeAllViews();
}
// Prevents the phone from going to sleep mode
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "net.majorkernelpanic.spydroid.wakelock");
// Starts the service of the HTTP server
this.startService(new Intent(this,CustomHttpServer.class));
// Starts the service of the RTSP server
this.startService(new Intent(this,CustomRtspServer.class));
}
public void onStart() {
super.onStart();
// Lock screen
mWakeLock.acquire();
// Did the user disabled the notification ?
if (mApplication.notificationEnabled) {
Intent notificationIntent = new Intent(this, SpydroidActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
Notification notification = builder.setContentIntent(pendingIntent)
.setWhen(System.currentTimeMillis())
.setTicker(getText(R.string.notification_title))
.setSmallIcon(R.drawable.icon)
.setContentTitle(getText(R.string.notification_title))
.setContentText(getText(R.string.notification_content)).build();
notification.flags |= Notification.FLAG_ONGOING_EVENT;
((NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE)).notify(0,notification);
} else {
removeNotification();
}
bindService(new Intent(this,CustomHttpServer.class), mHttpServiceConnection, Context.BIND_AUTO_CREATE);
bindService(new Intent(this,CustomRtspServer.class), mRtspServiceConnection, Context.BIND_AUTO_CREATE);
}
@Override
public void onStop() {
super.onStop();
// A WakeLock should only be released when isHeld() is true !
if (mWakeLock.isHeld()) mWakeLock.release();
if (mHttpServer != null) mHttpServer.removeCallbackListener(mHttpCallbackListener);
unbindService(mHttpServiceConnection);
if (mRtspServer != null) mRtspServer.removeCallbackListener(mRtspCallbackListener);
unbindService(mRtspServiceConnection);
}
@Override
public void onResume() {
super.onResume();
mApplication.applicationForeground = true;
}
@Override
public void onPause() {
super.onPause();
mApplication.applicationForeground = false;
}
@Override
public void onDestroy() {
Log.d(TAG,"SpydroidActivity destroyed");
super.onDestroy();
}
@Override
public void onBackPressed() {
Intent setIntent = new Intent(Intent.ACTION_MAIN);
setIntent.addCategory(Intent.CATEGORY_HOME);
setIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(setIntent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
MenuItemCompat.setShowAsAction(menu.findItem(R.id.quit), 1);
MenuItemCompat.setShowAsAction(menu.findItem(R.id.options), 1);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent intent;
switch (item.getItemId()) {
case R.id.options:
// Starts QualityListActivity where user can change the streaming quality
intent = new Intent(this.getBaseContext(),OptionsActivity.class);
startActivityForResult(intent, 0);
return true;
case R.id.quit:
quitSpydroid();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void quitSpydroid() {
// Removes notification
if (mApplication.notificationEnabled) removeNotification();
// Kills HTTP server
this.stopService(new Intent(this,CustomHttpServer.class));
// Kills RTSP server
this.stopService(new Intent(this,CustomRtspServer.class));
// Returns to home menu
finish();
}
private ServiceConnection mRtspServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mRtspServer = (CustomRtspServer) ((RtspServer.LocalBinder)service).getService();
mRtspServer.addCallbackListener(mRtspCallbackListener);
mRtspServer.start();
}
@Override
public void onServiceDisconnected(ComponentName name) {}
};
private RtspServer.CallbackListener mRtspCallbackListener = new RtspServer.CallbackListener() {
@Override
public void onError(RtspServer server, Exception e, int error) {
// We alert the user that the port is already used by another app.
if (error == RtspServer.ERROR_BIND_FAILED) {
new AlertDialog.Builder(SpydroidActivity.this)
.setTitle(R.string.port_used)
.setMessage(getString(R.string.bind_failed, "RTSP"))
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int id) {
startActivityForResult(new Intent(SpydroidActivity.this, OptionsActivity.class),0);
}
})
.show();
}
}
@Override
public void onMessage(RtspServer server, int message) {
if (message==RtspServer.MESSAGE_STREAMING_STARTED) {
if (mAdapter != null && mAdapter.getHandsetFragment() != null)
mAdapter.getHandsetFragment().update();
} else if (message==RtspServer.MESSAGE_STREAMING_STOPPED) {
if (mAdapter != null && mAdapter.getHandsetFragment() != null)
mAdapter.getHandsetFragment().update();
}
}
};
private ServiceConnection mHttpServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mHttpServer = (CustomHttpServer) ((TinyHttpServer.LocalBinder)service).getService();
mHttpServer.addCallbackListener(mHttpCallbackListener);
mHttpServer.start();
}
@Override
public void onServiceDisconnected(ComponentName name) {}
};
private TinyHttpServer.CallbackListener mHttpCallbackListener = new TinyHttpServer.CallbackListener() {
@Override
public void onError(TinyHttpServer server, Exception e, int error) {
// We alert the user that the port is already used by another app.
if (error == TinyHttpServer.ERROR_HTTP_BIND_FAILED ||
error == TinyHttpServer.ERROR_HTTPS_BIND_FAILED) {
String str = error==TinyHttpServer.ERROR_HTTP_BIND_FAILED?"HTTP":"HTTPS";
new AlertDialog.Builder(SpydroidActivity.this)
.setTitle(R.string.port_used)
.setMessage(getString(R.string.bind_failed, str))
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int id) {
startActivityForResult(new Intent(SpydroidActivity.this, OptionsActivity.class),0);
}
})
.show();
}
}
@Override
public void onMessage(TinyHttpServer server, int message) {
if (message==CustomHttpServer.MESSAGE_STREAMING_STARTED) {
if (mAdapter != null && mAdapter.getHandsetFragment() != null)
mAdapter.getHandsetFragment().update();
if (mAdapter != null && mAdapter.getPreviewFragment() != null)
mAdapter.getPreviewFragment().update();
} else if (message==CustomHttpServer.MESSAGE_STREAMING_STOPPED) {
if (mAdapter != null && mAdapter.getHandsetFragment() != null)
mAdapter.getHandsetFragment().update();
if (mAdapter != null && mAdapter.getPreviewFragment() != null)
mAdapter.getPreviewFragment().update();
}
}
};
private void removeNotification() {
((NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE)).cancel(0);
}
public void log(String s) {
Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show();
}
class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int i) {
if (device == HANDSET) {
switch (i) {
case 0: return new HandsetFragment();
case 1: return new PreviewFragment();
case 2: return new AboutFragment();
}
} else {
switch (i) {
case 0: return new TabletFragment();
case 1: return new AboutFragment();
}
}
return null;
}
@Override
public int getCount() {
return device==HANDSET ? 3 : 2;
}
public HandsetFragment getHandsetFragment() {
if (device == HANDSET) {
return (HandsetFragment) getSupportFragmentManager().findFragmentByTag("android:switcher:" R.id.handset_pager ":0");
} else {
return (HandsetFragment) getSupportFragmentManager().findFragmentById(R.id.handset);
}
}
public PreviewFragment getPreviewFragment() {
if (device == HANDSET) {
return (PreviewFragment) getSupportFragmentManager().findFragmentByTag("android:switcher:" R.id.handset_pager ":1");
} else {
return (PreviewFragment) getSupportFragmentManager().findFragmentById(R.id.preview);
}
}
@Override
public CharSequence getPageTitle(int position) {
if (device == HANDSET) {
switch (position) {
case 0: return getString(R.string.page0);
case 1: return getString(R.string.page1);
case 2: return getString(R.string.page2);
}
} else {
switch (position) {
case 0: return getString(R.string.page0);
case 1: return getString(R.string.page2);
}
}
return null;
}
}
}
【核心代码】
基于android的ipcamera编程,spydroid-ipcamera-master完整实现源码相关推荐
- [附源码]计算机毕业设计Python+uniapp基于Android校园二手交易平台设计与实现 o8k65(程序+源码+LW+远程部署)
[附源码]计算机毕业设计Python+uniapp基于Android校园二手交易平台设计与实现 o8k65(程序+源码+LW+远程部署) 该项目含有源码.文档.程序.数据库.配套开发软件.软件安装教程 ...
- [附源码]计算机毕业设计Python+uniapp基于android的古诗词鉴赏设计与实现lt9y0(程序+源码+LW+远程部署)
[附源码]计算机毕业设计Python+uniapp基于android的古诗词鉴赏设计与实现lt9y0(程序+源码+LW+远程部署) 该项目含有源码.文档.程序.数据库.配套开发软件.软件安装教程 项目 ...
- 基于Android Studio开发的旅游记录与分享APP源码,Android旅游路线记录与分享APP源码
GoTravelling 旅游路线记录与分享Android App--同享旅行 下载地址:基于Android Studio开发的旅游记录与分享APP源码 App介绍 目标用户 在寒暑假内希望结伴同游的 ...
- 基于Android的电影选座订票系统毕业设计源码011439
摘 要 随着现在网络的快速发展,网络的应用在各行各业当中它很快融入到了许多商家的眼球之中,他们利用网络来做这个电影选座的网站,随之就产生了"电影选座订票系统",这样就让用户电影选座 ...
- android 课设答辩ppt,基于Android的俄罗斯方块游戏设计与实现(设计源码+毕业论文+答辩PPT)...
摘 要 随着移动平台的崛起,越来越多的传统PC软件被移植到移动平台,比如ipad,iphone,Android等智能终端设备,在这些平台中,Android占领着最大的市场份额,所以为Android用 ...
- 基于Android平台实现匿名社交论坛【附项目源码】
基于Android平台实现匿名社交论坛演示 在当今的数字时代,社交网络已经成为人们生活中不可或缺的一部分.社交应用的需求不断增加,人们期望能够在这些应用中获得更多的互动和交流.而匿名社交论坛系统则是一 ...
- 基于android开发的简易五子棋游戏(附带学习源码)
这个游戏案例是android五子棋游戏源码,也是自己最近做的android五子棋游戏,现在拿出来给大家看看一下.不过这个没有影响大家的学习和运行,喜欢的朋友可以在这个的基础上进行升级或更新吧. 文件: ...
- ssm基于Android社区生鲜O2O订购系统设计与实现毕业设计源码231443
社区生鲜O2O订购系统app 摘 要 随着我国经济迅速发展,人们对手机的需求越来越大,各种手机软件也都在被广泛应用,但是对于手机进行数据信息管理,对于手机的各种软件也是备受用户的喜爱,社区生鲜O2O订 ...
- 基于Android开发的手持扫码枪APP(附带参考源码)
扫码枪扫码效果等同于键盘录入,会回调dispatchKeyEvent键盘按下事件. 开发环境:有线扫码枪,支持二维码 文件:url80.ctfile.com/f/25127180-740368576- ...
- 基于wxapp的圣诞帽头像小程序【完整项目源码】
抢先体验 微信小程序[Java烂笔头] 更多功能敬请体验~ 介绍 圣诞帽头像微信小程序,已发布上线.可以获取微信头像.相机拍照.上传本地照片到小程序,可选10种圣诞帽搭配到头像上,保存本地即可. 微信 ...
最新文章
- 你有没有试过“闭上眼”使用:京东、滴滴、QQ、支付宝?
- 谷歌升级Android分析应用程序
- 【PC工具】200324更新百度网盘下载工具——最新百度网盘下载工具使用方法及注意事项...
- 排序的概念(选择排序1)
- php中等3秒再跳转,跳转和重定向
- 计算机逻辑运算进位,二进位数进行逻辑运算1010AND1001的运算结果
- 【GNN综述】图神经网络的解释性综述
- k8s架构以及相关概念普及
- 常见消息中间件大 PK
- String常用方法有哪些?在工作中使用过哪些?
- 关于微信小程序,你不知道的那些事
- 什么是直方图,如何使用它来改善照片?
- win10打字反应慢处理
- 第四十九,反射基本介绍
- 【LeetCode-SQL】580. 统计各专业学生人数
- el-tooltip的使用(根据条件控制显示)
- 伺服系统三环的PID控制
- 双目立体匹配步骤详解
- 网络游戏服务器构架设计(四):云风的轨迹
- LINUX系统子系统DEMON,【linux】led子系统