2016-08-22 4 views
1

フリーズスイッチサーバーが設定されているため、2つのFSClientインスタンス間でオーディオコールを正常に行うことができます。ただし、同じ2つの番号を使用して、FSClientインスタンスとAndroidフォンの間でVOIPコールを接続すると、コールは受信されて応答されますが、音声はありません。私がAndroidで間違っていることを教えてください。私のコードは下に貼り付けられます。私のカスタムSIPアプリケーションをFSClientとAndroid phoneの間で使用している間に音声がありません

提供できるヘルプをお試しいただきありがとうございます。

public class MainActivity extends Activity { 

public SipManager mSipManager = null; 
private SipProfile mSipProfile = null; 
public SipAudioCall incomingCall = null; 
private final MediaPlayer mediaPlayer = new MediaPlayer(); 

private class IncomingAudioCallReceiver extends BroadcastReceiver { 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     // TODO Auto-generated method stub 

     final Context appContext = context; 

     try { 
      SipAudioCall.Listener listener = new SipAudioCall.Listener() { 
       @Override 
       public void onRinging(SipAudioCall call, android.net.sip.SipProfile caller) { 
        try { 

         Toast.makeText(appContext, "Incoming Call Event", Toast.LENGTH_SHORT).show(); 

         mediaPlayer.stop(); 
         incomingCall = call; 
         incomingCall.answerCall(30); 
         incomingCall.startAudio(); 
         incomingCall.setSpeakerMode(true); 
         if(incomingCall.isMuted()) { 
          incomingCall.toggleMute(); 
         } 
        } catch (Exception e) { 
         e.printStackTrace(); 
        } 
       } 

       @Override 
       public void onCallEstablished(SipAudioCall call) { 
        // Call picked UI 
        Toast.makeText(appContext, "Call is On", Toast.LENGTH_SHORT).show(); 
       } 

       @Override 
       public void onCallEnded(SipAudioCall call) { 
        // Call ended. Back to normal UI 
       } 
      }; 

      mediaPlayer.setDataSource(context, RingtoneManager 
        .getDefaultUri(RingtoneManager.TYPE_RINGTONE)); 
      mediaPlayer.setAudioStreamType(AudioManager.STREAM_RING); 
      mediaPlayer.prepare(); 
      mediaPlayer.start(); 

      incomingCall = mSipManager.takeAudioCall(intent, null); 
      incomingCall.setListener(listener, true); 


     } catch (Exception e) { 
      if (incomingCall != null) { 
       incomingCall.close(); 
      } 
     } 
    } 
} 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    IntentFilter filter = new IntentFilter(); 
    filter.addAction("android.TestVoip.INCOMING_CALL"); 
    IncomingAudioCallReceiver callReceiver = new IncomingAudioCallReceiver(); 
    registerReceiver(callReceiver, filter); 

    Button btnConnect = (Button) findViewById(R.id.connect); 
    btnConnect.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      instantiateSip(); 
     } 
    }); 

    Button btnCall = (Button) findViewById(R.id.testCall); 
    btnCall.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      initialiseCall(); 
     } 
    }); 

    Button btnDisconnect = (Button) findViewById(R.id.disconnect); 
    btnDisconnect.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      try { 
       mSipManager.close(mSipProfile.getUriString()); 
      } catch (SipException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
     } 
    }); 

    Button btnAnswerCall = (Button) findViewById(R.id.answerCall); 
    btnAnswerCall.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      try { 
       Toast.makeText(getApplicationContext(), "Answer Incoming", Toast.LENGTH_SHORT).show(); 
       incomingCall.answerCall(200); 
       incomingCall.startAudio(); 
       incomingCall.setSpeakerMode(true); 
       if(incomingCall.isMuted()) 
        incomingCall.toggleMute(); 
      } catch (SipException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
     } 
    }); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 
    if (id == R.id.action_settings) { 
     return true; 
    } 
    return super.onOptionsItemSelected(item); 
} 

