未能更新UIImageView

问题描述:

我试图通过本地IP流MJPEG视频到我的iOS应用程序。连接建立并且流成功,我可以在控制台中看到十六进制值更新。但是,UIImageView仅显示它收到的第一帧,并且在此之后不会更新。代码有什么问题?我甚至尝试用setNeedsDisplay刷新视图,但没有帮助。我知道NSURLConnection在iOS 9+中已弃用,这只是为了测试代码,因此如何解决这个问题?未能更新UIImageView

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 

@synthesize recievedData; 

- (void)viewDidLoad { 
    NSURLRequest *theRequest = 
    [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://192.168.0.15:8090/?action=stream"]]; 
    NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 
    recievedData = [[NSMutableData alloc] init]; 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 
    [recievedData appendData:data]; 
} 

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 
    NSLog(@"%@",recievedData); 

    UIImage *recievedImage = [UIImage imageWithData:recievedData]; 
    self.streamView.image = recievedImage; 
     [self.streamView setNeedsDisplay]; 


} 

@end 

因为我看到这是视频流,您需要使用视频播放器来显示媒体内容。

+0

它的图像流不是视频流,其格式为“MJPEG”。它只需要抓取图像并在UIImageView中进行更新。 MJPEG - 在多媒体中,Motion JPEG(M-JPEG或MJPEG)是一种视频压缩格式,其中数字视频序列的每个视频帧或隔行场作为JPEG图像单独压缩。 –