diff --git a/FA/Entertainment/DistrubutedMusicPlayer/README.md b/FA/Entertainment/DistrubutedMusicPlayer/README.md index 4f287d821b0a1dac2cf472e4213d7353b618fa82..cee7b3f5bd3639782945891c454a53dcb5568d49 100644 --- a/FA/Entertainment/DistrubutedMusicPlayer/README.md +++ b/FA/Entertainment/DistrubutedMusicPlayer/README.md @@ -22,7 +22,7 @@ **步骤三:** 使用DevEco Studio 3.0 +打开当前应用,配置签名,烧录开发板。 - **PS**注意更改config.json,以及MyPlayerConstants.ets的包名为自己的包名 + **PS**注意更改config.json的包名为自己的包名 **步骤四:** 分布式流转流转时,需要多个开发板,连接同一个wifi或使用网线连接 @@ -41,7 +41,6 @@ │   ├──DeviceListDialog.ets //设备列表自定义弹窗组件 │   ├──MusicListDialog.ets //音乐列表自定义弹窗组件 │   ├──CommonLog.ets // 日志管理类 -│   ├──MyPlayerConstants.ets // 常量类 │   ├──PlayerManager.ets //音乐播放管理类 │   ├──RemoteDeviceManager.ets //设备管理类,用于发现设备,认证设备 │   ├── MainAbility @@ -51,7 +50,7 @@ ``` 2. **安装方法** ``` -hdc_std install -r D:\本地绝对路径\my-open-harmony-player\entry\build\outputs\hap\debug\entry-debug-standard-ark-signed.hap +hdc_std kill && hdc_std install -r D:\本地绝对路径\my-open-harmony-player\entry\build\outputs\hap\debug\entry-debug-standard-ark-signed.hap ``` 3. **日志查看方法** ``` @@ -66,8 +65,7 @@ hilog | grep MyOpenHarmonyPlayer 5.**参考资料** - [OpenHarmony JS开发参考](https://gitee.com/openharmony/docs/tree/master/zh-cn/application-dev/js-reference) - - [OpenHarmony FeatureAbility模块](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/js-reference/apis/js-apis-featureAbility.md) - +- [OpenHarmony js自定义弹窗](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/js-reference/ts-based-declarative-development-paradigm/ts-methods-custom-dialog-box.md) - [OpenHarmony js 分布式播放器Sample](https://gitee.com/openharmony/app_samples/tree/master/ability/JsDistributedMusicPlayer) diff --git a/FA/Entertainment/DistrubutedMusicPlayer/entry/src/main/ets/Common/CommonLog.ets b/FA/Entertainment/DistrubutedMusicPlayer/entry/src/main/ets/Common/CommonLog.ets index a753f7b22876f8a60d81dbadf740e1c8b1ea66de..d0a9cf6bb1703d310baa24f638982c52f4441098 100644 --- a/FA/Entertainment/DistrubutedMusicPlayer/entry/src/main/ets/Common/CommonLog.ets +++ b/FA/Entertainment/DistrubutedMusicPlayer/entry/src/main/ets/Common/CommonLog.ets @@ -16,7 +16,7 @@ /** * 日志管理类 */ -export class CommonLog { +export default class CommonLog { static module: string = "MyOpenHarmonyPlayer" static info(log: string) { diff --git a/FA/Entertainment/DistrubutedMusicPlayer/entry/src/main/ets/Common/PlayerManager.ets b/FA/Entertainment/DistrubutedMusicPlayer/entry/src/main/ets/Common/PlayerManager.ets index 545fff6d7226568a9121304c5ae4f737ad712719..0fb49cadb2fb581316575e12e55d6b8ecac157fc 100644 --- a/FA/Entertainment/DistrubutedMusicPlayer/entry/src/main/ets/Common/PlayerManager.ets +++ b/FA/Entertainment/DistrubutedMusicPlayer/entry/src/main/ets/Common/PlayerManager.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import {CommonLog} from "./CommonLog" +import CommonLog from "./CommonLog" import media from '@ohos.multimedia.media' /** diff --git a/FA/Entertainment/DistrubutedMusicPlayer/entry/src/main/ets/Common/RemoteDeviceManager.ets b/FA/Entertainment/DistrubutedMusicPlayer/entry/src/main/ets/Common/RemoteDeviceManager.ets index cdf4c1be22d83ba74f2b834f1b29f910f04a9892..220cd2fefe5036a0d0e6d6fc271e029d6aee72af 100644 --- a/FA/Entertainment/DistrubutedMusicPlayer/entry/src/main/ets/Common/RemoteDeviceManager.ets +++ b/FA/Entertainment/DistrubutedMusicPlayer/entry/src/main/ets/Common/RemoteDeviceManager.ets @@ -12,246 +12,280 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {CommonLog} from "./CommonLog" -import {MyPlayerConstants} from "./MyPlayerConstants" + +import CommonLog from "./CommonLog" import deviceManager from '@ohos.distributedHardware.deviceManager' +import prompt from '@system.prompt'; +import featureAbility from '@ohos.ability.featureAbility'; -let SUBSCRIBE_ID = 100 +// 以下不能为空 +const APP_NAME = "MyOpenHarmonyPlayer" +const APP_DESCRIPTION = "MyOpenHarmonyPlayer" /** * 设备对象 */ export class RemoteDevice { - deviceId: string - deviceName: string - deviceType: number - status: RemoteDeviceStatus = RemoteDeviceStatus.UNTRUSTED + deviceId: string + deviceName: string + deviceType: number + status: RemoteDeviceStatus = RemoteDeviceStatus.UNTRUSTED - constructor(deviceId: string, deviceName: string, - deviceType: number, status?: RemoteDeviceStatus) { - this.deviceId = deviceId - this.deviceName = deviceName - this.deviceType = deviceType - if (status == undefined || status == null) { - this.status = RemoteDeviceStatus.UNTRUSTED - } else { - this.status = status - } - } + constructor(deviceId: string, deviceName: string, + deviceType: number, status?: RemoteDeviceStatus) { + this.deviceId = deviceId + this.deviceName = deviceName + this.deviceType = deviceType + if (status == undefined || status == null) { + this.status = RemoteDeviceStatus.UNTRUSTED + } else { + this.status = status + } + } } -export class RemoteOnlineDevice extends RemoteDevice { - constructor(deviceId: string, deviceName: string, - deviceType: number) { - super(deviceId, deviceName, deviceType, RemoteDeviceStatus.ONLINE); - } +export enum RemoteDeviceStatus { + OFFLINE = 0, + ONLINE = 2, + UNTRUSTED = -1 } -export enum RemoteDeviceStatus { - OFFLINE = 0, - ONLINE = 2, - UNTRUSTED = -1 +export function getBundleName(): Promise { + return featureAbility.getContext().getBundleName() } + /** * 设备管理类,用于发现设备,认证设备 */ export class RemoteDeviceManager { - private deviceList: Array = [] - private dmInstance //: deviceManager.DeviceManager + private deviceList: RemoteDevice[] = [] + private dmInstance = null + private bundleName = "" + private subscribeId:number = 1000 - constructor(deviceList: RemoteDevice[]) { - this.deviceList = deviceList - } + /** + * 构造函数,传入@State 或者 @Provide 装饰的设备列表数据 + * 不能对deviceList进行重新赋值,否则将不能动态更新视图 + */ + constructor(deviceList: RemoteDevice[]) { + this.deviceList = deviceList + // 使用相同的Id,若之前没有正常停止会导致第二次不能正常发现设备 + this.subscribeId = Math.floor(65536 * Math.random()); + } - /** - * 初始化,创建deviceManager对象,返回Promise对象 - */ - init() { - return new Promise((resolve, reject) => { - try { - if (!this.dmInstance) { - CommonLog.info('deviceManager.createDeviceManager begin'); - deviceManager.createDeviceManager(MyPlayerConstants.BUNDLE_NAME, (error, value) => { - if (error) { - CommonLog.error('deviceManager.createDeviceManager failed:' + error); - reject(error) - return - } - this.dmInstance = value - resolve(this.dmInstance) - CommonLog.info('deviceManager.createDeviceManager success') - }) - } else { - resolve(this.dmInstance) - } - } - catch (error) { - reject(error) - } - }) - } + /** + * 初始化,创建deviceManager对象,返回Promise对象 + */ + async init(): Promise { + if (!this.bundleName) { + this.bundleName = await getBundleName() + CommonLog.info('getBundleName:' + this.bundleName); + } + return new Promise((resolve, reject) => { + try { + if (!this.dmInstance) { + CommonLog.info('deviceManager.createDeviceManager begin'); + deviceManager.createDeviceManager(this.bundleName, (error, value) => { + if (error) { + CommonLog.error('deviceManager.createDeviceManager failed:' + error); + reject(error) + return + } + this.dmInstance = value + CommonLog.info('deviceManager.createDeviceManager success') + resolve(this.dmInstance) + }) + } else { + CommonLog.info('dmInstance already exists') + resolve(this.dmInstance) + } + } + catch (error) { + prompt.showToast({ message: "createDeviceManager fail :" + error }) + CommonLog.error('init fail ' + JSON.stringify(error)) + reject(error) + } + }) + } - /** + /** * 刷新设备列表 */ - refreshRemoteDeviceList() { - CommonLog.info("refreshRemoteDeviceList") - let list = this.dmInstance.getTrustedDeviceListSync() - if (typeof (list) != 'undefined' && list.length != 0) { - for (let remoteDevice of list) { - // 重启设备后,deviceID还会变化,,devicename好像没变 - let devices = this.deviceList.filter(device => device.deviceName == remoteDevice.deviceName) - if (devices.length == 0) { - let newDevice = { - deviceId: remoteDevice.deviceId, - deviceName: remoteDevice.deviceName, - deviceType: remoteDevice.deviceType, - status: RemoteDeviceStatus.ONLINE - } - this.deviceList.push(newDevice) - CommonLog.info('Add new trust device:deviceName=' + remoteDevice.deviceName + ' deviceId=' + remoteDevice.deviceId) - } else { - let device = devices[0] - device.deviceId = remoteDevice.deviceId // update deviceId - } - } - } - } + async refreshRemoteDeviceList() { + CommonLog.info("refreshRemoteDeviceList") + this.init().then(() => { + CommonLog.info("refreshRemoteDeviceList start") + let list = this.dmInstance.getTrustedDeviceListSync() + CommonLog.info('getTrustedDeviceListSync = ' + JSON.stringify(list)); + if (typeof (list) != 'undefined' && list.length != 0) { + for (let remoteDevice of list) { + // deviceName刷机后不改变,删除名字相同项目 + for (let i = this.deviceList.length - 1;i >= 0; i--) { + if (this.deviceList[i].deviceName == remoteDevice.deviceName) { + this.deviceList.splice(i, 1); + } + } + CommonLog.info("refreshRemoteDeviceList update deviceName:" + remoteDevice.deviceName) + remoteDevice.status = RemoteDeviceStatus.ONLINE + // 更新最新的设备信息 + this.deviceList.push(remoteDevice); + } + } + }) + } - /** + /** + * 强制更新deviceList UI视图 + */ + forcedUpdateList(){ + this.deviceList.push(new RemoteDevice("update","update",1,RemoteDeviceStatus.UNTRUSTED)) + this.deviceList.pop() + } + + /** * 认证设备 * @param remoteDevice 远程设备 */ - authDevice(remoteDevice: RemoteDevice) { - CommonLog.info("authDevice:deviceName=" + remoteDevice.deviceName + " deviceId=" + remoteDevice.deviceId) - return new Promise((resolve, reject) => { - // 认证 - let extraInfo = { - "targetPkgName": MyPlayerConstants.BUNDLE_NAME, - "appName": 'My openharmony player', - "appDescription": 'My openharmony player', - "business": '0' - }; - let authParam = { - "authType": 1, - "appIcon": '', - "appThumbnail": '', - "extraInfo": extraInfo - } - - this.dmInstance.authenticateDevice(remoteDevice, authParam, (err, data) => { - if (err) { - CommonLog.info(' authenticateDevice failed, err=' + JSON.stringify(err)) - reject("fail") // 认证失败 - } else { - CommonLog.info(' authenticateDevice succeed, data=' + JSON.stringify(data)) - resolve("success") // 认证成功 - } - }) - }) - } + async authDevice(remoteDevice: RemoteDevice) { + CommonLog.info("authDevice:deviceName=" + remoteDevice.deviceName + " deviceId=" + remoteDevice.deviceId) + await this.init() + return new Promise((resolve, reject) => { + if (remoteDevice.status != RemoteDeviceStatus.UNTRUSTED) { + CommonLog.info("authDevice:device already certified") + resolve("Already certified") + } + // 认证 + let extraInfo = { + "targetPkgName": this.bundleName, + "appName": APP_NAME, + "appDescription": APP_DESCRIPTION, + "business": '0' + }; + let authParam = { + "authType": 1, + "appIcon": '', + "appThumbnail": '', + "extraInfo": extraInfo + } + CommonLog.info("authDevice:start") + this.dmInstance.authenticateDevice(remoteDevice, authParam, (err, data) => { + if (err) { + CommonLog.info(' authenticateDevice failed, err=' + JSON.stringify(err)) + prompt.showToast({message:'authenticateDevice failed, err=' + JSON.stringify(err)}) + reject("fail") // 认证失败 + } else { + CommonLog.info('authenticateDevice succeed, data=' + JSON.stringify(data)) + resolve("success") // 认证成功 + } + }) + CommonLog.info("authDevice:end") + }) + } - /** + /** * 启动发现设备 */ - startDeviceDiscovery() { - CommonLog.info("startDeviceDiscovery") - - this.init().then(() => { - this.dmInstance.on('deviceStateChange', (data) => { - CommonLog.info('deviceStateChange data=' + JSON.stringify(data)); - switch (data.action) { - // ONLINE - case 0: - CommonLog.info('ONLINE a device !') - for (let i = 0; i < this.deviceList.length; i++) { - if (this.deviceList[i].deviceName == data.device.deviceName) { - this.deviceList[i].deviceId = data.device.deviceId - this.deviceList[i].status = RemoteDeviceStatus.ONLINE - CommonLog.info('Update a online device: ' + JSON.stringify(data.device)) - return - } - } - let newDevice = { - deviceId: data.device.deviceId, - deviceName: data.device.deviceName, - deviceType: data.device.deviceType, - status: RemoteDeviceStatus.ONLINE - } - CommonLog.info('Found a new online device: deviceName=' + JSON.stringify(newDevice)) - this.deviceList.push(newDevice); - break; - // OFFLINE - case 2: - CommonLog.info('OFFLINE a device !') - for (let i = 0; i < this.deviceList.length; i++) { - if (this.deviceList[i].deviceName == data.device.deviceName) { - CommonLog.info('Delete a offline device: deviceName=' + this.deviceList[i].deviceName) - this.deviceList.splice(i, 1) // 删除当前设备 - return - } - } - CommonLog.info('Not found this offline device in deviceList: ' + data.device.deviceName) - break; - // READY - case 1: - CommonLog.info('READY,but how to deal?') - break; - default: - break; - } - }) - - - this.dmInstance.on('deviceFound', (data) => { - for (let i = 0; i < this.deviceList.length; i++) { - if (this.deviceList[i].deviceName == data.device.deviceName) { - this.deviceList[i].deviceId = data.device.deviceId - CommonLog.info('deviceFound device founded in deviceList, update deviceId'); - return; - } - } - let newDevice = { - deviceId: data.device.deviceId, - deviceName: data.device.deviceName, - deviceType: data.device.deviceType, - status: RemoteDeviceStatus.UNTRUSTED - } - CommonLog.info('Found new device: ' + JSON.stringify(newDevice)) - this.deviceList.push(newDevice); - }); - this.dmInstance.on('discoverFail', (data) => { - CommonLog.error(' discoverFail data=' + JSON.stringify(data)) - }); - this.dmInstance.on('serviceDie', () => { - CommonLog.error(' serviceDie') - }); + startDeviceDiscovery() { + CommonLog.info("startDeviceDiscovery") + this.init().then(() => { + this.dmInstance.on('deviceStateChange', (data) => { + CommonLog.info('deviceStateChange data=' + JSON.stringify(data)); + switch (data.action) { + // ONLINE + case 0: + CommonLog.info('ONLINE a device ! deviceInfo=' + JSON.stringify(data.device)) + for (let i = 0; i < this.deviceList.length; i++) { + if (this.deviceList[i].deviceName == data.device.deviceName) { + // 无法检测到深层数据变化,需要将对象拷贝重新赋值 + let device = Object.assign(this.deviceList[i],{}) as RemoteDevice + device.status = RemoteDeviceStatus.ONLINE + device.deviceId = data.device.deviceId + this.deviceList[i] = device + CommonLog.info('Update a online device: ' + JSON.stringify(device)) + this.forcedUpdateList() + return + } + } + let newDevice = { + deviceId: data.device.deviceId, + deviceName: data.device.deviceName, + deviceType: data.device.deviceType, + status: RemoteDeviceStatus.ONLINE + } + CommonLog.info('Found a new online device: deviceName=' + JSON.stringify(newDevice)) + this.deviceList.push(newDevice); + break; + // OFFLINE + case 2: + CommonLog.info('OFFLINE a device !') + for (let i = 0; i < this.deviceList.length; i++) { + if (this.deviceList[i].deviceName == data.device.deviceName) { + CommonLog.info('Delete a offline device: deviceName=' + this.deviceList[i].deviceName) + this.deviceList.splice(i, 1) // 删除当前设备 + return + } + } + CommonLog.info('Not found this offline device in deviceList: ' + data.device.deviceName) + break; + // READY + case 1: + CommonLog.info('READY') + break; + default: + break; + } + }) + this.dmInstance.on('deviceFound', (data) => { + CommonLog.info('deviceFound deviceName = ' + data.device.deviceName) + for (let i = 0; i < this.deviceList.length; i++) { + if (this.deviceList[i].deviceName == data.device.deviceName) { + this.deviceList[i].deviceId = data.device.deviceId + CommonLog.info('deviceFound device founded in deviceList, update deviceId'); + return; + } + } + let newDevice = { + deviceId: data.device.deviceId, + deviceName: data.device.deviceName, + deviceType: data.device.deviceType, + status: RemoteDeviceStatus.UNTRUSTED + } + CommonLog.info('Found new device: ' + JSON.stringify(newDevice)) + this.deviceList.push(newDevice); + }); + this.dmInstance.on('discoverFail', (data) => { + CommonLog.error(' discoverFail data=' + JSON.stringify(data)) + }); + this.dmInstance.on('serviceDie', () => { + CommonLog.error(' serviceDie') + }); - let info = { - subscribeId: SUBSCRIBE_ID, - mode: 0xAA, - medium: 2, - freq: 2, - isSameAccount: false, - isWakeRemote: true, - capability: 0 - }; - this.dmInstance.startDeviceDiscovery(info) - }) - } + let info = { + subscribeId: this.subscribeId, + mode: 0xAA, + medium: 2, + freq: 2, + isSameAccount: false, + isWakeRemote: true, + capability: 0 + }; + this.dmInstance.startDeviceDiscovery(info); + CommonLog.info("startDeviceDiscovery end") + }) + } - /** + /** * 停止发现设备 */ - stopDeviceDiscovery() { - CommonLog.info('stopDeviceDiscovery ' + SUBSCRIBE_ID); - this.dmInstance.stopDeviceDiscovery(SUBSCRIBE_ID); - this.dmInstance.off('deviceStateChange'); - this.dmInstance.off('deviceFound'); - this.dmInstance.off('discoverFail'); - this.dmInstance.off('serviceDie'); - this.deviceList = []; - } + stopDeviceDiscovery() { + CommonLog.info('stopDeviceDiscovery ' + this.subscribeId); + this.dmInstance.stopDeviceDiscovery(this.subscribeId); + this.dmInstance.off('deviceStateChange'); + this.dmInstance.off('deviceFound'); + this.dmInstance.off('discoverFail'); + this.dmInstance.off('serviceDie'); + // this.deviceList = []; + } } diff --git a/FA/Entertainment/DistrubutedMusicPlayer/entry/src/main/ets/Common/components/DeviceListDialog.ets b/FA/Entertainment/DistrubutedMusicPlayer/entry/src/main/ets/Common/components/DeviceListDialog.ets index 9b9a0338544e6c232e67d7d42e32e86048284523..e5ad3945ac40c5918bfb4dbc45e6dc58cbd71c4c 100644 --- a/FA/Entertainment/DistrubutedMusicPlayer/entry/src/main/ets/Common/components/DeviceListDialog.ets +++ b/FA/Entertainment/DistrubutedMusicPlayer/entry/src/main/ets/Common/components/DeviceListDialog.ets @@ -19,7 +19,7 @@ import {RemoteDevice} from "../RemoteDeviceManager" */ @CustomDialog export struct DeviceListDialog { - @State deviceList: Array = [] + @State deviceList: RemoteDevice[] = [] private controller: CustomDialogController private cancel: () => void private confirm: (deviceName: string) => void diff --git a/FA/Entertainment/DistrubutedMusicPlayer/entry/src/main/ets/MainAbility/pages/index.ets b/FA/Entertainment/DistrubutedMusicPlayer/entry/src/main/ets/MainAbility/pages/index.ets index 957d2f289bd448d7ccd1e0965b935a8534bf03d2..c27ac0a61eb085209f7c6aee1cf0ae7c3dc94aa4 100644 --- a/FA/Entertainment/DistrubutedMusicPlayer/entry/src/main/ets/MainAbility/pages/index.ets +++ b/FA/Entertainment/DistrubutedMusicPlayer/entry/src/main/ets/MainAbility/pages/index.ets @@ -13,11 +13,10 @@ * limitations under the License. */ import {PlayerManager, Music} from "../../Common/PlayerManager" -import {RemoteDeviceManager, RemoteDevice, RemoteDeviceStatus} from "../../Common/RemoteDeviceManager" -import {CommonLog} from "../../Common/CommonLog" +import {RemoteDeviceManager, RemoteDevice, RemoteDeviceStatus,getBundleName} from "../../Common/RemoteDeviceManager" +import CommonLog from "../../Common/CommonLog" import {MusicListDialog} from "../../Common/components/MusicListDialog" import {DeviceListDialog} from "../../Common/components/DeviceListDialog" -import {MyPlayerConstants} from "../../Common/MyPlayerConstants" import prompt from '@system.prompt'; import featureAbility from '@ohos.ability.featureAbility'; @@ -25,15 +24,17 @@ import featureAbility from '@ohos.ability.featureAbility'; @Component struct Index { private playerManager: PlayerManager = new PlayerManager() - private remoteDeviceManager: RemoteDeviceManager + @State deviceList: RemoteDevice[] = [ + { deviceId: 'LocalHost', deviceName: 'LocalHost', deviceType: 1, status: 1 }] + private remoteDeviceManager: RemoteDeviceManager = new RemoteDeviceManager(this.deviceList) @State currentMusic: Music = this.playerManager.getCurrentMusic() @State isPlaying: boolean = false @State currentProgress: number = 0 @State currentTimeText: string = '00:00' @State totalTimeText: string = '00:00' private isSwitching: boolean= false - @State deviceList: Array = [ - { deviceId: 'LocalHost', deviceName: 'LocalHost', deviceType: 1, status: 1 }] + private bundleName : string + // 音乐列表自定义弹窗 musicListDialogController: CustomDialogController = new CustomDialogController({ @@ -60,10 +61,8 @@ struct Index { deviceList: this.deviceList, cancel: () => { CommonLog.info('onCancelDeviceListDialog') - this.remoteDeviceManager.stopDeviceDiscovery() }, confirm: (deviceName: string) => { - this.remoteDeviceManager.stopDeviceDiscovery() CommonLog.info('Select from deviceListDialog, deviceName = ' + deviceName) if (deviceName == 'LocalHost') { @@ -249,7 +248,6 @@ struct Index { existDeviceListDialog() { CommonLog.info('existDeviceListDialog') - this.remoteDeviceManager.stopDeviceDiscovery() } onChangePlayMode() { @@ -259,9 +257,6 @@ struct Index { onDistributeDevice() { CommonLog.info("onDistributeDevice") - - // 启动设备扫描 - this.remoteDeviceManager.startDeviceDiscovery() // 显示设备列表窗口 this.remoteDeviceManager.refreshRemoteDeviceList() this.deviceListDialogController.open() @@ -287,7 +282,7 @@ struct Index { this.isSwitching = false } - aboutToAppear() { + async aboutToAppear() { CommonLog.info("aboutToAppear") this.playerManager.setOnPlayingProgressListener((currentTimeMs) => { this.currentTimeText = this.getShownTimer(currentTimeMs) @@ -311,19 +306,24 @@ struct Index { this.isPlaying = true }) - this.remoteDeviceManager = new RemoteDeviceManager(this.deviceList) - this.remoteDeviceManager.init().then((data) => { - CommonLog.info('remoteDeviceManager init success') - }).catch((error) => { - prompt.showToast({ - message: 'remoteDeviceManager init error ' + JSON.stringify(error) - }) - }) - // 分布式拉起还原 this.restoreFromWant() + + //获取包名 + getBundleName().then((data) => { + this.bundleName = data + }) + + // 启动设备扫描 + this.remoteDeviceManager.startDeviceDiscovery() } + aboutToDisappear() { + CommonLog.info('aboutToDisappear'); + this.remoteDeviceManager.stopDeviceDiscovery() + } + + /** * 计算显示时间 */ @@ -355,10 +355,11 @@ struct Index { CommonLog.info('startAbilityContinuation deviceId=' + remoteDevice.deviceId + ' deviceName=' + remoteDevice.deviceName) CommonLog.info('startAbilityContinuation params=' + JSON.stringify(params)) + CommonLog.info('startAbilityContinuation ' + this.bundleName) let wantValue = { - bundleName: MyPlayerConstants.BUNDLE_NAME, - abilityName: MyPlayerConstants.BUNDLE_NAME + '.MainAbility', + bundleName: this.bundleName , + abilityName: this.bundleName + '.MainAbility', deviceId: remoteDevice.deviceId, parameters: params } @@ -389,14 +390,14 @@ struct Index { CommonLog.info('restoreFromWant featureAbility.getWant=' + JSON.stringify(want)) let status = want.parameters if (status != null && status.index != null) { - this.playerManager.playSpecifyMusic(status.seekTo,status.index) + this.playerManager.playSpecifyMusic(status.seekTo, status.index) this.isPlaying = true -// if (status.isPlaying) { -// this.isPlaying = true -// } else { -// this.playerManager.pause() -// this.isPlaying = false -// } + // if (status.isPlaying) { + // this.isPlaying = true + // } else { + // this.playerManager.pause() + // this.isPlaying = false + // } } }) } diff --git a/README.md b/README.md index a849ee5f133219913a3859e6aaa7a68a52ba0ab5..f0e93198d90420d351b7e83d7687d65f90a2fcb9 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ## knowledge_demo_temp #### 介绍 -​ 基于HiSpark Wifi loT开发套件(HI3861开发版)的相关demo。 +​ 临时存放设备和应用样例。 #### 目录结构 本仓库目录结构由如下4部分内容构成: @@ -14,13 +14,12 @@ │   ├── team_x // 具体相关智能设备的应用代码 │   └── third_party // 设备开发相关的第三方库文件 ├── FA -│   └── DistSchedule // 数字管家应用代码 -├── profile // 设备与应用间沟通的模型文件 -└── Server - ├── design // 服务端设计文档 - ├── distschedule-core // 入口模块,包含main和controller - ├── distschedule-dao // 数据库模块 - └── distschedule-service // 服务模块 +│   └── Entertainment // 娱乐场景应用 +│   │   ├── BombGame // 分布式传炸弹小游戏(ETS) +│   │   ├── DistrubutedMusicPlayer // 分布式音乐播放器(ETS) +│   │   ├── TicTacToeGame // 分布式井子过三关游戏(ETS) +│   └── Shopping // 购物场景应用 + ```