1.2.0 • Published 9 months ago

@jsuites/player v1.2.0

Weekly downloads
-
License
-
Repository
github
Last release
9 months ago

Player

jSuites Player is a lightweight JavaScript song player plugin made to facilitate the integration of songs into web application just by providing an array with file sources and information about the songs.

Installation

jSuites Player can be installed by running the command below in your terminal:

npm install @jsuites/player

Integration

To integrate the Player into your web application, ensure you have the following song information available: audio source, image source, title, and author name.

You can then initialize the Player as demonstrated in the code snippet below:

import player from '@jsuites/player';


const p = player(element, {
    // The song information should be inside the data array
    data: [
        { title: 'Mysong', author: 'Me', file: '/songs/my-song.mp3', image: '/images/my-album-cover.jpg' }
    ]
})

// Load the song queue
p.loadSong();

// Show the player and start playing the songs
p.play();

Methods

MethodDescription
showMakes the player_container visible.
hideMakes the player_container invisible.
closeHides the player and resets the audio.
setQueueSets a new value for the queue.
loadSongLoads the song object.
setDataSets the song data.
playTriggers play on the audio.
stopTriggers pause on the audio.
restartResets the current audio time to zero.
nextAdvances to the next song.
previousReturns to the previous song.
setAlbumMusicChanges the state to a specific position in the album.
shuffleRandomizes the order of the songs.
unshuffleRestores the original song order.
setMobileModeActivates the mobile layout.
addSongAdd a song to the end of the queue.
removeSongRemove a song from the given index.

Initialization options

PropertyDescription
data: Song[]The song array containing objects with the following structure: { title, author, file, image }.
eventName: FunctionAny event listed in the table below can be declared inside the initialization options.

Events

MethodDescription
onplayCalled when the song is resumed.
onpauseCalled when the song is paused.
onmuteCalled when the player is muted.
onunmuteCalled when the player is unmuted.
onvolumechangeCalled when the volume changes.
onsongchangeCalled when the song changes.
onopenCalled when the player is displayed.
oncloseCalled when the player is hidden.