android 播放视频?
本帖最后由 kaly_liu 于 2013-08-13 15:23:29 编辑 安卓客户端是利用socket进行摄像头数据的传送的,在另一台android设备上如何接收并播放?
Socket tempSocket = new Socket(ipname, port);
outsocket = tempSocket.getOutputStream();
//写入头部数据信息
String msg=java.net.URLEncoder.encode("PHONEVIDEO|"+username+"|","utf-8");
byte[] buffer= msg.getBytes();
outsocket.write(buffer);
//将数据转成 数据流
ByteArrayInputStream inputstream = new ByteArrayInputStream(myoutputstream.toByteArray());
int amount;
//在while括号里面 读取数据的个数 amount
while ((amount = inputstream.read(byteBuffer)) != -1) {
outsocket.write(byteBuffer, 0, amount);//将 byteBuffer里的数据发送出去 ,一共有amount个
}
myoutputstream.flush();
myoutputstream.close();
tempSocket.close();
if(data!=null)
{
YuvImage image = new YuvImage(data,VideoFormatIndex, VideoWidth, VideoHeight,null);
if(image!=null)
{
ByteArrayOutputStream outstream = new ByteArrayOutputStream();
//在此设置图片的尺寸和质量
image.compressToJpeg(new Rect(0, 0, (int)(VideoWidthRatio*VideoWidth),
(int)(VideoHeightRatio*VideoHeight)), VideoQuality, outstream);
outstream.flush();
//启用线程将图像数据发送出去
Thread th = new MySendFileThread(outstream,pUsername,serverUrl,serverPort);
th.start();
}