错误:异常InterruptedException从未抛出在相应的try语句的正文中

时间:2019-07-15 07:29:43

标签: java android multithreading

我正在运行以下线程。我从SO那里获得了有关如何正确启动和停止线程的帮助。

我的编译器出现以下错误。

  

错误:异常InterruptedException从未在主体中抛出   相应的try语句

我是Java世界的新手,被困住了。

只需卸下挡块,这是否是解决问题的正确方法?

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();
      }
    }
  }
}

0 个答案:

没有答案