Answer the question
In order to leave comments, you need to log in
Getting mjpeg video stream from ip camera in iOS app?
Hello. I'm trying to asynchronously (using NSURLConnection) load a mjpeg video stream from an IP camera into an iOS7 application, displaying it in a UIImageView. The application screen in iOSSimulator remains blank. Where is the fluff in my code? I am new to iOS programming. I read a lot of materials on receiving mjpeg video stream. Thank you.
// ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIImageView *cameraView;
@end
NSMutableData *dataResponse; // buffer for accumulating data
====================================================
// ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSString *cameraURL = @"http://192.168.1.160:554/video.mjpg";
NSURL *url = [NSURL URLWithString:cameraURL];
NSURLRequest *requestURLcamera = [NSURLRequest requestWithURL:url]; // URL request
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:requestURLcamera delegate:self startImmediately:YES]; // connecting
}
- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning];}
- (void)connection: (NSURLConnection *) connection didReceiveData:(NSData *)data
{ [dataResponse appendData:data]; } // accumulating data
- (void)connection: (NSURLConnection *) connection didReceiveResponse:(NSURLResponse *)response
{ UIImage *imageZ = [UIImage imageWithData:dataResponse]; // creating image
_cameraView.image = imageZ; // image to UIImageView
dataResponse = nil; // reset of dataResponse
}
@end
Answer the question
In order to leave comments, you need to log in
From what I saw - you do not create a dataResponse.
You need to write either in viewDidLoad or in the delegate method where the data is received.
PS In general, you are looking at the old lessons. NSURLConnection - deprecated already
look for tutorials on NSURLSession. Or AFNetworking (it's a third party library)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question