private void instantiateSip() 
{ 
    try { 
     if(mSipManager == null) { 
      mSipManager = SipManager.newInstance(this); 
     } 

     EditText txtUserName = (EditText) findViewById(R.id.username); 
     EditText txtPassword = (EditText) findViewById(R.id.pass); 

     SipProfile.Builder builder = new SipProfile.Builder(txtUserName.getText().toString(), "14.49.56.12"); 
     builder.setPassword(txtPassword.getText().toString()); 
     builder.setPort(5060); 
     builder.setProtocol("TCP"); 

     mSipProfile = builder.build(); 

     SipRegistrationListener regnListener = new SipRegistrationListener() { 

      @Override 
      public void onRegistrationFailed(String localProfileUri, int errorCode, 
        String errorMessage) { 
       // TODO Auto-generated method stub 
       runOnUiThread(new Runnable() { 
        public void run() { 
         Toast.makeText(getApplicationContext(), "Registration failed. Please check settings.", Toast.LENGTH_SHORT).show(); 
        } 
       }); 

      } 

      @Override 
      public void onRegistrationDone(String localProfileUri, long expiryTime) { 
       // TODO Auto-generated method stub 

       runOnUiThread(new Runnable() { 
        public void run() { 
         Toast.makeText(getApplicationContext(), "Ready", Toast.LENGTH_SHORT).show(); 
        } 
       }); 

      } 

      @Override 
      public void onRegistering(String localProfileUri) { 
       // TODO Auto-generated method stub 

       runOnUiThread(new Runnable() { 
        public void run() { 
         Toast.makeText(getApplicationContext(), "Registering with SIP Server...", Toast.LENGTH_SHORT).show(); 
        } 
       }); 

      } 
     }; 

     System.out.println(mSipProfile.getUriString()); 

     Intent intent = new Intent(); 
     intent.setAction("android.TestVoip.INCOMING_CALL"); 
     PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, Intent.FILL_IN_DATA); 

     //mSipManager.register(mSipProfile, 200, regnListener); 

     mSipManager.open(mSipProfile, pendingIntent, null); 

     Toast.makeText(getApplicationContext(), "Opened Connection", Toast.LENGTH_SHORT).show(); 

     /* 
     if (mSipManager.isRegistered(mSipProfile.getUriString())) 
     { 
      mSipManager.open(mSipProfile); 
     } 
     else 
     { 
      mSipManager.register(mSipProfile, 200, regnListener); 
     } 
     */ 

    } catch (ParseException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (SipException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
} 

private void initialiseCall() 
{ 
    try { 
     SipAudioCall.Listener listener = new SipAudioCall.Listener() { 

      @Override 
      public void onRinging(SipAudioCall call, android.net.sip.SipProfile caller) { 
       try { 

        Toast.makeText(getApplicationContext(), "Ringing", Toast.LENGTH_SHORT).show(); 
       } catch (Exception e) { 
        e.printStackTrace(); 
       } 
      } 

       @Override 
       public void onCallEstablished(SipAudioCall call) { 

        Toast.makeText(getApplicationContext(), "Answered Call", Toast.LENGTH_SHORT).show(); 
        call.startAudio(); 
        call.setSpeakerMode(true); 
        call.toggleMute(); 
       } 

       @Override 
       public void onCallEnded(SipAudioCall call) { 
        // Do something. 
        super.onCallEnded(call); 
        Toast.makeText(getApplicationContext(), "Ended Call", Toast.LENGTH_SHORT).show(); 
       } 
      }; 

      EditText txtNumberToCall = (EditText) findViewById(R.id.numberToCall); 

     SipAudioCall call = mSipManager.makeAudioCall(
       mSipProfile.getUriString(), "sip:" + txtNumberToCall.getText().toString() + "@14.49.56.12", listener, 30); 

     Toast.makeText(getApplicationContext(), "Call placed", Toast.LENGTH_SHORT).show(); 

    } catch (SipException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 

     Toast.makeText(getApplicationContext(), "Exception :" + e.getMessage(), Toast.LENGTH_SHORT).show(); 
    } 
} 

}

+0

権限を設定し、<使用許可アンドロイド:名= "android.permission.USE_SIP" /> <使用許可アンドロイド:名= "android.permission.INTERNETあなた" />は \tは<アンドロイド許可使用しています「use-feature android:name = "android":android.permission.MODIFY_AUDIO_SETTINGS "/> \t \t .software.sip.voip "android:required =" true "/> –

答えて

1

は答えを見つけました!ドキュメントごとに、startAudio()には2つのパーミッションが設定されている必要があります。私がそれらを追加すると、私は両耳でオーディオを取得し始めました。

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="android.permission.WAKE_LOCK" /> 
関連する問題