Android的imageview不刷新问题

panjianle 发布于 2012/06/19 11:09
阅读 5K+
收藏 0

【深度】AI、5G时代下,算力网络与内生安全最全解析!>>>

今天写了一个UDP播放器,接收服务器的流,然后播放

通过j2se塔建,可以正常播放。

然后移植到android上,通过imageview装载,bitmap来构造,点击播放,imageview没有反应,刷新不了,点击暂停,imageview就可以播放,但是几张图片就又卡住了(我的udp发送的流媒体是20帧的,播放速度很快,在j2se上播放和看电影差不多),我想知道,这个是怎么一回事?

 

下面给代码:

//捕获,格式化和修改imageview的方法

public void go() {

rcvdp = new DatagramPacket(buf, buf.length);

try {

// receive the UDP from the socket:

Log.d("Timer", "receiving");

RTPsocket.receive(rcvdp);

Log.d("Timer", "received");

// Os dados estão criptografados. A primeira coisa é

// decriptografá-los.

// Não estou interessado nos 15000 bytes. Só naquilo que

// efetivamente foi preenchido.

final byte[] encryptedBytes = Arrays.copyOfRange(rcvdp.getData(),

0, rcvdp.getLength());

// Métodos para cálculo do desempenho

// ThreadTimes tt = new ThreadTimes( 100 ); // 100ms interval

// tt.start( );

// Decriptografa

byte[] decryptedBytes = null;

switch (RTSPAndroidActivity.algorithm) {

case AES:

decryptedBytes = decriptaAES(encryptedBytes);

break;

case BlowFish:

decryptedBytes = decriptaBlowfish(encryptedBytes);

break;

case DES:

decryptedBytes = decriptaDES(encryptedBytes);

break;

case DESede:

decryptedBytes = decriptaDES3(encryptedBytes);

break;

case XOR:

decryptedBytes = criptaDecripta(encryptedBytes);

break;

case Nenhum:

decryptedBytes = encryptedBytes;

break;

default:

throw new IllegalArgumentException("Algoritmo não previsto");

}

Log.d("Timer", "after switch");

// Constroi o pacote com os dados decriptografados.

final RTPPacket rtpPacket = new RTPPacket(decryptedBytes,

decryptedBytes.length);

// RTPPacket rtpPacket = new RTPPacket(rcvdp.getData(),

// rcvdp.getLength());

 

// print important header fields of the RTP packet received:

System.out.println("Pegou pacote RTP com SeqNum # "

+ rtpPacket.getSequencenumber() + " TimeStamp "

+ rtpPacket.getTimestamp() + " ms, do tipo "

+ rtpPacket.getPayloadType());

 

// print header bitstream:

rtpPacket.printHeader();

 

// get the payload bitstream from the RTPpacket object

final int payload_length = rtpPacket.getPayloadLength();

final byte[] payload = new byte[payload_length];

rtpPacket.getPayload(payload);

bitmap = BitmapFactory.decodeByteArray(payload, 0, payload_length);

// Bitmap bm = Bitmap.createBitmap(bitmap,18,18);

Log.d("Timer", "set bitmap");

iv.setImageBitmap(bitmap);

iv.postInvalidate();

// get an Image object from the payload bitstream

 

} catch (final Exception ex) {

ex.printStackTrace();

}

}

//通过TimerTask来执行

class ChangeImg extends TimerTask {

@Override

public void run() {

// TODO Auto-generated method stub

go();

}

//一分钟20播放20次。

timer.scheduleAtFixedRate(new ChangeImg(), 100, 50);

加载中
返回顶部
顶部