简体   繁体   中英

Activity indicator not working in iOS?

I've to play A video from server and it takes some time. So I've Written an activityIndicator and started animating it. but the activity indicator is not showing up until the video is playing. Firs I've hidden activity indicator later unhidden it and started animating but its shown when the video is started playing.

Here is my code: for info indicatorView is a UIView and I've indView is an UIIndicatorView inside of UIView; And I'm using AV Player for playing;

Please Read Clearly that indicator view is showing up in the view, but the problem is not showing up when i Said start animating but after some time when video is started.

  indicatorView.hidden = NO;
  [indView startAnimating];

//Here Indicator view must shown in VIEW but it's not showing up;

  MediaItem *item = [allVideos objectAtIndex:indexPath.row];
  [playerModel playMyVideo:item];

// now here after 5 sec when video is ready to play it's showing up

What is the problem. I've used dispach asynch in both the places but no use

I've used dispach asynch in both the places but no use

But is this code being run on the main thread? UI updates should be executed on the main thread.

dispatch_async(dispatch_get_main_queue(), ^{
    //UI code
});

Change [playerModel playMyVideo:item]; to

[playerModel performSelector:@selector(playMyVideo:) withObject:item afterDelay:0.0001f inModes:@[NSRunLoopCommonModes]];

Just add one method like,

-(void) videoPrepareToPlay {
    MediaItem *item = [allVideos objectAtIndex:indexPath.row];
    [playerModel playMyVideo:item];
}

and call that method like,

   indicatorView.hidden = NO;
  [indView startAnimating];
  [self performSelector:@selector(videoPrepareToPlay) withObject:nil afterDelay:0.2];

It may be work for you..

Execute the ActivityIndicator code using performSelectorOnMainThread and retrieve the video using background thread.

ELSE

Easy Fix:

Use this https://github.com/jdg/MBProgressHUD

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM