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:

1private func setupSeekBar() {
2 seekBar.translatesAutoresizingMaskIntoConstraints = false
3 seekBar.layer.cornerRadius = 3
4 playerView.addSubview(seekBar)
5
6 NSLayoutConstraint.activate([
7 seekBar.leadingAnchor.constraint(equalTo: playerView.leadingAnchor, constant: 16),
8 seekBar.trailingAnchor.constraint(equalTo: playerView.trailingAnchor, constant: -16),
9 seekBar.bottomAnchor.constraint(equalTo: playerView.bottomAnchor, constant: -20),
10 seekBar.heightAnchor.constraint(equalToConstant: 28)
11 ])
12
13 seekBar.onSeekEnd = { [weak self] time in
14 self?.playerViewController.seek(to: time)
15 }
16}

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:

1extension VideoPlayerViewController: FastPixSeekDelegate {
2
3 func onBufferedTimeUpdate(loaded: TimeInterval, duration: TimeInterval) {
4 seekBar.updateBuffer(loaded: loaded, duration: duration)
5 }
6
7 func onTimeUpdate(currentTime: TimeInterval, duration: TimeInterval) {
8 seekBar.updateTime(current: currentTime, duration: duration)
9 }
10
11 func onSeekStart(at time: TimeInterval) {}
12 func onSeekEnd(at time: TimeInterval) {}
13}

What’s next