Skip to content

Commit

Permalink
High quality audio
Browse files Browse the repository at this point in the history
  • Loading branch information
Khaled Aldaoudieh committed Apr 4, 2021
1 parent 0ced7f7 commit e22e003
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions Houseclub/src/main/java/me/grishka/houseclub/VoiceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import android.os.Looper;
import android.util.Log;

import androidx.annotation.Nullable;

import com.google.gson.JsonObject;
import com.pubnub.api.PNConfiguration;
import com.pubnub.api.PubNub;
Expand All @@ -34,6 +32,7 @@
import java.util.List;
import java.util.stream.Collectors;

import androidx.annotation.Nullable;
import io.agora.rtc.Constants;
import io.agora.rtc.IRtcEngineEventHandler;
import io.agora.rtc.RtcEngine;
Expand Down Expand Up @@ -111,7 +110,7 @@ public void onDestroy(){
@Override
public int onStartCommand(Intent intent, int flags, int startId){
if(engine!=null){
String id=intent.getStringExtra("channel");
String id = intent.getStringExtra("channel");
channel=DataProvider.getChannel(id);
updateChannel(channel);

Expand Down Expand Up @@ -241,10 +240,13 @@ public void leaveChannel(){
uiHandler.removeCallbacks(pinger);
pubnub.unsubscribeAll();
pubnub.destroy();

uiHandler.post(() -> {
for(ChannelEventListener l:listeners)
l.onSelfLeft();
});
for(ChannelEventListener l:listeners)
l.onSelfLeft();
});


}

public void leaveCurrentChannel(){
Expand Down Expand Up @@ -391,15 +393,18 @@ private void onUserLeft(JsonObject msg){
if(!ch.equals(channel.channel))
return;
int id=msg.get("user_id").getAsInt();
uiHandler.post(()->{
for(ChannelUser user:channel.users){
if(user.userId==id){
channel.users.remove(user);
break;
uiHandler.post(new Runnable(){
@Override
public void run(){
for(ChannelUser user:channel.users){
if(user.userId==id){
channel.users.remove(user);
break;
}
}
for(ChannelEventListener l:listeners)
l.onUserLeft(id);
}
for(ChannelEventListener l:listeners)
l.onUserLeft(id);
});
}

Expand All @@ -426,6 +431,7 @@ public interface ChannelEventListener{
void onSpeakingUsersChanged(List<Integer> ids);
void onChannelEnded();
void onSelfLeft();

}

private class RtcEngineEventHandler extends IRtcEngineEventHandler{
Expand All @@ -442,11 +448,14 @@ public void onError(int err){
@Override
public void onAudioVolumeIndication(AudioVolumeInfo[] speakers, int totalVolume){
// Log.d(TAG, "onAudioVolumeIndication() called with: speakers = ["+Arrays.toString(speakers)+"], totalVolume = ["+totalVolume+"]");
uiHandler.post(()->{
int selfID=Integer.parseInt(ClubhouseSession.userID);
List<Integer> uids=Arrays.stream(speakers).map(s->s.uid==0 ? selfID : s.uid).collect(Collectors.toList());
for(ChannelEventListener l:listeners)
l.onSpeakingUsersChanged(uids);
uiHandler.post(new Runnable(){
@Override
public void run(){
int selfID=Integer.parseInt(ClubhouseSession.userID);
List<Integer> uids=Arrays.stream(speakers).map(s -> s.uid==0 ? selfID : s.uid).collect(Collectors.toList());
for(ChannelEventListener l:listeners)
l.onSpeakingUsersChanged(uids);
}
});
}

Expand All @@ -465,7 +474,6 @@ public void run(){
for(ChannelEventListener l:listeners)
l.onUserMuteChanged(uid, muted);
}

});
}
}
Expand Down

0 comments on commit e22e003

Please sign in to comment.