端末から連続 UDP データ(RAW 画像)を受信しています。それをデコードし、ビットマップショーを使用します
動画のように表示されます。問題は、フレームが表示されないことです
継続的に。フレーム変更約。2〜3秒ごとですが、1/30でフレームごとに表示したいです。
以下は私のコードの一部です
public class ArDroneMain extends Activity {
Bitmap image = null;
public ImageView myImageView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
animationDrawable = new AnimationDrawable();
myImageView = (ImageView)findViewById(R.id.imageView);
thread.start();
}
}
Thread thread=new Thread (new Runnable() {
Message message;
String obj="run";
@Override
public void run() {
while(true){
try {
Log.e("enter_video_thread","enter_video_thread");
receiveVideoRawData();
Log.e("///receiveVideoRawData ","receiveVideoRawData");
message = handler.obtainMessage(1,obj);
handler.sendMessage(message);
} catch (IOException e) {
e.printStackTrace();
}
}
}
public Handler handler = new Handler(){
@SuppressLint("NewApi")
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
String MsgString = (String)msg.obj;
if (MsgString.equals("run"))
{
Drawable ardrone_Frame_Drawable =newBitmapDrawable(getResources(),image);
animationDrawable.addFrame(ardrone_Frame_Drawable,100);
myImageView.setBackground(animationDrawable);
}
}
};
public void sendTriggerCommand() throws IOException{
byte [] ip_bytes = new byte[] {(byte)192,(byte)168,(byte)1,(byte)1};//Drone address
byte[] buf_snd = {0x01, 0x00, 0x00, 0x00};//trigger buffer
inet_addr = InetAddress.getByAddress(ip_bytes );
DatagramPacket packet_snd = new DatagramPacket(buf_snd, buf_snd.length, i net_addr, ardrone_video_port);
socket_video.send(packet_snd);
}
public void receiveVideoRawData() throws IOException{
Log.e("enter_receiveVideoRawData()","enter_receiveVideoRawData()");
socket_video = new DatagramSocket();
byte[] buf_rcv = new byte[153600];
DatagramPacket rawData = new DatagramPacket(buf_rcv, buf_rcv.length);
sendTriggerCommand();
Log.e("sendTriggerCommand();","sendTriggerCommand();");
socket_video.receive(rawData);
Log.e("socket_video.receive(rawData);","socket_video.receive(rawData);");
ReadRawFileImage readMyRawData=new ReadRawFileImage();
image = readMyRawData.readUINT_RGBImage(buf_rcv);
}