通过流获取帧并在屏幕上显示 [英] Getting frames though a stream and display on screen
问题描述
我需要从服务器流式传输并在屏幕上显示流式内容...使用NSStream和NSInputStream以及NSOutputStream流式传输正常工作。如何在屏幕上显示它?
I have a requirement of streaming from server and displaying the streamed content on the screen...Streaming is working fine using NSStream, and NSInputStream and NSOutputStream.How can I display it on the screen?
使用的流看起来像@ http://191.168.143.41:1212/ ;
Stream used looks like @"http://191.168.143.41:1212/;
if(stream == inputStream) {
uint8_t buf[1024];
unsigned int len = 0;
len = [inputStream read:buf maxLength:1024];
if(len > 0) {
NSMutableData* datas=[[NSMutableData alloc] initWithLength:0];
[datas appendBytes: (const void *)buf length:len];
NSString *s = [[NSString alloc] initWithData:datas encoding:NSASCIIStringEncoding];
[self readIn:s];
NSLog(@"ss%@",s);
[self loadMovie:s]; //method for movie player
}
我试图将它显示在电影播放器中下面..
I tried to display this is in a movieplayer as below..
-(void_loadMovie:(NSString*)moviePrefix
{
NSString *path = [NSString stringWithFormat:@"%@.mjpg", moviePrefix];
NSURL *url = [NSURL fileURLWithPath:path];
if (url) {
_moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
_moviePlayer.view.frame = CGRectMake(0, 70, 600, 450);
_moviePlayer.controlStyle = MPMovieControlStyleNone;
_moviePlayer.scalingMode = MPMovieScalingModeNone;
[dic setObject:__moviePlayer forKey:path];
}
}
[_moviePlayer prepareToPlay];
[self.view addSubview: _moviePlayer.view];
[self.view bringSubviewToFront:_moviePlayer.view];
[self.view addSubview: _moviePlayer.view];
[_moviePlayer play];
}
是NSS tring * path = [NSString stringWithFormat:@%@。mjpg,moviePrefix];正确的方法??
Is NSString *path = [NSString stringWithFormat:@"%@.mjpg", moviePrefix]; correct way??
这显示黑屏。出了什么问题?
如果这种方式不正确,有没有其他方法可以显示这些帧?
任何人都可以帮我解决这个问题......
This displays a black screen.What is wrong? If this way is not correct,Is there any other way I can display those frames? Can anyone help me to solve this...
推荐答案
https://github.com/horsson/mjpeg-iphone/tree/55251a85e2c2489014036ddf5a491783f9b1962d
用它来获取流和显示。它工作
Used this to get the stream and display.It works
这篇关于通过流获取帧并在屏幕上显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!