diff --git a/README.md b/README.md index d119d50..5657ed1 100644 --- a/README.md +++ b/README.md @@ -55,15 +55,40 @@ import upnp from 'upnp-client'; const client = new upnp.UpnpMediaRendererClient('http://192.168.1.50:54380/MediaRenderer_HT-A9.xml'); -// TODO: To be written +const options = { + autoplay: true, + contentType: 'audio/flac', + dlnaFeatures: dlnaContentFeatures, // see below for dlnaHelpers + metadata: { + title: 'My song', + creator: 'My creator', + artist: 'My artist', + album: 'My album', + albumArtURI: 'http://127.0.0.1/albumArtURI.jpg', + type: 'audio' + } +}; -await client.play(); +await client.load('http://127.0.0.1/music.flac', options); + +await client.loadNext('http://127.0.0.1/next-music.flac', options); await client.pause(); +await client.play(); + await client.stop(); +await client.next(); + +await client.previous(); + await client.seek(60); + +// you can also call any AVTransport action supported by your device +const response = await client.callAVTransport('YourCustomAVTransportCall', { + InstanceID: client.instanceId +}); ``` ## Usage of dlnaHelpers @@ -77,6 +102,24 @@ const dlnaContentFeatures = `${upnp.dlnaHelpers.defaultFlags.DLNA_STREAMING_TIME_BASED_FLAGS}`; ``` +## Tips and tricks + +In the metadata you're passing to your speaker, make sure to avoid using accents and special characters. + +Here is a simple helper you could use: + +```ts +const escapeSpecialChars = (value: string) => { + return value + .normalize('NFD') + .replace(/[\u0300-\u036f]/g, '') // remove all accents from characters + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/’/g, "'"); +}; +``` + ## Debugging Run with debug traces diff --git a/src/index.ts b/src/index.ts index 7e8166c..0c969c6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ export { UpnpDeviceClient } from './deviceClient'; export { UpnpMediaRendererClient } from './mediarendererClient'; export { dlnaHelpers } from './utils/dlna'; +export { formatTime, parseTime } from './utils/time'; export * from './types'; diff --git a/src/mediarendererClient.ts b/src/mediarendererClient.ts index a2901ce..47e900e 100644 --- a/src/mediarendererClient.ts +++ b/src/mediarendererClient.ts @@ -109,8 +109,11 @@ export class UpnpMediaRendererClient extends UpnpDeviceClient { InstanceID: this.instanceId }); - const strTime = response.AbsTime !== 'NOT_IMPLEMENTED' ? response.AbsTime : response.RelTime; - return parseTime(strTime); + return parseTime(response.RelCount); + }; + + getPositionInfo = (): Promise => { + return this.callAVTransport('GetPositionInfo', { InstanceID: this.instanceId }); }; getDuration = async (): Promise => { @@ -189,6 +192,16 @@ export class UpnpMediaRendererClient extends UpnpDeviceClient { await this.callAVTransport('Stop', params); }; + next = async () => { + const params = { InstanceID: this.instanceId }; + await this.callAVTransport('Next', params); + }; + + previous = async () => { + const params = { InstanceID: this.instanceId }; + await this.callAVTransport('Previous', params); + }; + seek = (seconds: number): Promise => { const params = { InstanceID: this.instanceId,