我正在 iPad 上从名为 Foscam 的 IP 摄像机获取流。如果我在 iPad 浏览器中打开 IP,那么它运行良好,但是当我在我的应用程序中获取流时,它会出现第一个屏幕截图并卡在上面。应用程序没有从 cam 获得连续的流媒体。我正在使用这种方式
- (IBAction)powerChanged:(id)sender {
UISwitch * s = (UISwitch *)sender;
if( s.on == TRUE){
[self initializeData];
if(![deviceClient connect]){
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Can not connect to T-Rex device!"
message:[[NSString alloc] initWithFormat:@"Could not connec to %@ and %d port",deviceClient.host,deviceClient.port]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[message show];
[s setOn:FALSE animated:TRUE];
} else {
[self adjustLayout:TRUE];
[self startFrequencyTimer];
}
}else {
[self stopFrequencyTimer];
[self adjustLayout:FALSE];
}
}
-(void)initializeData {
[cameraViewFront loadRequest:[NSURLRequest requestWithURL:[frontCameraClient getVideoStreamURL]]];
}
-(BOOL)connect {
if (udpSocket == nil){
udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
}
NSLog(@"host %@ and port %i", self.host, self.port);
return [udpSocket connectToHost:self.host onPort:self.port error:nil];
}
- (NSURL *) getURL:(NSString *)forPage {
NSLog(@"front cam IP %@" ,self.host);
return [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"http://%@/%@user=%@&pwd=%@",self.host,forPage,self.username, self.password]];
}
-(NSURL *)getVideoStreamURL{
return [self getURL:@"videostream.cgi?"];
}