Skip to main content
Version: v3

MUSIC

Creating Sensors

const music = hmSensor.createSensor(hmSensor.id.MUSIC)

MUSIC instance

music: object

PropertiesDescriptionType
artistartist namestring
titlemusic namestring
isPlayingPlay status true: playing, false: not playingboolean

music.audInit()

Initialize music controls

Type

() => void

music.audPlay()

Play

Type

() => void

music.audPause()

Pause

Type

() => void

music.audPrev()

Previous

Type

() => void

music.audNext()

Next

Type

() => void

Registering sensor instance callback events

music.addEventListener(event, callback: Callback)

The events of CHANGE

The value of event

hmSensor.event.CHANGE

Callback

() => void

The example of events

music.addEventListener(hmSensor.event.CHANGE, function () {
console.log("The current song's name: " + music.title + '\r\n')
})

Code example

const music = hmSensor.createSensor(hmSensor.id.MUSIC)

music.audInit()
music.audPlay()
music.audPause()
music.audPrev()
music.audNext()

console.log('The artist of song: ' + music.artist)
console.log('The name of song: ' + music.title)