Pregunta

Estoy tratando de hacer un visor de MJPEG en Objective C pero estoy teniendo un montón de problemas con él.

En primer lugar, estoy usando AsyncSocket ( http://code.google.com/p / cocoaasyncsocket / ) que me permite conectar con el host.

Esto es lo que tengo hasta ahora

NSLog(@"Ready");
asyncSocket = [[AsyncSocket alloc] initWithDelegate:self];
//http://kamera5.vfp.slu.se/axis-cgi/mjpg/video.cgi
NSError *err = nil;
if(![asyncSocket connectToHost:@"kamera5.vfp.slu.se" onPort:80 error:&err])
{
    NSLog(@"Error: %@", err);
}

a continuación, en el método didConnectToHost:

 - (void)onSocket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port{
NSLog(@"Accepted client %@:%hu", host, port);


NSString *urlString = [NSString stringWithFormat:@"http://kamera5.vfp.slu.se/axis-cgi/mjpg/video.cgi"];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"GET"];

    //set headers
NSString *_host = [NSString stringWithFormat:host];
[request addValue:_host forHTTPHeaderField: @"Host"];

NSString *KeepAlive = [NSString stringWithFormat:@"300"];
[request addValue:KeepAlive forHTTPHeaderField: @"Keep-Alive"];

NSString *connection = [NSString stringWithFormat:@"keep-alive"];
[request addValue:connection forHTTPHeaderField: @"Connection"];


//get response
NSHTTPURLResponse* urlResponse = nil;  
NSError *error = [[NSError alloc] init];  
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error]; 

NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

NSLog(@"Response Code: %d", [urlResponse statusCode]);
if ([urlResponse statusCode] >= 200 && [urlResponse statusCode] < 300) {
    NSLog(@"Response: %@", result);
            //here you get the response
}

}

Esto llama la corriente MJPEG, pero no lo llama para obtener más datos. Lo que creo que es haciendo es cargar el primer fragmento de datos, a continuación, desconectar.

¿Lo estoy haciendo totalmente equivocado o hay luz al final del túnel?

Gracias!

¿Fue útil?

Solución

Trate de cargar el MJPEG en un UIWebView, debería ser capaz de reproducir de forma nativa.

Asumiendo que tiene un UIWebView llamado "myWebView", algo como esto debería funcionar:

NSURLRequest* urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://kamera5.vfp.slu.se/axis-cgi/mjpg/video.cgi"]];
[myWebView loadRequest:urlRequest];

Espero que ayude!

Otros consejos

El problema principal es que webkit Nunca suelte los datos, por lo que después de un tiempo que explote.

Eso probablemente lo mejor sería hecho con JavaScript, ya que no es una buena manera de comunicarse con UIWebView lo contrario.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top