npm i --save nativescript-sonos
- 版本:0.5.1
- GitHub: https://github.com/toddanglin/nativescript-sonos
- NPM: https://npmjs.net.cn/package/nativescript-sonos
- 下载
- 昨天: 0
- 上周: 0
- 上个月: 0
NativeScript Sonos 插件(WIP)
此插件提供了一种从 NativeScript 应用程序控制本地网络上的 Sonos 系统的接口。它受到由 Ben Evans 创建的 NodeJS Sonos 库 的影响。
这是一个不完整的、正在进行的插件。请相应使用。
运行演示
在克隆此存储库后,在您的终端中导航到存储库文件夹并运行此命令
$ npm run demo.ios
这将构建插件的最新版本,将其添加到演示项目,并在模拟器中启动演示。
注意:此演示仅在 iOS 上进行了测试,但插件应该可以在 iOS 和 Android 上使用。
如何使用此插件?
从终端将插件添加到 NativeScript 应用程序
$ tns plugin add nativescript-sonos
在您的应用程序中,使用有效的 Sonos IP 地址初始化插件
import { Sonos } from "nativescript-sonos"
let sonos = new Sonos("10.0.1.188"); //Replace with your Sonos IP address
您现在可以调用方法来控制 Sonos 播放器。与原始 NodeJS 库不同,此插件对所有异步方法都使用 Promise。例如,要播放
this.sonos.play()
.then(() => {
// Command to play completed successfully
})
.catch((err) => {
// Something went wrong; handle the error state
});
支持的操作
此插件尚未支持来自 原始 NodeJS 库 的所有方法。目前实现的方法是
- currentTrack: () => Promise;
- selectTrack: (trackNr?: number) => Promise
; - getVolume: () => Promise
; - setVolume: (volume: number) => Promise
; - getMuted: () => Promise
; - setMuted: (muted: boolean) => Promise
; - play: (uri?: string | UriObject) => Promise
; - stop: () => Promise
; - pause: () => Promise
; - seek: (seconds: number) => Promise
; - next: () => Promise
; - previous: () => Promise
; - flush: () => Promise
; - becomeCoordinatorOfStandaloneGroup: () => Promise
; - setName: (name: any) => Promise
; - setPlayMode: (playmode: PlayModeEnum) => Promise
; - selectQueue: () => Promise
; - queue: (uri: string | UriObject, positionInQueue?: number) => Promise
; - getCurrentState: () => Promise
; - getZoneInfo: () => Promise
; - getZoneAttrs: () => Promise
; - getZoneGroupState: () => Promise
; - getLEDState: () => Promise
; - setLEDState: (setStateOn: boolean) => Promise
; - getTopology: () => Promise
; - getZonesWithDescriptions: () => Promise
; - deviceDescription: (host?: string, port?: number) => Promise
; - getQueue: () => Promise
; - getMusicLibrary: (searchType: SonosSearchType, startIndex?: number, pageSize?: number) => Promise
; - searchMusicLibrary: (searchType: SonosSearchType, searchTerm: string, startIndex?: number, pageSize?: number) => Promise
; - getFavoritesRadioStations: (startIndex?: number, pageSize?: number) => Promise
; - getFavoritesRadioShows: (startIndex?: number, pageSize?: number) => Promise
; - getFavoritesRadio: (favoriteRadioType: any, startIndex?: number, pageSize?: number) => Promise
; - playTuneinRadio: (stationId: any, stationTitle: any) => Promise
; - addSpotify: (trackId: any) => Promise
; - playSpotifyRadio: (artistId: any, artistName: any) => Promise
; - addSpotifyQueue: (trackId: any) => Promise
;
Sonos 设备发现 API
由于 NativeScript 对 UDP 套接字连接不支持,此插件尚未支持发现 API(允许您自动定位网络上的 Sonos 设备)。
当UDP套接字连接变得可能时,在NativeScript中应该可以实现发现API。
欢迎贡献。😄
下一步是什么?
此插件将公开NodeJS库中的附加Sonos API。如果您需要尚未公开的API,请创建一个问题,我们将尝试将其优先处理。
欢迎贡献和建设性反馈。
许可证
MIT。使用它,转换它,随便你怎么用。