I have the following thread running. I got help from SO, that how to start and stop thread properly.
I am getting the following error in my compiler.
error: exception InterruptedException is never thrown in body of corresponding try statement
I am new to Java world and got stuck.
Just removing the catch block, Is it a proper way to solve the problem?
public class MyThread extends Thread {
InetAddress inetAddress;
AudioGroup audioGroup = new AudioGroup();
MediaPlayer mediaPlayer = new MediaPlayer();
@Override
public void run() {
if (!Thread.interrupted()) {
try {
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
audioManager.setSpeakerphoneOn(true);
audioGroup.setMode(AudioGroup.MODE_ECHO_SUPPRESSION);
mediaPlayer.setAudioStreamType(audioManager.STREAM_VOICE_CALL);
inetAddress = InetAddress.getByName(getLocalIpAddress());
audioStream = new AudioStream(inetAddress);
audioStream.setCodec(AudioCodec.PCMU);
audioStream.setMode(RtpStream.MODE_NORMAL);
InetAddress inetAddressRemote = InetAddress.getByName(remoteIp);
audioStream.associate(inetAddressRemote, remotePort);
audioStream.join(audioGroup);
//streaming the audio to speakers
mediaPlayer.setDataSource(getLocalIpAddress());
mediaPlayer.prepare();
mediaPlayer.start();
//Thread.sleep(4000);
//throw new InterruptedException("");
} catch (InterruptedException e) {
System.out.println("InterruptedException occur" + e.getMessage());
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (SocketException e) {
e.printStackTrace();
} catch (IOException IO) {
IO.printStackTrace();
}
}
}
}