show progress bar until video loads IOS7

前端 未结 1 659
旧巷少年郎
旧巷少年郎 2021-01-14 06:19

Hi in my application I\'m playing the video using URL. I\'m passing the video URL form my server now the problem its taking to much time to play the video. So i want to show

相关标签:
1条回答
  • 2021-01-14 06:41

    1.create new view control

    2.pass your videoarray1 value to nextvieww control i mean your video url

    3.add following code nextview control

    - (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 buffered 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;
    }
    
    0 讨论(0)
提交回复
热议问题