Awesome
H5 Audio Controls
- Simple h5 music controller Demo
How to use
Install
$ npm install @cycjimmy/h5-audio-controls --save
# or
$ yarn add @cycjimmy/h5-audio-controls
Usage
import h5AudioControls from '@cycjimmy/h5-audio-controls';
# OR
const h5AudioControls = require('@cycjimmy/h5-audio-controls');
h5AudioControls(audioSrc [, options])
-
audioSrc
: [Require][string] a url to an audio file -
The
options
supports:context
: [Option][string|element] the context of audio controller. Defaultdocument.body
.position
: [Option][string] the position of audio controller.- Choose one of the four options:
'left-top'
'top-right'
(Default)'right-bottom'
'left-bottom'
- Choose one of the four options:
positionType
: [Option][string] Set position type of audio controller.- Choose one of the five options:
'fixed'
(Default)'absolute'
'relative'
'sticky'
'static'
- Choose one of the five options:
buttonSize
: [Option][string|number] Set button wrapper size.iconSize
: [Option][string|number] Set button icon size.playIcon
: [Option][string] Set play icon.pauseIcon
: [Option][string] Set pause icon.autoPlay
: [Option][boolean] Whether to play immediately after loading. Defaulttrue
.
-
h5AudioControls
instance supports the following methods:load()
: Init controller.play()
: Play the audio.pause()
: Pause the audio.stop()
: Stop the audio.isPlaying()
: Return whether the audio is playing.changeAudioSrc(src)
: Dynamically modify the value ofaudioSrc
.changePosition(position)
: Dynamically modify the value ofposition
.changeButtonSize(size)
: Dynamically modify the value ofbuttonSize
.changeIconSize(size)
: Dynamically modify the value oficonSize
.change(key, val)
: Dynamically change the value of configuration properties.- Supports the following keys:
'audioSrc'
: Change the value ofaudioSrc
.change('audioSrc', 'yourSrc')
is the same aschangeAudioSrc('yourSrc')
'position'
: Change the value ofposition
.change('position', 'left-top')
is the same aschangePosition('left-top')
'buttonSize'
: Change the value ofbuttonSize
.change('buttonSize', '16vw')
is the same aschangeButtonSize('16vw')
'iconSize'
: Change the value oficonSize
.change('iconSize', '10vw')
is the same aschangeIconSize('10vw')
'playIcon'
: Change the value ofplayIcon
.'pauseIcon'
: Change the value ofpauseIcon
.'autoPlay'
: Change the value ofautoPlay
.
- Supports the following keys:
Use in browser
<script src="h5-audio-controls.umd.min.js"></script>
<script>
var audioSrc = '../media/test_audio.mp3';
h5AudioControls(audioSrc).load();
</script>
CDN
To use via a CDN include this in your html:
<script src="https://cdn.jsdelivr.net/npm/@cycjimmy/h5-audio-controls@5/dist/h5-audio-controls.umd.min.js"></script>
<!-- Links: -->