[Android] Issue with Android Media Devices example.

bb0707

New Member
Hi team,

I have some issues with the Android Media Devices example.

Issue #1:
Steps:
1. Publish stream.
2. Play stream.
3. Open another camera app.
4. Open the example app again.

Actual result: The local render view and remote render view are black. It looks like the camera has been stopped.
-> How can I resume the camera in this case?

Issue #2:
I want to implement the pause/resume feature. Is it correct if I use these APIs: Pause: stream.muteAudio(), stream.muteVideo(). Resume: stream.unmuteAudio(), stream.unmuteVideo().

Thanks,
 

Max

Administrator
Staff member
Good day.
Actual result: The local render view and remote render view are black. It looks like the camera has been stopped.
-> How can I resume the camera in this case?
If the application goes to background, it can't use camera. You should launch a service from application activity to continue streaming:
Stream publishing from Android application in background mode
I want to implement the pause/resume feature. Is it correct if I use these APIs: Pause: stream.muteAudio(), stream.muteVideo(). Resume: stream.unmuteAudio(), stream.unmuteVideo().
Those methods just mute/unmute realtime audio and video. If publisher speaks something while audio is muted, a viewer will not hear it even when audio becomes unmuted. So it is not pause/resume feature, however it may be used to temporary mute the stream without stopping it.
 

bb0707

New Member
Hi Max,

If the application goes to background, it can't use camera. You should launch a service from application activity to continue streaming:
Stream publishing from Android application in background mode
Let me clear up my question. When I open the camera from another app, it takes control of the camera from my app. In this case, I see this method is called.
Screenshot 2024-03-01 at 09.10.23.png

Log:
Code:
2024-03-01 08:45:50.144 25958-26027 CameraCapturer          com...oner.wcsexample.media_devices  I  Stop capture
2024-03-01 08:45:52.924 25958-26027 CameraCapturer          com...oner.wcsexample.media_devices  I  Stop capture: No session open
2024-03-01 08:45:52.924 25958-26027 CameraCapturer          com...oner.wcsexample.media_devices  I  Stop capture done
As you can see, the camera is stopped. How can I start it again?
 

bb0707

New Member
Hi Max,

Thank you for the answer. I have another question. When the internet is down, why isn't SessionEvent.onDisconnection() triggered immediately?

Here are my test steps:
1. Connect.
2. Publish.
3. Disconnect from the internet.
4. Wait ~10s.
5. Re-connect to the internet.
6. Wait ~60s.

Actual result:
- At 4, SessionEvent.onDisconnection() is not called.
- At 6, SessionEvent.onDisconnection() is called.

