Note that there are some explanatory texts on larger screens.

plurals
  1. POcurrentPlaybackTime & NSTimer to launch views during a video and be correctly launched/relaunched when time point positioned with the scrubber
    primarykey
    data
    text
    <p>Struggling here...</p> <p>I am trying to have views displayed during specific periods in a videos timeline, being replaced when the next view is triggered. This much I have managed to do - my problem is that this only happens in a linear fashion and if the playhead is moved back to a view that has already been triggered (ie anything prior to that point) the timer continues on, but the triggers are no longer firing.</p> <p>Any help will be greatly appreciated! Here's the code...</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; keyframeTimes = [[NSMutableArray alloc] init]; shoutOutTexts = [[NSArray arrayWithObjects:@"This is a test\nLabel at 2 secs ", @"This is a test\nLabel at 325 secs", nil] retain]; shoutOutTimes = [[NSArray arrayWithObjects:[[NSNumber alloc] initWithInt: 2], [[NSNumber alloc] initWithInt: 325], nil] retain]; self.player = [[MPMoviePlayerController alloc] init]; self.player.contentURL = [self movieURL]; // END:viewDidLoad1 self.player.view.frame = self.viewForMovie.bounds; self.player.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; [self.viewForMovie addSubview:player.view]; [self.player play]; // START_HIGHLIGHT [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(timerAction:) userInfo:nil repeats:YES]; // END_HIGHLIGHT // START:viewDidLoad1 [self.view addSubview:self.myScrollView]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieDurationAvailable:) name:MPMovieDurationAvailableNotification object:nil]; } // END:viewDidLoad // END:viewDidLoad1 // START:movieURL -(NSURL *)movieURL { NSBundle *bundle = [NSBundle mainBundle]; NSString *moviePath = [bundle pathForResource:@"BigBuckBunny_640x360" ofType:@"m4v"]; if (moviePath) { return [NSURL fileURLWithPath:moviePath]; } else { return nil; } } // END:movieURL int position = 0; - (void)timerAction:(NSTimer*)theTimer { NSLog(@"hi"); int count = [shoutOutTimes count]; NSLog(@"count is at %d", count); if (position &lt; count) { NSNumber *timeObj = [shoutOutTimes objectAtIndex:position]; int time = [timeObj intValue]; NSLog(@"time is at %d", time); if (self.player.currentPlaybackTime &gt;= time) { CommentView *cview = [[CommentView alloc] initWithText:[shoutOutTexts objectAtIndex:position]]; [self.player.view addSubview:cview]; position++; [NSTimer scheduledTimerWithTimeInterval:4.0f target:self selector:@selector(removeView:) userInfo:cview repeats:NO]; } } } - (void)removeView:(NSTimer*)theTimer { UIView *view = [theTimer userInfo]; [view removeFromSuperview]; } </code></pre> <p>Here's the log calls Till...</p> <p>Here's the log calls...</p> <pre><code>2011-04-23 11:53:44.370 MoviePlayer[17129:207] last check was at 7.76279 2011-04-23 11:53:44.371 MoviePlayer[17129:207] current playback time is 8.76292 2011-04-23 11:53:44.371 MoviePlayer[17129:207] shouting: This is a test Label at 2 secs 2011-04-23 11:53:45.368 MoviePlayer[17129:207] position is at 2 2011-04-23 11:53:45.369 MoviePlayer[17129:207] shout scheduled for 8 2011-04-23 11:53:45.370 MoviePlayer[17129:207] last check was at 8.76451 2011-04-23 11:53:45.371 MoviePlayer[17129:207] current playback time is 9.76299 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload