riferiscono sottostante Codice: questo codice è una parte di Apple Codice di esempio
AVPlayerDemo
Se si tenta di implementare un giocatore in streaming, fare riferimento al codice di esempio riportato di seguito.
StitchedStreamPlayer
inoltre, un implementa completo esattamente scrub è di utilizzare il dispositivo di scorrimento come qui di seguito. perché l'ottimo Video Player dovrebbe prendere in considerazione UX. come sapete, eseguendo l'app video predefinita. mentre si esegue lo scrubbing, se il cursore di trascinamento verso il basso deve essere regolato con precisione.
CPSlider | OBSlider
/* The user is dragging the movie controller thumb to scrub through the movie. */
- (IBAction)beginScrubbing:(id)sender
{
mRestoreAfterScrubbingRate = [mPlayer rate];
[mPlayer setRate:0.f];
/* Remove previous timer. */
[self removePlayerTimeObserver];
}
/* Set the player current time to match the scrubber position. */
- (IBAction)scrub:(id)sender
{
if ([sender isKindOfClass:[UISlider class]])
{
UISlider* slider = sender;
CMTime playerDuration = [self playerItemDuration];
if (CMTIME_IS_INVALID(playerDuration)) {
return;
}
double duration = CMTimeGetSeconds(playerDuration);
if (isfinite(duration))
{
float minValue = [slider minimumValue];
float maxValue = [slider maximumValue];
float value = [slider value];
double time = duration * (value - minValue)/(maxValue - minValue);
[mPlayer seekToTime:CMTimeMakeWithSeconds(time, NSEC_PER_SEC)];
}
}
}
/* The user has released the movie thumb control to stop scrubbing through the movie. */
- (IBAction)endScrubbing:(id)sender
{
if (!mTimeObserver)
{
CMTime playerDuration = [self playerItemDuration];
if (CMTIME_IS_INVALID(playerDuration))
{
return;
}
double duration = CMTimeGetSeconds(playerDuration);
if (isfinite(duration))
{
CGFloat width = CGRectGetWidth([mScrubber bounds]);
double tolerance = 0.5f * duration/width;
mTimeObserver = [[mPlayer addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(tolerance, NSEC_PER_SEC) queue:NULL usingBlock:
^(CMTime time)
{
[self syncScrubber];
}] retain];
}
}
if (mRestoreAfterScrubbingRate)
{
[mPlayer setRate:mRestoreAfterScrubbingRate];
mRestoreAfterScrubbingRate = 0.f;
}
}
fonte
2011-10-05 18:06:43
Sapete che questo codice funziona molto meglio al di fuori di quella vista/controller che hanno fatto per me. Non ho provato solo il codice dello scrubber, funziona molto meglio grazie! –
lo proverò. Grazie! – headkit