/h5-audio-controls

Simple h5 music controller

Primary LanguageJavaScriptMIT LicenseMIT

H5 Audio Controls

NPM version David deps devDependencies Status npm download jsdelivr npm license

This package has been deprecated

This package has been migrated to @cycjimmy/h5-audio-controls for scoped NPM package. Please switch to @cycjimmy/h5-audio-controls to stay up to date.

How to use

Install

$ npm install h5-audio-controls --save
# or
$ yarn add h5-audio-controls

Usage

import H5AudioControls from 'h5-audio-controls';
# OR
let H5AudioControls = require('h5-audio-controls');
new H5AudioControls(audioSrc [, options])
  • audioSrc: [string] a url to an audio file

  • The options supports:

    • context: [string|element] the context of audio controller. Default document.body.
    • position: [string] the position of audio controller.
      • Choose one of the four options:
        • 'left-top'
        • 'top-right'(Default)
        • 'right-bottom'
        • 'left-bottom'
    • buttonSize: [string|number] Set button wrapper size. Default ''
    • picSize: [string|number] Set button picture size. Default ''
    • autoPlay: [boolean] Whether to play immediately after loading. Default true
  • H5AudioControls instance supports the following methods:

    • load(): init controller.
    • play(): play the audio.
    • pause(): pause the audio.
    • stop(): stop the audio.

Use in browser

<script src="H5AudioControls.min.js"></script>
<script>
  var audioSrc = '../media/test_audio.mp3';
  new H5AudioControls(audioSrc).load();
</script>

CDN

To use via a CDN include this in your html:

<script src="https://cdn.jsdelivr.net/npm/h5-audio-controls@1/build/H5AudioControls.min.js"></script>