2011-06-15 74 views
0

我已经创建了一个应用程序能够实时流式传输,但是我目前无法测试视频是否处于活动状态。我正在尝试创建一个if if语句来测试视频是否处于活动状态。我正在使用返回“d”结果的JSON Web服务。我目前使用的代码块下面的IB动作设计,播放视频文件:iPhone测试视频链接是否有效

-(IBAction) playVideo:(id)sender { 
NSString *baseVideoUrl = @"http://streaming5.calvaryccm.com:1935/live/iPhone/playlist.m3u8"; 
NSLog(@" finalUrl is : %@",baseVideoUrl); 

//EXPERIMENTAL 

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.calvaryccm.com/ServiceTimes.asmx/IsServiceTime/path"]]; 
[request setHTTPMethod:@"POST"]; 
if (NSString *postString = @"d";) { 
    [request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]]; 
} 
else{ 
    MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:baseVideoUrl]]; 

    if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) { 
     // Use the 3.2 style API 
     moviePlayer.controlStyle = MPMovieControlStyleDefault; 
     moviePlayer.shouldAutoplay = YES; 
     [self.view addSubview:moviePlayer.view]; 
     [moviePlayer setFullscreen:YES animated:YES]; 
    } 

} 
} 

我不知道我做错了。我需要帮助创建测试流是否处于活动状态的语句。

回答

1

首先用isEqualToString:来比较NSString s。您在if声明中所做的是一项评估为真的任务。因此,请改为

if ([responseString isEqualToString:@"d"]) { 
    // Handle active content. 
} 
[..] 

这里还有一个问题。您正在创建一个NSMutableURLRequest对象,但它永远不会被评估。虽然我对如何实现这个JSON网络服务没有一个正确的想法,但我期望它是这样的,

NSError * error = nil; 
NSString * responseString = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.calvaryccm.com/ServiceTimes.asmx/IsServiceTime/path"] 
                encoding:NSUTF8StringEncoding 
                 error:&error]; 
if (error) { 
    NSLog(@"%@", [error localizedDescription]); 
} 

if ([responseString isEqualToString:@"d"]) { 
    // Handle active content. 
} else { 
    // Inform user that the content is unavailable. 
} 
+0

它的工作原理!谢谢! – 2011-06-16 13:11:36