Skip to content

Commit dc02c76

Browse files
author
Jessica Palmer
authored
Merge pull request #96 from red5pro/develop
Develop
2 parents 51b95cc + ab1753c commit dc02c76

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

app/src/main/java/red5pro/org/testandroidproject/tests/SubscribeReconnectTest/SubscribeReconnectTest.java

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.red5pro.streaming.event.R5ConnectionEvent;
2020
import com.red5pro.streaming.event.R5ConnectionListener;
2121
import com.red5pro.streaming.source.R5Camera;
22+
import com.red5pro.streaming.view.R5VideoView;
2223

2324
import java.util.concurrent.ExecutionException;
2425

@@ -32,6 +33,7 @@ public class SubscribeReconnectTest extends SubscribeTest {
3233

3334

3435
public boolean stopped = false;
36+
public int reconnectDelay = 5;
3537

3638
@Override
3739
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@@ -53,10 +55,30 @@ public boolean onTouch(View v, MotionEvent event) {
5355
return view;
5456
}
5557

58+
protected void reconnect () {
59+
Subscribe();
60+
SetupListener();
61+
}
62+
63+
protected void delayReconnect (int delay) {
64+
65+
final SubscribeReconnectTest subscribeTest = this;
66+
Handler h = new Handler(Looper.getMainLooper());
67+
h.postDelayed(new Runnable() {
68+
@Override
69+
public void run() {
70+
subscribeTest.reconnect();
71+
}
72+
}, delay);
73+
74+
}
5675

5776
public void SetupListener(){
5877

78+
final SubscribeReconnectTest subscribeTest = this;
5979
final R5ConnectionListener additionalListener = this;
80+
final R5Stream subscriber = this.subscribe;
81+
final R5VideoView view = this.display;
6082

6183
subscribe.setListener(new R5ConnectionListener() {
6284
@Override
@@ -67,19 +89,36 @@ public void onConnectionEvent(R5ConnectionEvent r5ConnectionEvent) {
6789

6890
if (r5ConnectionEvent == R5ConnectionEvent.CLOSE && !SubscribeReconnectTest.this.stopped) {
6991

70-
7192
Handler h = new Handler(Looper.getMainLooper());
7293
h.postDelayed(new Runnable() {
7394
@Override
7495
public void run() {
7596

7697
if(!stopped) {
77-
Subscribe();
78-
SetupListener();
98+
reconnectDelay = 5;
99+
subscribeTest.reconnect();
79100
}
80101

81102
}
82-
}, 5);
103+
}, reconnectDelay);
104+
105+
}
106+
else if (r5ConnectionEvent == R5ConnectionEvent.NET_STATUS && r5ConnectionEvent.message.equals("NetStream.Play.UnpublishNotify")) {
107+
108+
reconnectDelay = 1000;
109+
Handler h = new Handler(Looper.getMainLooper());
110+
111+
h.postDelayed(new Runnable() {
112+
@Override
113+
public void run() {
114+
115+
subscriber.setListener(null);
116+
subscriber.stop();
117+
view.attachStream(null);
118+
subscribeTest.delayReconnect(reconnectDelay);
119+
120+
}
121+
}, reconnectDelay);
83122

84123
}
85124
}

0 commit comments

Comments
 (0)