私はこれらのカムのためにウェブカメラビューアに取り組んでいます:http://www.canvision.net/support/pt300-cgi/GetData.htm
データは次のように到着します:
HTTP/1.0 200 OK
Date: Wed, 19 Feb 2003 03:40:16 GMT
Server: WYM/1.0
Connection: close
Content-Type: multipart/x-mixed-replace;boundary=WINBONDBOUDARY
Last-Modified: Wed, 19 Feb 2003 03:40:16 GMT
Pragma: no-cache
Cache-Control: no-cache
Expires: 01 Jan 1970 00:00:00 GMT
--WINBONDBOUDARY
Content-Type: image/jpeg
--WINBONDBOUDARY
Content-Type: image/jpeg
これらは私のNSURLConnectionデリゲートメソッドです:
- (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)data
{
[currentData appendData:data];
}
- (void)connection:(NSURLConnection *)theConnection didReceiveResponse:(NSURLResponse *)response{
NSLog(@"response with mime: %@ length:%i",[response MIMEType],[currentData length]);
if([[response MIMEType] isEqualToString:@"image/jpeg"] && [currentData length] != 0){
currentFrame = [UIImage imageWithData:currentData];
NSLog(@"valid frame");
[image setImage:currentFrame];
frameCounter++;
}
else {
NSLog(@"other data:%@",currentData);
}
currentFrame = nil;
if (currentData == receivedData1)//swap buffers
currentData = receivedData2;
else
currentData = receivedData1;
[currentData setLength:0];
[currentFrame release];
}
これはすべて正常に機能し、コンソール出力は期待どおりに表示されます。
[Session started at 2011-02-21 20:20:39 +0100.]
2011-02-21 20:20:43.237 MotionJPEG[16330:207] response with mime: multipart/x-mixed-replace length:0
2011-02-21 20:20:43.261 MotionJPEG[16330:207] other data:<>
2011-02-21 20:20:43.262 MotionJPEG[16330:207] response with mime: image/jpeg length:0
2011-02-21 20:20:43.263 MotionJPEG[16330:207] other data:<>
2011-02-21 20:20:43.340 MotionJPEG[16330:207] response with mime: image/jpeg length:4608
2011-02-21 20:20:43.340 MotionJPEG[16330:207] valid frame
2011-02-21 20:20:43.445 MotionJPEG[16330:207] response with mime: image/jpeg length:4600
2011-02-21 20:20:43.446 MotionJPEG[16330:207] valid frame
2011-02-21 20:20:43.544 MotionJPEG[16330:207] response with mime: image/jpeg length:4580
2011-02-21 20:20:43.545 MotionJPEG[16330:207] valid frame
ただし、Camは別のモードをサポートしており、jpeg間に追加情報が埋め込まれています。
HTTP/1.0 200 OK
Date: Wed, 19 Feb 2003 03:40:16 GMT
Server: WYM/1.0
Connection: close
Content-Type: multipart/x-mixed-replace;boundary=WINBONDBOUDARY
Last-Modified: Wed, 19 Feb 2003 03:40:16 GMT
Pragma: no-cache
Cache-Control: no-cache
Expires: 01 Jan 1970 00:00:00 GMT
--WINBONDBOUDARY
Content-Type: image/jpeg
--WINBONDBOUDARY
Content-Type: text/plain
--WINBONDBOUDARY
Content-Type: image/jpeg
--WINBONDBOUDARY
Content-Type: text/plain
このモードでは、コードは正常に機能し、テキスト/プレーン部分はコンソールに書き込まれると予想されます。
NSLog(@"other data:%@",currentData);
ライン。ただし、何らかの理由で、出力はまったく同じに見え、mimeで応答を示すことはありません。代わりにtext / plain、プレーンテキスト部分がjpegに追加され、UIImageViewはデータを表示できません。NSURLConnectionがテキスト/プレーン部分を認識しないのはなぜですか?完全なソースは次のとおりです:http://renehopf.de/MotionJPEG.zip しかし、問題を再現するには、同じWebカメラが必要になります...
ありがとう、
レネ