如何避免增加堆警告以停止图像视图冻结?

时间:2019-07-16 17:28:44

标签: android video-streaming audio-streaming tcpsocket

我正在尝试将视频和音频从android设备流传输到服务器。 当我将图像字节或音频字节分别发送到另一台android设备上的服务器时,它工作正常。但是当我尝试发送此字节时,服务器同时工作2或7分钟,之后没有任何错误,图像视图被冻结,但应用仍在运行。警告“增长堆”后图像视图冻结 我使用TCP套接字,但我不想使用UDP套接字。

我将此行添加为清单“ android:largeHeap =“ true”“,但无济于事;

while (true) {
try {
int token = inputStream.readInt();
if (token == 4) {
int imgLength = inputStream.readInt();
byte[] buffer = new byte[imgLength];
int len = 0;
while (len < imgLength) {
len += inputStream.read(buffer, len, imgLength - len);
              }
displayStream(buffer);
}

 if(token==5) {
int audioLength= inputStream.readInt();
byte[] buffer = new byte[audioLength];
int len = 0;
while (len < audioLength) {
len += inputStream.read(buffer, len, audioLength - len);
}

playAudio(buffer);
}   
} catch (Exception e) {
 e.printStackTrace();
}
}

private  void  displayStream(final byte[] buffer){
Runnable runnable=    new Runnable() {
@Override
public void run() {
Bitmap lastframe=BitmapFactory.decodeByteArray(buffer, 0, 
buffer.length,bitmap_options);
mCameraView.setImageBitmap(lastframe);

}
};
handler2.postDelayed(runnable,1000/15);
}


private  void playAudio(final byte[] buffer) {
Thread th=new Thread(new Runnable() {
 @Override
 public void run() {

  myAudioTrack.write(buffer, 0, buffer.length);
  myAudioTrack.play();

}
});
th.run();

}

0 个答案:

没有答案