| | |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.ServiceConnection; |
| | | import android.media.AudioManager; |
| | | import android.media.MediaPlayer; |
| | | import android.os.Build; |
| | | import android.os.IBinder; |
| | |
| | | import org.linphone.core.AuthInfo; |
| | | import org.linphone.core.Call; |
| | | import org.linphone.core.CallParams; |
| | | import org.linphone.core.ChatMessage; |
| | | import org.linphone.core.ChatMessageListener; |
| | | import org.linphone.core.ChatRoom; |
| | | import org.linphone.core.Core; |
| | | import org.linphone.core.CoreException; |
| | | import org.linphone.core.Factory; |
| | |
| | | */ |
| | | public int missedCallsTime = 30; |
| | | |
| | | public AudioManager audioManager; |
| | | |
| | | |
| | | private HDLLinphoneKit() { |
| | | |
| | |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void initAudioManager(Context context){ |
| | | if(audioManager == null){ |
| | | try{ |
| | | audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); |
| | | }catch (Exception exception){ |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | public int getRingerMode() |
| | | { |
| | | return audioManager.getRingerMode(); |
| | | } |
| | | |
| | | public boolean getMediaPlayerPlayingStatus(){ |
| | |
| | | if (!HDLLinphoneService.isReady()) { |
| | | CheckIfNeedstartService(); |
| | | InitMediaPlayer(context); |
| | | initAudioManager(context); |
| | | } else { |
| | | } |
| | | } |
| | |
| | | mLinphoneCore.addProxyConfig(prxCfg);//添加代理配置。如果启用了注册,这将开始在代理上注册。 |
| | | mLinphoneCore.addAuthInfo(authInfo);//添加认证信息到,该信息片段将在所有需要的SIP事务中使用身份验证 |
| | | mLinphoneCore.setDefaultProxyConfig(prxCfg);//设置默认代理。 |
| | | |
| | | } |
| | | |
| | | public void sendSipMessage(String sipAddress, String message) { |
| | | try { |
| | | Core mLinphoneCore = HDLLinphoneService.getCore(); |
| | | if (mLinphoneCore == null) { |
| | | Log.e("Linphone", "Linphone Core 未初始化"); |
| | | return; |
| | | } |
| | | |
| | | // 解析对方的SIP地址 |
| | | Address address = mLinphoneCore.interpretUrl(sipAddress); |
| | | |
| | | // 建立对话 |
| | | ChatRoom chatRoom = mLinphoneCore.getChatRoom(address); |
| | | |
| | | // 创建消息 |
| | | ChatMessage chatMessage = chatRoom.createMessageFromUtf8(message); |
| | | |
| | | // 监听消息状态 |
| | | chatMessage.addListener(new ChatMessageListener() { |
| | | @Override |
| | | public void onChatMessageStateChanged(Core core, ChatMessage msg, ChatMessage.State state) { |
| | | if (state == ChatMessage.State.Delivered) { |
| | | Log.d("Linphone", "消息已成功发送"); |
| | | } else if (state == ChatMessage.State.NotDelivered) { |
| | | Log.d("Linphone", "消息发送失败"); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | // 发送消息 |
| | | chatMessage.send(); |
| | | |
| | | } catch (Exception e) { |
| | | Log.e("Linphone", "消息发送失败", e); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 提交账号和密码注册到全视通服务器 |
| | |
| | | if (addressToCall != null) { |
| | | call = core.inviteAddressWithParams(addressToCall, params); |
| | | // 设置外放 |
| | | for (AudioDevice audioDevice : HDLLinphoneService.getCore().getAudioDevices()) { |
| | | if (audioDevice.getType() == AudioDevice.Type.Speaker) { |
| | | call.setOutputAudioDevice(audioDevice); |
| | | try { |
| | | for (AudioDevice audioDevice : HDLLinphoneService.getCore().getAudioDevices()) { |
| | | if (audioDevice.getType() == AudioDevice.Type.Speaker) { |
| | | call.setOutputAudioDevice(audioDevice); |
| | | } |
| | | } |
| | | }catch (Exception exception){ |
| | | Log.e("LinphoneError",exception.getMessage()); |
| | | } |
| | | } |
| | | } |