projects
/
rtmpclient.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix issue 1) not recognizes some usb device, 2) reconnect when ffmpeg encoder error
[rtmpclient.git]
/
app
/
src
/
main
/
java
/
ai
/
suanzi
/
rtmpclient
/
MainActivity.java
diff --git
a/app/src/main/java/ai/suanzi/rtmpclient/MainActivity.java
b/app/src/main/java/ai/suanzi/rtmpclient/MainActivity.java
index
1ad33b4
..
bf53ce4
100644
(file)
--- a/
app/src/main/java/ai/suanzi/rtmpclient/MainActivity.java
+++ b/
app/src/main/java/ai/suanzi/rtmpclient/MainActivity.java
@@
-43,9
+43,9
@@
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Cal
private NetworkMonitor networkMonitor;
private UsbMonitor mUsbMonitor;
private ServiceHealthMonitor mServiceHealthMonitor;
private NetworkMonitor networkMonitor;
private UsbMonitor mUsbMonitor;
private ServiceHealthMonitor mServiceHealthMonitor;
- private static final int INTERVAL =
2
* 60; // seconds
+ private static final int INTERVAL =
3
* 60; // seconds
- boolean mBounded;
+ boolean mBounded
= false
;
MyService mServer;
Intent mIntent;
MyService mServer;
Intent mIntent;
@@
-98,7
+98,6
@@
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Cal
if(mUsbMonitor.hasUsbCamera()){
doBindService();
}
if(mUsbMonitor.hasUsbCamera()){
doBindService();
}
-
}
}, this);
}
}, this);
@@
-135,7
+134,7
@@
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Cal
gLogger.error("onNotHealthy, in " + INTERVAL + " seconds, the publishing may stopped or have error ");
doUnbindService();
doBindService();
gLogger.error("onNotHealthy, in " + INTERVAL + " seconds, the publishing may stopped or have error ");
doUnbindService();
doBindService();
-
+ //restartApplication();
}
});
mServiceHealthMonitor.setInterval(INTERVAL); // 5 minutes
}
});
mServiceHealthMonitor.setInterval(INTERVAL); // 5 minutes
@@
-162,7
+161,7
@@
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Cal
if(mServer.setRtmpUrl(UserInfo.getConfig().toUrl(mMacAddr))){
mServer.startPreview(mHolder);
}
if(mServer.setRtmpUrl(UserInfo.getConfig().toUrl(mMacAddr))){
mServer.startPreview(mHolder);
}
- gLogger.debug("onServiceConnected - start health monitor thread, interval " + INTERVAL);
+
}
};
}
};
@@
-170,6
+169,7
@@
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Cal
private void doBindService(){
gLogger.debug("doBindService");
if(!mBounded && canStartService()) {
private void doBindService(){
gLogger.debug("doBindService");
if(!mBounded && canStartService()) {
+ gLogger.debug("Start service --------->");
bindService(mIntent, mConnection, BIND_AUTO_CREATE);
}
}
bindService(mIntent, mConnection, BIND_AUTO_CREATE);
}
}
@@
-177,6
+177,7
@@
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Cal
private void doUnbindService() {
gLogger.debug("doUnbindService");
if(mBounded){
private void doUnbindService() {
gLogger.debug("doUnbindService");
if(mBounded){
+ gLogger.debug("Stop service <---------");
unbindService(mConnection);
mBounded = false;
}
unbindService(mConnection);
mBounded = false;
}
@@
-193,10
+194,8
@@
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Cal
if(NetworkMonitor.isNetworkAvailable(this) && mUsbMonitor.hasUsbCamera()){
gLogger.error("Current network is available");
doBindService();
if(NetworkMonitor.isNetworkAvailable(this) && mUsbMonitor.hasUsbCamera()){
gLogger.error("Current network is available");
doBindService();
-
-
} else {
} else {
- gLogger.error("Current network
is NOT available
");
+ gLogger.error("Current network
NOT available or no USB Camera connected
");
}
mBtnStart.setText("start");
}
mBtnStart.setText("start");
@@
-205,16
+204,13
@@
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Cal
public void onClick(View view){
gLogger.error("----------> onClick");
saveConfig();
public void onClick(View view){
gLogger.error("----------> onClick");
saveConfig();
-
- //unbindService(mConnection);
- bindService(mIntent, mConnection, BIND_AUTO_CREATE);
- //doUnbindService();
- //doBindService();
+ doUnbindService();
+ doBindService();
}
});
if(!mServiceHealthMonitor.isAlive()) {
}
});
if(!mServiceHealthMonitor.isAlive()) {
- gLogger.debug("mServiceHealthMonitor start
"
);
+ gLogger.debug("mServiceHealthMonitor start
, interval " + INTERVAL
);
mServiceHealthMonitor.start();
}
}
mServiceHealthMonitor.start();
}
}
@@
-246,7
+242,9
@@
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Cal
@Override
protected void onDestroy(){
super.onDestroy();
@Override
protected void onDestroy(){
super.onDestroy();
+ mUsbMonitor.unregisterReceiver();
unregisterReceiver(networkMonitor);
unregisterReceiver(networkMonitor);
+ unbindService(mConnection);
gLogger.debug("onDestroy --------->");
}
gLogger.debug("onDestroy --------->");
}
@@
-320,18
+318,25
@@
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Cal
public void onCameraError(String msg){
gLogger.error("onCameraEvent " + msg);
if(mUsbMonitor.hasUsbCamera()){
public void onCameraError(String msg){
gLogger.error("onCameraEvent " + msg);
if(mUsbMonitor.hasUsbCamera()){
- mServer.reopenCamera();
+
//
mServer.reopenCamera();
}
}
@Override
public void onEncoderError(String msg){
}
}
@Override
public void onEncoderError(String msg){
- gLogger.error("onEncoderEvent: " + msg);
+ gLogger.error("onEncoderError: " + msg);
+ doUnbindService();
+ doBindService();
}
@Override
public void onPublishing(String msg){
}
@Override
public void onPublishing(String msg){
- gLogger.error("onPublishing: " + msg);
mServiceHealthMonitor.record();
}
mServiceHealthMonitor.record();
}
+
+ private void restartApplication() {
+ final Intent intent = getPackageManager().getLaunchIntentForPackage(getPackageName());
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ startActivity(intent);
+ }
}
}