Skip to content

Commit 90982ee

Browse files
authored
Add setRemoteAudioPlayback functionality for android (#708)
* Feature: Add setRemoteAudioPlayback to android * remove unnecessary return
1 parent 4f50a30 commit 90982ee

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

android/src/main/java/com/twiliorn/library/CustomTwilioVideoView.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,20 @@ public void toggleRemoteAudio(boolean enabled) {
767767
}
768768
}
769769

770+
public void setRemoteAudioPlayback(String participant, boolean enabled) {
771+
if (room != null) {
772+
for (RemoteParticipant rp : room.getRemoteParticipants()) {
773+
if (rp.getSid().equals(participant)) {
774+
for (AudioTrackPublication at : rp.getAudioTracks()) {
775+
if (at.getAudioTrack() != null) {
776+
((RemoteAudioTrack) at.getAudioTrack()).enablePlayback(enabled);
777+
}
778+
}
779+
}
780+
}
781+
}
782+
}
783+
770784
public void publishLocalVideo(boolean enabled) {
771785
if (localParticipant != null && localVideoTrack != null) {
772786
if (enabled) {

android/src/main/java/com/twiliorn/library/CustomTwilioVideoViewManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public class CustomTwilioVideoViewManager extends SimpleViewManager<CustomTwilio
6060
private static final int SEND_STRING = 12;
6161
private static final int PUBLISH_VIDEO = 13;
6262
private static final int PUBLISH_AUDIO = 14;
63+
private static final int SET_REMOTE_AUDIO_PLAYBACK = 15;
6364

6465
@Override
6566
public String getName() {
@@ -143,6 +144,11 @@ public void receiveCommand(CustomTwilioVideoView view, int commandId, @Nullable
143144
case PUBLISH_AUDIO:
144145
view.publishLocalAudio(args.getBoolean(0));
145146
break;
147+
case SET_REMOTE_AUDIO_PLAYBACK:
148+
String participantSid = args.getString(0);
149+
Boolean enabled = args.getBoolean(1);
150+
view.setRemoteAudioPlayback(participantSid, enabled);
151+
break;
146152
}
147153
}
148154

src/TwilioVideo.android.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ const nativeEvents = {
166166
sendString: 12,
167167
publishVideo: 13,
168168
publishAudio: 14,
169+
setRemoteAudioPlayback: 15,
169170
};
170171

171172
class CustomTwilioVideoView extends Component {
@@ -247,6 +248,13 @@ class CustomTwilioVideoView extends Component {
247248
return Promise.resolve(enabled);
248249
}
249250

251+
setRemoteAudioPlayback({ participantSid, enabled }) {
252+
this.runCommand(nativeEvents.setRemoteAudioPlayback, [
253+
participantSid,
254+
enabled,
255+
]);
256+
}
257+
250258
getStats() {
251259
this.runCommand(nativeEvents.getStats, []);
252260
}

0 commit comments

Comments
 (0)