I am working on Video Player in iOS with MPMediaPlayer framework. I am retrieving the data from server end with JSON responser. My question is I want to Play Video when View was loaded and below is my Code
Please help me.
- (void)viewDidLoad {
videoURL=[NSURL URLWithString:@"http://GetLiveVideoUrl"];
NSMutableURLRequest *urlRequest=[NSMutableURLRequest requestWithURL:videoURL];
[urlRequest addValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
[urlRequest setHTTPMethod:@"POST"];
videoWebData=[[NSURLConnection alloc]initWithRequest:urlRequest delegate:self];
mp = [[MPMoviePlayerController alloc]initWithContentURL:strURL];
mp.view.frame = self.view.bounds; //Set the size
self.view.backgroundColor=[UIColor clearColor];
mp.controlStyle = MPMovieControlStyleNone;
mp.view.userInteractionEnabled = YES;
mp.movieSourceType = MPMovieSourceTypeStreaming;
[self.view addSubview:mp.view]; //Show the view
mp.scalingMode = MPMovieScalingModeFill;
[mp setFullscreen:YES animated:YES];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
NSError *error1;
NSString *stringResponse=[[NSString alloc]initWithData:responseDataVideo encoding:NSUTF8StringEncoding];
NSLog(@"String Resonse is :%@",stringResponse);
videoDict=[NSJSONSerialization JSONObjectWithData:responseDataVideo options:NSJSONReadingAllowFragments error:&error1];
NSLog(@"Dictionary is :%@",videoDict);
strVideoUrl=[NSString stringWithFormat:@"%@",[videoDict valueForKey:@"GetLiveVideoUrlResult"]];
NSLog(@"String URL is :%@",strVideoUrl);
strURL=[NSURL URLWithString:strVideoUrl];
NSLog(@"string url at player :%@",strURL);
}