muestra la barra de progreso hasta que el video carga IOS7

Hola, en mi aplicación, estoy reproduciendo el video usando la URL. Estoy pasando la URL del video de mi server, ahora el problema lleva mucho time para reproducir el video. Entonces quiero mostrar la barra de progreso hasta que cargue el video.

Entonces, he usado el MBProgressHUD para la barra de progreso, está mostrando la barra de progreso, pero el video no está reproduciendo, por favor, dime dónde estoy haciendo mal.

Mi código.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSString * currentVideo = [videoarray1 objectAtIndex:indexPath.row]; NSString *strurl=[self urlencode:currentVideo]; NSURL *url=[NSURL URLWithString:strurl]; NSURLRequest *req=[NSURLRequest requestWithURL:url]; NSURLConnection *con=[NSURLConnection connectionWithRequest:req delegate:self]; if (con) { datas=[[NSMutableData alloc]init]; } spinner = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; spinner.mode = MBProgressHUDModeCustomView; [spinner setLabelText:@"Loading file....."]; [spinner setLabelFont:[UIFont systemFontOfSize:15]]; [spinner show:YES]; } -(NSString *)urlencode:(NSString *)str { NSString *encodeString=(NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)str, NULL, (CFStringRef)@"", kCFStringEncodingUTF8)); return encodeString; } - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ NSLog(@"%lld",[response expectedContentLength]); self.length = [response expectedContentLength]; } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data1{ [datas appendData:data1]; float progress = (float)[datas length]/(float)self.length; NSLog(@"%f",progress); float check=progress*100; if (check==100) { [spinner hide:YES]; [spinner removeFromSuperViewOnHide]; } } - (void)connectionDidFinishLoading:(NSURLConnection *)connection{ NSData *data = datas; NSLog(@"%@",data); NSString* myurl; myurl = [[NSString alloc] initWithData:datas encoding:NSASCIIStringEncoding]; NSLog(@"%@",myurl); _movieplayer = [[MPMoviePlayerController alloc]initWithContentURL: [NSURL URLWithString:myurl]]; [[_movieplayer view] setFrame: CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)]; [self.view addSubview: [_movieplayer view]]; [_movieplayer setShouldAutoplay:YES]; [_movieplayer prepareToPlay]; [_movieplayer play]; } 

He usado el código anterior para no reproducir el video, por favor, díganme dónde estoy haciendo mal en el código anterior cómo lograrlo.

Gracias.

1. crear nuevo control de vista

2. pasa tu valor de videoarray1 al control nextvieww me refiero a tu url de video

3. agregue el siguiente código al control nextview

 - (void)viewDidLoad { [super viewDidLoad]; self.indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; self.indicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0); self.indicator.center = self.view.center; [self.view addSubview:self.indicator]; [self.indicator startAnimating]; _movieplayer = [[MPMoviePlayerController alloc]initWithContentURL: [NSURL URLWithString:[self urlencode:self.strPlayUrl]]]; [[_movieplayer view] setFrame: CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)]; [self.view addSubview: [_movieplayer view]]; [_movieplayer setShouldAutoplay:YES]; [_movieplayer prepareToPlay]; //this is the line we need to do [self.view insertSubview:self.movieplayer.view belowSubview:self.indicator]; [self.movieplayer play]; } - (void)viewDidAppear:(BOOL)animated { NSLog(@"VIEW DID LOAD"); // Register to receive a notification that the movie is now in memory and ready to play [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieLoadStateDidChange:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil]; } -(void)movieLoadStateDidChange:(id)sender { NSLog(@"STATE CHANGED"); if(MPMovieLoadStatePlaythroughOK ) { NSLog(@"State is Playable OK"); NSLog(@"Enough data has been buffenetworking for playback to continue uninterrupted.."); self.indicator.hidden = YES; [ self.indicator stopAnimating]; } } -(NSString *)urlencode:(NSString *)str { NSString *encodeString=(NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)str, NULL, (CFStringRef)@"", kCFStringEncodingUTF8)); return encodeString; }