Skip to content

Commit

Permalink
Improve error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
bhj committed Feb 19, 2021
1 parent 7c75903 commit 488b58e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,15 @@ class CDGPlayer {
}

load (buffer) {
if (!(buffer instanceof ArrayBuffer)) throw new Error('load() expects an ArrayBuffer')

this.forceKey = null
this.parser = new CDGParser(buffer)
}

render (time, opts = {}) {
if (isNaN(time) || time < 0) {
throw new Error(`Invalid time: ${time}`)
}
if (!this.parser) throw new Error('load() must be called before render()')
if (isNaN(time) || time < 0) throw new Error(`Invalid time: ${time}`)

const instructions = this.parser.parseThrough(time)
const isChanged = !!instructions.length || !!instructions.isRestarting || opts.forceKey !== this.forceKey
Expand Down

0 comments on commit 488b58e

Please sign in to comment.