Skip to content

Commit

Permalink
fix: Play notification now also works with streams
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan van Rooij committed Aug 25, 2019
1 parent 1f980f3 commit fd0e9e7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 18 additions & 2 deletions lib/sonos.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,9 @@ Sonos.prototype.playNotification = async function (options) {
}

const mediaInfo = await this.avTransportService().GetMediaInfo()
debug('Current mediaInfo %j', mediaInfo)
const positionInfo = await this.avTransportService().GetPositionInfo()
debug('Current positionInfo %j', positionInfo)
await this.setAVTransportURI(options)
if (volume > 0) await this.setVolume(options.volume)
const self = this
Expand All @@ -900,8 +902,22 @@ Sonos.prototype.playNotification = async function (options) {
if (volume > 0) await this.setVolume(volume)
if (!wasListening) await Listener.stopListener()
await self.setAVTransportURI({ uri: mediaInfo.CurrentURI, metadata: mediaInfo.CurrentURIMetaData, onlySetUri: true })
if (positionInfo.Track > 0) await self.selectTrack(positionInfo.Track)
await self.avTransportService().Seek({ InstanceID: 0, Unit: 'REL_TIME', Target: positionInfo.RelTime })

// These statements can maybe be improved. See discussion on https://github.com/bencevans/node-sonos/pull/430
if (positionInfo.Track && positionInfo.Track > 1 && mediaInfo.NrTracks > 1) {
debug('Selecting track %j', positionInfo.Track)
await self.selectTrack(positionInfo.Track).catch(reason => {
debug('Reverting back track failed, happens for some muic services.')
})
}

if (positionInfo.RelTime && positionInfo.TrackDuration !== '0:00:00') {
debug('Setting back time to %j', positionInfo.RelTime)
await self.avTransportService().Seek({ InstanceID: 0, Unit: 'REL_TIME', Target: positionInfo.RelTime }).catch(reason => {
debug('Reverting back track time failed, happens for some muic services (radio or stream).')
})
}

if (wasPlaying) await self.play()
return true
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"lint": "standard",
"test": "npm run lint && mocha test/sonos.test.js --exit --timeout 10000",
"test": "npm run lint && mocha test/sonos.test.js --exit --timeout 20000",
"env-run": "npm run $CMD",
"semantic-release": "semantic-release",
"docs": "jsdox -t ./docs/generator/templates --output docs lib/ && jsdox -t ./docs/generator/templates --output docs/services lib/services && jsdox -t ./docs/generator/templates --output docs/events lib/events"
Expand Down

0 comments on commit fd0e9e7

Please sign in to comment.