Front-End utility to ease the process of plying audio elements in sequences.
MPL-2.0 License
npm i audio_sequence --save
// ES5
const AudioSequence = require('audio_sequence').default
// ES6
import AudioSequence from 'audio_sequence'
<script src="https://mrf345.github.io/audio_sequence/bin/AudioSequence.min.js"></script>
<script>
var Player = new AudioSequence()
</script>
Should work with anything newer than Internet Explorer 10
and NodeJS 10
.
var Player = new AudioSequence(
/**
* Utility to help import html templates and parse them minimally.
* @param {object} options contains the module options.
*
*`options` = {
* files: [], // files to store and play
* repeats: 1, // number of repeats
* repeat_whole: true, // repeat all files as whole
* repeat_each: false, // repeat each file for the number of repeats
* repeat_forever: false, // to keep repeating endlessly
* repeat_delay: 0, // to add a time delay between each repeat
* reverse_order: false, // to reverse the order list of audio files
* shuffle_order: false, // to randomly shuffle the order of the files list
* volume: 0.5, // to set the default volume
* auto_start: false, // to auto load and start playing as the module loads
* autoplay_warning: true, // to display warning if AutoPlay's disabled
* autoplay_message: 'message' // message to show if AutoPlay's disabled
*
* NOTE: if both `repeat_each` and `repeat_whole` are `true`. In any case
* `repeat_each` will always take precedence.
* }
*/
)
// if the default options work for you out-of-the-box. this should load it:
Player.load()
.then(function(audios) { console.log(audios) })
.catch(function(error) { console.warn(error) })
AutoPlay
policy notification: notify the user with an overlay instructions to how to enable AutoPlay
.List of typical music player like methods:
Method | Input | Output | Description |
---|---|---|---|
.play(file = '') |
file : audio file's link. |
boolean |
to start playing the added audio files. |
.playAfter(files = []) |
files : array of files to play. |
N/A | play files after the ongoing playlist sequence is done. |
.replay() |
N/A | boolean |
restart playing the current audio file. |
.stop() |
N/A | boolean |
stop playing all added audio files. |
.pause() |
N/A | boolean |
pause the currently playing audio. |
.next() |
N/A | boolean |
play the next file in the playlist. |
.previous() |
N/A | boolean |
play the previous file in the playlist. |
.forward(seconds = 0) |
seconds : number of seconds to forward with. |
boolean |
forward the currently playing audio. |
.backward(seconds = 0) |
seconds : number of seconds to backward with. |
boolean |
backward the currently playing audio. |
.mute() |
N/A | boolean |
mute all audio files. |
.unmute(volume = 0.5) |
volume : volume to unmute with. |
boolean |
unmute all audio files. |
.each() |
N/A | N/A | activate repeat each file for the number of Player.repeats mode. |
.whole() |
N/A | N/A | activate repeat the whole playlist for the number of Player.repeats mode. |
.forever() |
N/A | N/A | activate forever mode to disregard Player.repeats and repeat forever. |
.add(file = '') |
file : audio file's link. |
Promise() |
load and add file to the playlist. |
.remove(file = '') |
file : audio file's link. |
boolean |
remove file from the playlist. |
.load() |
N/A | Promise() |
to load Player.files manually with a Promise that resolves when all files are loaded. |
.doAfter() |
todo : function to call when playlist sequence is finished. |
N/A | add a function to list of functions to execute after playlist sequence is finished. |
There's a bit old and dated live example,
that was created when JQuery
was a requirement "no longer it is". But it still works and serves the purpose.
Replaying the playlist sequence:
If you want to replay the whole playlist sequence rather than replaying the last audio file with .replay()
.
You'll have to run Player.load().then(function() { Player.play() })
or you can automate that with setting autoStart
option to true
.
Player.autoStart = true
Player.load() // will replay automatically as soon as the tracks are loaded.
npm test
npm run format
npm run push
./pages.sh