-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(PPDSC-2047): Resolve gaps in buffering seekbar by refactoring formatTrackData #206
Changes from 2 commits
aea0d56
451ec63
5bf1f7d
82e60e1
53e7a7f
c475dd6
d22d664
57ce414
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,26 +11,47 @@ export const formatTrackData = ( | |
|
||
const time = timeArr[0]; | ||
const bufferPositions = []; | ||
tbradbury marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const closestBuffer = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this should just be a single value not an array? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will take a look There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm adding a single value to an array because it enable me to use the spread operator to add the correct value to the colors array (line 48) and the values array (line 54). If the array is empty I don't need to add a ternary operator to colors or values to ensure they have the right content. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Up to you. I'd prefer using a ternary operator later on but I don't feel strongly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 I've changed it |
||
|
||
const {length} = buffered; | ||
for (let i = 0; i < length; i += 1) { | ||
const startPosition = buffered.start(i); | ||
if (startPosition > time) { | ||
bufferPositions.push(startPosition); | ||
// get all buffer segments | ||
bufferPositions.push({type: 'start', value: buffered.start(i)}); | ||
bufferPositions.push({type: 'end', value: buffered.end(i)}); | ||
} | ||
|
||
if (bufferPositions.length) { | ||
// get closest buffer segment to curser | ||
const closest = bufferPositions.reduce((prev, curr) => | ||
Math.abs(curr.value - time) < Math.abs(prev.value - time) ? curr : prev, | ||
); | ||
// get index of closest buffer in array | ||
const pos = bufferPositions.map(a => a.value).indexOf(closest.value); | ||
|
||
let value; | ||
if (closest.type === 'start') { | ||
// if closest buffer is type start set the next end as value | ||
value = bufferPositions[pos + 1].value; | ||
} | ||
|
||
const endPosition = buffered.end(i); | ||
if (endPosition > time) { | ||
bufferPositions.push(endPosition); | ||
if (closest.type === 'end' && closest.value > time) { | ||
// if closest buffer is type end and greater then current time set as value | ||
value = bufferPositions[pos].value; | ||
} | ||
|
||
if (value) { | ||
// set value for buffer | ||
closestBuffer.push(value); | ||
} | ||
} | ||
|
||
const colors = [ | ||
indicatorColor, | ||
...bufferPositions.map((x, i) => (i % 2 ? trackColor : bufferColor)), | ||
...closestBuffer.map(() => bufferColor), | ||
trackColor, | ||
]; | ||
const values = [time, ...bufferPositions]; | ||
|
||
const values = [time, ...closestBuffer]; | ||
return {colors, values}; | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lil typo
diecided
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤯 I'll sort 👍