1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16var Prompt = globalThis.requireNapi('prompt'); 17var commonEventManager = globalThis.requireNapi('commonEventManager'); 18var AVSessionManager = globalThis.requireNapi('multimedia.avsession'); 19 20const TAG = 'avpicker_component '; 21 22export class AVCastPicker extends ViewPU { 23 constructor(parent, params, __localStorage, elmtId = -1) { 24 super(parent, __localStorage, elmtId); 25 this.setInitiallyProvidedValue(params); 26 } 27 28 setInitiallyProvidedValue(params) { 29 } 30 31 updateStateVars(params) { 32 } 33 34 purgeVariableDependenciesOnElmtId(rmElmtId) { 35 } 36 37 aboutToBeDeleted() { 38 SubscriberManager.Get().delete(this.id__()); 39 this.aboutToBeDeletedInternal(); 40 } 41 42 aboutToAppear() { 43 console.info(TAG + 'aboutToAppear'); 44 let subscriber = undefined; 45 let subscribeInfo = { 46 events: ['avpickerCommunication'] 47 }; 48 commonEventManager.createSubscriber(subscribeInfo, (err, data) => { 49 if (err) { 50 console.info(TAG + 'createSubscriber fail, err : ' + err); 51 return; 52 } 53 subscriber = data; 54 commonEventManager.subscribe(subscriber, (err, data) => { 55 if (err) { 56 console.info(TAG + 'subscribe fail, err : ' + err); 57 return; 58 } 59 console.info(TAG + 'subscriber get message : ' + JSON.stringify(data)); 60 Prompt.showToast({ message: String(data.data), duration: 1500, bottom: 30 }); 61 }); 62 }); 63 } 64 65 aboutToDisappear() { 66 console.info(TAG + 'aboutToDisappear'); 67 } 68 69 initialRender() { 70 this.observeComponentCreation((elmtId, isInitialRender) => { 71 ViewStackProcessor.StartGetAccessRecordingFor(elmtId); 72 Column.create(); 73 Column.size({ width: '100%', height: '100%' }) 74 isInitialRender || Column.pop(); 75 ViewStackProcessor.StopGetAccessRecording(); 76 }); 77 this.observeComponentCreation((elmtId, isInitialRender) => { 78 ViewStackProcessor.StartGetAccessRecordingFor(elmtId); 79 UIExtensionComponent.create( 80 { 81 abilityName: 'AVPickerUIExtAbility', 82 bundleName: 'com.ohos.systemui', 83 parameters: {'ability.want.params.uiExtensionType':'sysPicker/mediaControl'} 84 } 85 ); 86 UIExtensionComponent.size({ width: '100%', height: '100%' }) 87 isInitialRender || UIExtensionComponent.pop(); 88 ViewStackProcessor.StopGetAccessRecording(); 89 }); 90 UIExtensionComponent.pop(); 91 Column.pop(); 92 } 93 94 rerender() { 95 this.updateDirtyElements(); 96 } 97} 98 99export default AVCastPicker; 100