Log:
Code:
20:1: 2024-03-07 11:01:18.048 24499-28793 NetworkMon...AutoDetect com...oner.wcsexample.media_devices  I  Network 126 is disconnected
20:3: 2024-03-07 11:01:18.177 24499-24499 NetworkMon...AutoDetect com...oner.wcsexample.media_devices  I  Network connectivity changed, type is: CONNECTION_NONE
20:70: 2024-03-07 11:01:23.835 24499-28599 MediaConnection         com...oner.wcsexample.media_devices  D  IceConnectionState: DISCONNECTED
20:71: 2024-03-07 11:01:23.835 24499-28599 MediaConnection         com...oner.wcsexample.media_devices  D  ConnectionState: DISCONNECTED
20:75: 2024-03-07 11:01:25.036 24499-28599 MediaConnection         com...oner.wcsexample.media_devices  D  IceConnectionState: DISCONNECTED
20:76: 2024-03-07 11:01:25.036 24499-28599 MediaConnection         com...oner.wcsexample.media_devices  D  ConnectionState: DISCONNECTED
20:150: 2024-03-07 11:01:33.857 24499-28599 MediaConnection         com...oner.wcsexample.media_devices  D  IceConnectionState: FAILED
20:151: 2024-03-07 11:01:33.857 24499-28599 MediaConnection         com...oner.wcsexample.media_devices  E  Peerconnection error: ICE connection failed.
20:157: 2024-03-07 11:01:33.857 24499-28599 MediaConnection         com...oner.wcsexample.media_devices  D  ConnectionState: FAILED
20:168: 2024-03-07 11:01:35.008 24499-28599 MediaConnection         com...oner.wcsexample.media_devices  D  IceConnectionState: FAILED
20:169: 2024-03-07 11:01:35.008 24499-28599 MediaConnection         com...oner.wcsexample.media_devices  E  Peerconnection error: ICE connection failed.
20:170: 2024-03-07 11:01:35.008 24499-28599 MediaConnection         com...oner.wcsexample.media_devices  D  ConnectionState: FAILED
20:174: 2024-03-07 11:01:35.875 24499-28793 NetworkMon...AutoDetect com...oner.wcsexample.media_devices  I  Network becomes available: 127
20:363: 2024-03-07 11:02:31.326 24499-28752 WebSocketChannelClient  com...oner.wcsexample.media_devices  D  WSS->C: {"message":"ping","data":[]}
20:365: 2024-03-07 11:02:31.357 24499-28750 WebSocketChannelClient  com...oner.wcsexample.media_devices  D  WSS<-C: {"message":"pong","data":"null"}
20:366: 2024-03-07 11:02:31.446 24499-28752 WebSocketChannelClient  com...oner.wcsexample.media_devices  D  WSS->C: {"message":"ping","data":[]}
20:367: 2024-03-07 11:02:31.454 24499-28752 WebSocketChannelClient  com...oner.wcsexample.media_devices  D  WSS->C: {"message":"ping","data":[]}
20:369: 2024-03-07 11:02:31.465 24499-28750 WebSocketChannelClient  com...oner.wcsexample.media_devices  D  WSS<-C: {"message":"pong","data":"null"}
20:371: 2024-03-07 11:02:31.484 24499-28750 WebSocketChannelClient  com...oner.wcsexample.media_devices  D  WSS<-C: {"message":"pong","data":"null"}
20:372: 2024-03-07 11:02:31.520 24499-28752 WebSocketChannelClient  com...oner.wcsexample.media_devices  D  WSS->C: {"message":"notifyStreamStatusEvent","data":[{"logger":{"name":"Stream","debugEnabled":false,"infoEnabled":true,"warnEnabled":true,"errorEnabled":true,"traceEnabled":false},"protocols":["ws","wss","vod","vod-live","rtmp","rtsp","pcap"],"mediaSessionId":"e1b9b358-59b1-4706-9d37-2fe3e254cb26","name":"test","published":false,"hasVideo":true,"hasAudio":true,"status":"FAILED","sdp":"v=0\r\no=- 2864139637704770658 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE audio video\r\na=msid-semantic: WMS\r\nm=audio 9 UDP/TLS/RTP/SAVPF 111 103 104 9 102 0 8 106 105 13 110 112 113 126\r\nc=IN IP4 0.0.0.0\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=ice-ufrag:G9Sh\r\na=ice-pwd:E1DYs07SfpDgLqihXkEomXPA\r\na=ice-options:trickle renomination\r\na=fingerprint:sha-256 87:CD:1C:D4:EB:5C:98:8E:71:6B:9A:59:3E:04:84:E2:9E:18:05:3D:D1:99:20:DA:49:26:DE:1A:AF:5E:24:A4\r\na=setup:actpass\r\na=mid:audio\r\na=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level\r\na=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\na=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\r\na=recvonly\r\na=rtcp-mux\r\na=rtpmap:111 opus/48000/2\r\na=rtcp-fb:111 transport-cc\r\na=fmtp:111 minptime=10;useinbandfec=1\r\na=rtpmap:103 ISAC/16000\r\na=rtpmap:104 ISAC/32000\r\na=rtpmap:9 G722/8000\r\na=rtpmap:102 ILBC/8000\r\na=rtpmap:0 PCMU/8000\r\na=rtpmap:8 PCMA/8000\r\na=rtpmap:106 CN/32000\r\na=rtpmap:105 CN/16000\r\na=rtpmap:13 CN/8000\r\na=rtpmap:110 telephone-event/48000\r\na=rtpmap:112 telephone-event/32000\r\na=rtpmap:113 telephone-event/16000\r\na=rtpmap:126 telephone-event/8000\r\nm=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 125 100 101 127\r\nc=IN IP4 0.0.0.0\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=ice-ufrag:G9Sh\r\na=ice-pwd:E1DYs07SfpDgLqihXkEomXPA\r\na=ice-options:trickle renomination\r\na=fingerprint:sha-256 87:CD:1C:D4:EB:5C:98:8E:71:6B:9A:59:3E:04:84:E2:9E:18:05:3D:D1:99:20:DA:49:26:DE:1A:AF:5E:24:A4\r\na=setup:actpass\r\na=mid:video\r\na=extmap:14 urn:ietf:params:rtp-hdre
20:373: 2024-03-07 11:02:31.588 24499-28752 WebSocketChannelClient  com...oner.wcsexample.media_devices  D  WebSocket connection closed. Code: 1006. Reason: . State: CONNECTED
20:378: 2024-03-07 11:02:31.608 24499-28750 WebSocketChannelClient  com...oner.wcsexample.media_devices  D  Disconnect WebSocket. State: CLOSED
20:379: 2024-03-07 11:02:31.608 24499-28750 WebSocketChannelClient  com...oner.wcsexample.media_devices  D  Disconnecting WebSocket done.
20:375: 2024-03-07 11:02:31.605 24499-28750 MediaConnection         com...oner.wcsexample.media_devices  I  D1 - Thread-6
20:376: 2024-03-07 11:02:31.605 24499-28750 MediaConnection         com...oner.wcsexample.media_devices  I  D3 - Thread-6
20:377: 2024-03-07 11:02:31.607 24499-28593 MediaConnection         com...oner.wcsexample.media_devices  I  D2 - Thread-2
20:380: 2024-03-07 11:02:31.609 24499-28750 MediaConnection         com...oner.wcsexample.media_devices  I  D1 - Thread-6
20:381: 2024-03-07 11:02:31.609 24499-28750 MediaConnection         com...oner.wcsexample.media_devices  I  D3 - Thread-6
20:388: 2024-03-07 11:02:31.620 24499-28599 MediaConnection         com...oner.wcsexample.media_devices  D  IceConnectionState: CLOSED
20:389: 2024-03-07 11:02:31.620 24499-28599 MediaConnection         com...oner.wcsexample.media_devices  D  ConnectionState: CLOSED
20:390: 2024-03-07 11:02:31.620 24499-28599 MediaConnection         com...oner.wcsexample.media_devices  D  SignalingState: CLOSED
 

Max

Administrator
Staff member
Thank you for the answer. I have another question. When the internet is down, why isn't SessionEvent.onDisconnection() triggered immediately?
This is the application level task to monitor a network state, not SDK level. Please use ConnectivityManager to register a callback to monitor a network events, and call session.disconnect() in onLost event handler:
Code:
private ConnectivityManager.NetworkCallback networkCallback = new ConnectivityManager.NetworkCallback() {
    @Override
    public void onAvailable(@NonNull Network network) {
        super.onAvailable(network);
    }

    @Override
    public void onLost(@NonNull Network network) {
        session.disconnect();
        super.onLost(network);
    }

    @Override
    public void onCapabilitiesChanged(@NonNull Network network, @NonNull NetworkCapabilities networkCapabilities) {
        super.onCapabilitiesChanged(network, networkCapabilities);
        final boolean unmetered = networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
    }
};
 
Top