Skip to content

Commit 0aa12aa

Browse files
committed
fix:录音播放
1 parent b8cdd6a commit 0aa12aa

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

android/src/main/java/com/netease/im/ReactCache.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -179,25 +179,29 @@ public static Object createRecentList(List<RecentContact> recents, int unreadNum
179179
}
180180
map.putString("time", TimeUtil.getTimeShowString(contact.getTime(), true));
181181

182-
String fromNick = "";
183-
try {
184-
fromNick = contact.getFromNick();
185-
} catch (Exception e) {
186-
e.printStackTrace();
187-
}
188182

189-
fromNick = TextUtils.isEmpty(fromNick) ? NimUserInfoCache.getInstance().getUserDisplayName(fromAccount) : fromNick;
190-
map.putString("nick", fromNick);
183+
String fromNick = "";
191184
String teamNick = "";
192-
if (contact.getSessionType() == SessionTypeEnum.Team && !TextUtils.equals(LoginService.getInstance().getAccount(), fromAccount)) {
193-
String tid = contact.getContactId();
194-
teamNick = getTeamUserDisplayName(tid, fromAccount)+": ";
195-
if ((contact.getAttachment() instanceof NotificationAttachment)) {
196-
if (AitHelper.hasAitExtention(contact)) {
197-
if (contact.getUnreadCount() == 0) {
198-
AitHelper.clearRecentContactAited(contact);
199-
} else {
200-
content = AitHelper.getAitAlertString(content);
185+
if (!TextUtils.isEmpty(fromAccount)) {
186+
try {
187+
fromNick = contact.getFromNick();
188+
} catch (Exception e) {
189+
e.printStackTrace();
190+
}
191+
192+
fromNick = TextUtils.isEmpty(fromNick) ? NimUserInfoCache.getInstance().getUserDisplayName(fromAccount) : fromNick;
193+
map.putString("nick", fromNick);
194+
195+
if (contact.getSessionType() == SessionTypeEnum.Team && !TextUtils.equals(LoginService.getInstance().getAccount(), fromAccount)) {
196+
String tid = contact.getContactId();
197+
teamNick = TextUtils.isEmpty(fromAccount) ? "" : getTeamUserDisplayName(tid, fromAccount) + ": ";
198+
if ((contact.getAttachment() instanceof NotificationAttachment)) {
199+
if (AitHelper.hasAitExtention(contact)) {
200+
if (contact.getUnreadCount() == 0) {
201+
AitHelper.clearRecentContactAited(contact);
202+
} else {
203+
content = AitHelper.getAitAlertString(content);
204+
}
201205
}
202206
}
203207
}

android/src/main/java/com/netease/im/session/AudioPlayService.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ public class AudioPlayService implements SensorEventListener {
2727
AudioPlayerM currentAudioPlayer;
2828
private String currentFile;
2929
private int state;
30-
private int currentAudioStreamType = AudioManager.STREAM_VOICE_CALL;
30+
private int currentAudioStreamType = AudioManager.STREAM_MUSIC;
3131

3232
protected boolean needSeek = false;
3333
protected long seekPosition;
34+
private ReactContext mContext;
3435

3536
private AudioPlayService() {
3637
}
@@ -72,6 +73,7 @@ public void playAudio(Handler handler, ReactContext context, int audioStreamType
7273
}
7374
// ReactCache.emit(ReactCache.observeAudioRecord, ReactCache.createAudioPlay("Volume", context.getCurrentActivity().getVolumeControlStream()));
7475

76+
mContext = context;
7577
if (context.getCurrentActivity() != null) {
7678
context.getCurrentActivity().setVolumeControlStream(currentAudioStreamType); // 默认使用听筒播放
7779
}
@@ -88,7 +90,7 @@ public void playAudio(Handler handler, ReactContext context, int audioStreamType
8890

8991
currentAudioPlayer.setOnPlayListener(new BasePlayerListener(currentAudioPlayer));
9092

91-
handler.postDelayed(playRunnable, 50);
93+
handler.postDelayed(playRunnable, 500);
9294
state = AudioControllerState.ready;
9395
}
9496

@@ -149,7 +151,9 @@ public boolean updateAudioStreamType(int audioStreamType) {
149151
if (audioStreamType == currentAudioStreamType) {
150152
return false;
151153
}
152-
154+
if (mContext.getCurrentActivity() != null) {
155+
mContext.getCurrentActivity().setVolumeControlStream(currentAudioStreamType); // 默认使用听筒播放
156+
}
153157
changeAudioStreamType(audioStreamType);
154158
return true;
155159
}

0 commit comments

Comments
 (0)