开发者

iPhone Test if Video Link is Active

开发者 https://www.devze.com 2023-03-13 11:32 出处:网络
I have created an app capable of live streaming, but I currently have no way of testing if the the video is active or not.I am trying to create an if else statment that will test if the video is activ

I have created an app capable of live streaming, but I currently have no way of testing if the the video is active or not. I am trying to create an if else statment that will test if the video is active or not. I am using a JSON web service that returns a result of "d". I am currently using the block of code below in the IB action designed to play the video file:

-(IBAction) playVideo:(id)sender {
NSString *baseVideoUrl = @"http://streaming5.calvaryccm.com:1935/live/iPhone/p开发者_开发问答laylist.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];  
    } 

}
}

I don't know what I am doing wrong. I need help creating the statement that tests if the streaming is active.


First of all use isEqualToString: to compare NSStrings. What you're doing in the if statement is an assignment which will evaluate to true. So do this instead,

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

There is also another issue here. You are creating an NSMutableURLRequest object but it is never evaluated. While I haven't a proper idea of how this JSON web service is implemented, I would expect it to be something like,

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号