參考下面的代碼:此代碼是蘋果的示例代碼
AVPlayerDemo
某些部分如果試圖實現一個流媒體播放器,請參閱下面的示例代碼。
StitchedStreamPlayer
也,一個完整的工具準確地擦洗是使用下面的滑塊一樣。 因爲偉大的視頻播放器應該考慮UX。就像你知道運行默認的視頻應用程序當你拖動滑塊時,如果拖動滑塊必須進行微調。
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;
}
}
你知道這段代碼在他們爲我製作的視圖/控制器之外工作得更好。沒有嘗試過洗滌器代碼,謝謝! –
我會嘗試。感謝名單! – headkit