Skip to content

Commit

Permalink
Merge 3c429e8 into e144957
Browse files Browse the repository at this point in the history
  • Loading branch information
mrf345 committed Aug 11, 2020
2 parents e144957 + 3c429e8 commit f7985d6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion bin/AudioSequence.min.js

Large diffs are not rendered by default.

24 changes: 10 additions & 14 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
import { thisExpression } from "@babel/types"

export class AudioSequence {
/**
* Utility to ease the process of plying audio elements in sequences.
* @param {object} options contains the module options.
*/
constructor (options = {}) {
const AUTOPLAY_MSG = 'AutoPlay permission is lacking. Enable it then reload:'
const b = (value, defValue) => value === undefined ? defValue : !!value

this.autoplayMessage = options.autoplay_message ?? AUTOPLAY_MSG // message to show if AutoPlay's disabled
this.files = options.files || [] // files inserted will be stored in
this.repeats = options.repeats || 1 // number of repeats to obey with some adjustments later
this.repeatWhole = b(options.repeat_whole, true) // repeat all files as whole
this.repeatEach = b(options.repeat_each, false) // repeat each file for the number of repeats
this.repeatForever = b(options.repeat_forever, false) // to keep repeating endlessly
this.repeatDelay = options.repeat_delay * 1000 || 0 // to add a time delay between each repeat
this.reverseOrder = b(options.reverse_order, false) // to reverse the order list of audio files
this.shuffleOrder = b(options.shuffle_order, false) // to randomly shuffle the order of the files list
this.repeatWhole = options.repeat_whole ?? true // repeat all files as whole
this.repeatEach = options.repeat_each ?? false // repeat each file for the number of repeats
this.repeatForever = options.repeat_forever ?? false // to keep repeating endlessly
this.repeatDelay = (options.repeat_delay * 1000) || 0 // to add a time delay between each repeat
this.reverseOrder = options.reverse_order ?? false // to reverse the order list of audio files
this.shuffleOrder = options.shuffle_order ?? false // to randomly shuffle the order of the files list
this.volume = options.volume || 0.5 // to set the default volume
this.autoStart = b(options.auto_start, false) // to auto load and start playing as the module loads
this.autoplayWarning = b(options.autoplay_warning, true) // to display warning if AutoPlay's disabled
this.autoplayMessage = options.autoplay_message || AUTOPLAY_MSG // message to show if AutoPlay's disabled
this.autoStart = options.auto_start ?? false // to auto load and start playing as the module loads
this.autoplayWarning = options.autoplay_warning ?? true // to display warning if AutoPlay's disabled

this.playlist = [] // stack of audio elements playing
this.current = 0 // index of the currently playing
Expand All @@ -46,7 +42,7 @@ export class AudioSequence {
this.isLast = () => (this.playlist.length - 1) === this.current
this.isFinal = () => {
const lastTrack = (this.playlist.length - 1) === this.current
const lastRepeat = this.getCurrent().item.repeats >= this.repeats
const lastRepeat = this.getCurrent().item.repeats == 0

return lastTrack && (this.repeatEach ? lastRepeat : this.repeatCounter >= this.repeats)
}
Expand Down

0 comments on commit f7985d6

Please sign in to comment.