Skip to content

Commit f91e3ef

Browse files
committed
added onPause and onResume behavior
1 parent db90e76 commit f91e3ef

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

src/fr/pchab/AndroidRTC/RTCActivity.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class RTCActivity extends Activity implements WebRtcClient.RTCListener {
3838
private static final int REMOTE_WIDTH = 100;
3939
private static final int REMOTE_HEIGHT = 100;
4040
private VideoRendererGui.ScalingType scalingType = VideoRendererGui.ScalingType.SCALE_ASPECT_FILL;
41+
private GLSurfaceView vsv;
4142
private VideoRenderer.Callbacks localRender;
4243
private VideoRenderer.Callbacks remoteRender;
4344
private WebRtcClient client;
@@ -52,7 +53,9 @@ public void onCreate(Bundle savedInstanceState) {
5253
mSocketAddress = "http://" + getResources().getString(R.string.host);
5354
mSocketAddress += (":" + getResources().getString(R.string.port) + "/");
5455

55-
GLSurfaceView vsv = (GLSurfaceView) findViewById(R.id.glview_call);
56+
vsv = (GLSurfaceView) findViewById(R.id.glview_call);
57+
vsv.setPreserveEGLContextOnPause(true);
58+
vsv.setKeepScreenOn(true);
5659
VideoRendererGui.setView(vsv, new Runnable() {
5760
@Override
5861
public void run() {
@@ -95,16 +98,23 @@ public void onConfigurationChanged(Configuration newConfig) {
9598
@Override
9699
public void onPause() {
97100
super.onPause();
101+
vsv.onPause();
102+
if(client != null) {
103+
client.stopVideoSource();
104+
}
98105
}
99106

100107
@Override
101108
public void onResume() {
102109
super.onResume();
110+
vsv.onResume();
111+
if(client != null) {
112+
client.restartVideoSource();
113+
}
103114
}
104115

105116
@Override
106117
public void onCallReady(String callId) {
107-
Log.d("POUET", callId);
108118
if (callerId != null) {
109119
try {
110120
answer(callerId);

src/fr/pchab/AndroidRTC/WebRtcClient.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class WebRtcClient {
2121
private LinkedList<PeerConnection.IceServer> iceServers = new LinkedList<>();
2222
private MediaConstraints pcConstraints = new MediaConstraints();
2323
private MediaStream localMS;
24+
private VideoSource videoSource;
2425
private RTCListener mListener;
2526
private Socket client;
2627
private final static String TAG = WebRtcClient.class.getCanonicalName();
@@ -111,7 +112,6 @@ private MessageHandler() {
111112
public Emitter.Listener onMessage = new Emitter.Listener() {
112113
@Override
113114
public void call(Object... args) {
114-
Log.d("POUET", "receive message "+args[0].toString());
115115
JSONObject data = (JSONObject) args[0];
116116
try {
117117
String from = data.getString("from");
@@ -262,7 +262,7 @@ public void setCamera(String height, String width){
262262
videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("maxHeight", height));
263263
videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("maxWidth", width));
264264

265-
VideoSource videoSource = factory.createVideoSource(getVideoCapturer(), videoConstraints);
265+
videoSource = factory.createVideoSource(getVideoCapturer(), videoConstraints);
266266
AudioSource audioSource = factory.createAudioSource(new MediaConstraints());
267267
localMS = factory.createLocalMediaStream("ARDAMS");
268268
localMS.addTrack(factory.createVideoTrack("ARDAMSv0", videoSource));
@@ -271,6 +271,18 @@ public void setCamera(String height, String width){
271271
mListener.onLocalStream(localMS);
272272
}
273273

274+
public void stopVideoSource() {
275+
if(videoSource != null) {
276+
videoSource.stop();
277+
}
278+
}
279+
280+
public void restartVideoSource() {
281+
if(videoSource != null) {
282+
videoSource.restart();
283+
}
284+
}
285+
274286
private int findEndPoint() {
275287
for(int i = 0; i < MAX_PEER; i++) {
276288
if(!endPoints[i]) return i;

0 commit comments

Comments
 (0)