Skip to navigation

Add a custom seek bar

Learn how to add a custom seek bar to your FastPix iOS Player using FastPixSeekBar and FastPixSeekManager.

Add the seek bar

Create and position a FastPixSeekBar in your player view. Connect its onSeekEnd handler to the player’s seek method:

private func setupSeekBar() {
seekBar.translatesAutoresizingMaskIntoConstraints = false
seekBar.layer.cornerRadius = 3
playerView.addSubview(seekBar)
NSLayoutConstraint.activate([
seekBar.leadingAnchor.constraint(equalTo: playerView.leadingAnchor, constant: 16),
seekBar.trailingAnchor.constraint(equalTo: playerView.trailingAnchor, constant: -16),
seekBar.bottomAnchor.constraint(equalTo: playerView.bottomAnchor, constant: -20),
seekBar.heightAnchor.constraint(equalToConstant: 28)
])
seekBar.onSeekEnd = { [weak self] time in
self?.playerViewController.seek(to: time)
}
}

Implement the seek delegate

Conform to FastPixSeekDelegate to receive real-time updates for buffered time and current playback position. Use these callbacks to keep the seek bar in sync with the player:

extension VideoPlayerViewController: FastPixSeekDelegate {
func onBufferedTimeUpdate(loaded: TimeInterval, duration: TimeInterval) {
seekBar.updateBuffer(loaded: loaded, duration: duration)
}
func onTimeUpdate(currentTime: TimeInterval, duration: TimeInterval) {
seekBar.updateTime(current: currentTime, duration: duration)
}
func onSeekStart(at time: TimeInterval) {}
func onSeekEnd(at time: TimeInterval) {}
}

What’s next