0.0.13 • Published 2 years ago

@deutsche-audio/crbn-player v0.0.13

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
2 years ago

CRBN Core Player

A JavaScript built player which can currently be used for:

  • playing and stopping audio,
  • pausing audio,
  • changing of the track that is currently playing,
  • changing track's volume,
  • going forward and backward

CRBN Player, if provided with an element prop within the options param, can be used with the default UI (to be implemented in the future). If the element prop is not specified, only the functionalities of the Player will be available for use (currently available in the Player package).

Props can be passed to the Player in order to trigger events such as playing and stopping the audio file, changing the stream that is currently being played, changing the track's volume, etc.

Also, CRBN Core Player supports Google Chromecast which can be implemented by adding chromecast prop to the instance of the Player and setting its value to true.

Usage

npm install @deutsche-audio/crbn-player
import Player from "@deutsche-audio/crbn-player";

const player = new Player(options);

Example of Player usage

    const player = new Player({
        html5: true,
        chromecast: true, 
        format: ['webm', 'wav'],
        onplay: () => {
            console.log('Playing');
        },
        onpause: () => {
            console.log('Paused');
        },
        onmetadata: metadata => {
            console.log(metadata, "metadata");
        },
    });

    // ...

    return (

        // ...

        // In order to open Google's extension and select the desired device, Google's button needs to be added
        <google-cast-launcher id="castbutton"></google-cast-launcher>
    
        // ...

        <Button playButton onClick={() => player.play()}>Play</Button>
        <Button onClick={() => player.stop()}>Stop</Button>
        <Button            
            onClick={() => player.changeSrc({
                src: 'https://...',
                title: 'ROCK',
                images: [{url: 'https://...'}]
            })}
        >Rock
        </Button>       
       
        // ...
    
);

Props

PropDescriptionDefault
srcSource of the current track that is playing.-
preloadSet to true to begin downloading the audio file if it is not loaded yet.true
playingSet to true or false to pause or play the media.true
loopSet to true or false to enable/disable loop.false
muteSet to true or false to mute/unmute current audio.false
volumeThe volume of the specific audio, from 0.0 to 1.01.0
rateThe initial playback speed.1
html5Set to true to force HTML5 Audio. This should be used for large audio files so that there isn't a need to wait for the full file to be downloaded and decoded before playing.false
formatSpecify a format in situations where extraction won't work.[]
chromecastEnables Google Chromecast.false
elementOptional. Targets the DOM element that is being specified and attaches the default player to that element. element prop can be provided with the ID of the element or with the element itself.-
onloadCalled when audio is loaded (buffered).noop
onplayCalled when audio starts or resumes playing.noop
onendCalled when media is finished playing.noop
onpauseCalled when audio is paused.noop
onmetadataFor each new song in the livestream, fetches the information (metadata) about the current song playing.noop
onstopCalled when audio is stopped.noop
onvolumechangeCalled when volume is changed.noop
onloaderrorCalled when an error occurs while attempting to load media.noop
onseekCalled when the sound has been seeked. The first parameter is the ID of the sound - onSeek(id).noop

Methods

Method signatureParametersDescription
play(mediaOptions)@param {Object} mediaOptions; Properties that can be paseed to mediaOpstions are src, title, artist, albumName, imagesPlay a song in the player.
changeSrc(mediaOptions)@param {Object} mediaOptions; Properties that can be paseed to mediaOpstions are src, title, artist, albumName, images or @param {Array} srcChange to a specific track.
pause()-Pause the current track.
stop()-Stop the current track.
volume(val)@param {Number} val Volume between 0 and 1.Increase/decrease the volume.
seek(per)@param {Number} per Percentage through the song to skip.Seek to a new position.