+ IntentFilter filter = new IntentFilter();
+ filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
+ registerReceiver(networkMonitor, filter);
+
+ mServiceHealthMonitor = new ServiceHealthMonitor(new ServiceHealthMonitor.Callback() {
+ @Override
+ public void onNotHealthy() {
+ gLogger.error("onNotHealthy, in " + INTERVAL + " seconds, the publishing may stopped or have error ");
+ doUnbindService();
+ doBindService();
+ }
+ });
+ mServiceHealthMonitor.setInterval(INTERVAL);
+ }
+
+
+ ServiceConnection mConnection = new ServiceConnection() {
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ Toast.makeText(MainActivity.this, "Service is disconnected", 1000).show();
+ gLogger.error("onServiceDisconnected ---------->");
+ mBounded = false;
+ mServer = null;
+ }
+
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ Toast.makeText(MainActivity.this, "Service is connected", 1000).show();
+ gLogger.error("onServiceConnected ---------->");
+ mBounded = true;
+ LocalBinder mLocalBinder = (LocalBinder)service;
+ mServer = mLocalBinder.getServiceInstance();
+ mServer.setServiceEventListener(MainActivity.this);
+ if(mServer.setRtmpUrl(UserInfo.getConfig().toUrl(mMacAddr))){
+ mServer.startPreview(mCameraView.getHolder());
+ Camera.Size cs = mServer.getBestPictureSize();
+ mCameraView.setLayout(cs.width, cs.height);
+ }
+
+
+ }
+ };
+
+ private void doBindService(){
+ gLogger.debug("doBindService");
+ if(!mBounded && canStartService()) {
+ gLogger.debug("Start service --------->");
+ bindService(mIntent, mConnection, BIND_AUTO_CREATE);
+ }
+ }