bbcrd/peaks.js — pull request #42 by oncletom (2014-03-26 11:33:08+00:00)
Title: Adding segmented playback

# tl;dr

The goal is to experiment a segmented playback: rather than a continuous playback, the player will play each segments sequentially.

# How it works

We need to expose several APIs such as:

- [x] `peaks.player.playFrom(startPoint, endPoint)` (will always lookup from the beginning of a track)
- [ ] `peaks.player.playSegments()` (will always lookup from the beginning of a track)
- [ ] `peaks.player.playNextSegment()` (will always lookup after the `currentTime`)
- [ ] `peaks.player.playPreviousSegment()`
- [ ] `peaks.player.playSegment(segment_id)`

Considering those sparse and overlapping segments:

- `{ startTime: 10, endTime: 15, id: "first" }`
- `{ startTime: 12, endTime: 18, id: "overlapping" }`
- `{ startTime: 12, endTime: 14, id: "contained" }`
- `{ startTime: 20, endTime: 25, id: "sparse" }`

It will:

1. seek the first segment at 10 seconds
1. pick segment `id:first`
1. add an event to seek the next segment at time 15
1. play segment `id:first` by setting the `currentTime` to 10
1. on `player_time_update` at time 15, seek for the next segment
1. pick segment `id:overlapping`
1. add an event to seek the next segment at time 18
1. because it is continuous, continue playing without changing the `currentTime`
1. on `player_time_update` at time 18, seek for the next segment
1. pick segment `id:sparse`
1. add an event to seek the next segment at time 25
1. play segment `id:sparse` by setting the `currentTime` to 20
1. on `player_time_update` at time 25, seek for the next segment
1. as there is no segment left, stop the playback.

# Why this approach?

- segments can be added and removed during the playback
- it scales as we don't have to keep in memory all the segments data

# Future

- extract the playback mode as strategies (continuous and segmented)
- how are we supposed to behave if we remove the currently played segment? (error, force delete or else?)
- split as static playlist and dynamic playlist (segments are just a way to drive a dynamic playlist)