2016-07-09 43 views
0

我試圖通過本地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

因爲我看到這是視頻流,您需要使用視頻播放器來顯示媒體內容。

+0

它的圖像流不是視頻流,其格式爲「MJPEG」。它只需要抓取圖像並在UIImageView中進行更新。 MJPEG - 在多媒體中,Motion JPEG(M-JPEG或MJPEG)是一種視頻壓縮格式,其中數字視頻序列的每個視頻幀或隔行場作爲JPEG圖像單獨壓縮。 –