1import { paramMock } from "./utils" 2 3export function mockMultimediaImage() { 4 global.systemplugin.multimedia = {} 5 const sizeMock = { 6 height: "[PC Preview] unknow height", 7 width: "[PC Preview] unknow width" 8 } 9 const imageInfoMock = { 10 size: sizeMock, 11 pixelFortmat: "[PC Preview] unknow pixelFortmat", 12 colorSpace: "[PC Preview] unknow colorSpace", 13 alphaType: "[PC Preview] unknow alphaType" 14 } 15 const imageSourceMock = { 16 getImageInfo: function (...args) { 17 console.warn("ImageSource.getImageInfo interface mocked in the Previewer. How this interface works on the" + 18 " Previewer may be different from that on a real device.") 19 const len = args.length 20 if (typeof args[len - 1] === 'function') { 21 args[len - 1].call(this, paramMock.businessErrorMock, imageInfoMock); 22 } else { 23 return new Promise((resolve, reject) => { 24 resolve(imageInfoMock); 25 }) 26 } 27 }, 28 release: function (...args) { 29 console.warn("ImageSource.release interface mocked in the Previewer. How this interface works on the Previewer" + 30 " may be different from that on a real device.") 31 const len = args.length 32 if (typeof args[len - 1] === 'function') { 33 args[len - 1].call(this, paramMock.businessErrorMock); 34 } else { 35 return new Promise((resolve, reject) => { 36 resolve(); 37 }) 38 } 39 }, 40 supportedFormats: "[PC Preview] unknow supportedFormats" 41 } 42 const imagePackerMock = { 43 packing: function (...args) { 44 console.warn("ImagePacker.packing interface mocked in the Previewer. How this interface works on the Previewer" + 45 " may be different from that on a real device.") 46 const len = args.length 47 if (typeof args[len - 1] === 'function') { 48 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramArrayMock); 49 } else { 50 return new Promise((resolve, reject) => { 51 resolve(paramMock.paramArrayMock); 52 }) 53 } 54 }, 55 release: function (...args) { 56 console.warn("ImagePacker.release interface mocked in the Previewer. How this interface works on the Previewer" + 57 " may be different from that on a real device.") 58 const len = args.length 59 if (typeof args[len - 1] === 'function') { 60 args[len - 1].call(this, paramMock.businessErrorMock); 61 } else { 62 return new Promise((resolve, reject) => { 63 resolve(); 64 }) 65 } 66 }, 67 supportedFormats: "[PC Preview] unknow supportedFormats" 68 } 69 global.systemplugin.multimedia.image = { 70 createImageSource: function () { 71 console.warn("multimedia.image.createImageSource interface mocked in the Previewer. How this interface works" + 72 " on the Previewer may be different from that on a real device.") 73 return imageSourceMock; 74 }, 75 createImagePacker: function () { 76 console.warn("multimedia.image.createImagePacker interface mocked in the Previewer. How this interface works" + 77 " on the Previewer may be different from that on a real device.") 78 return imagePackerMock; 79 } 80 } 81} 82 83export function mockMultimediaMedia() { 84 const audioPlayerMock = { 85 play: function () { 86 console.warn("AudioPlayer.play interface mocked in the Previewer. How this interface works on the Previewer" + 87 " may be different from that on a real device.") 88 return 89 }, 90 pause: function () { 91 console.warn("AudioPlayer.pause interface mocked in the Previewer. How this interface works on the Previewer" + 92 " may be different from that on a real device.") 93 return 94 }, 95 stop: function () { 96 console.warn("AudioPlayer.stop interface mocked in the Previewer. How this interface works on the Previewer" + 97 " may be different from that on a real device.") 98 return 99 }, 100 seek: function (...args) { 101 console.warn("AudioPlayer.seek interface mocked in the Previewer. How this interface works on the Previewer" + 102 " may be different from that on a real device.") 103 return 104 }, 105 setVolume: function (...args) { 106 console.warn("AudioPlayer.setVolume interface mocked in the Previewer. How this interface works on the" + 107 " Previewer may be different from that on a real device.") 108 return 109 }, 110 release: function () { 111 console.warn("AudioPlayer.release interface mocked in the Previewer. How this interface works on the Previewer" + 112 " may be different from that on a real device.") 113 return 114 }, 115 src: "[PC Preview] unknow src", 116 loop: "[PC Preview] unknow loop", 117 currentTime: "[PC Preview] unknow currentTime", 118 duration: "[PC Preview] unknow duration", 119 state: "[PC Preview] unknow state", 120 on: function (...args) { 121 console.warn("AudioPlayer.on interface mocked in the Previewer. How this interface works on the Previewer may" + 122 " be different from that on a real device.") 123 const len = args.length 124 if (typeof args[len - 1] === 'function') { 125 if (args[0] == 'error') { 126 args[len - 1].call(this, paramMock.businessErrorMock); 127 } else if (args[0] == 'timeUpdate') { 128 args[len - 1].call(this, paramMock.paramNumberMock); 129 } else { 130 args[len - 1].call(this); 131 } 132 } 133 } 134 } 135 const audioRecorderMock = { 136 prepare: function () { 137 console.warn("AudioRecorder.prepare interface mocked in the Previewer. How this interface works on the" + 138 " Previewer may be different from that on a real device.") 139 }, 140 start: function () { 141 console.warn("AudioRecorder.start interface mocked in the Previewer. How this interface works on the Previewer" + 142 " may be different from that on a real device.") 143 }, 144 pause: function () { 145 console.warn("AudioRecorder.pause interface mocked in the Previewer. How this interface works on the Previewer" + 146 " may be different from that on a real device.") 147 }, 148 resume: function () { 149 console.warn("AudioRecorder.resume interface mocked in the Previewer. How this interface works on the" + 150 " Previewer may be different from that on a real device.") 151 }, 152 stop: function () { 153 console.warn("AudioRecorder.stop interface mocked in the Previewer. How this interface works on the Previewer" + 154 " may be different from that on a real device.") 155 }, 156 release: function () { 157 console.warn("AudioRecorder.release interface mocked in the Previewer. How this interface works on the" + 158 " Previewer may be different from that on a real device.") 159 }, 160 reset: function () { 161 console.warn("AudioRecorder.reset interface mocked in the Previewer. How this interface works on the Previewer" + 162 " may be different from that on a real device.") 163 }, 164 on: function (...args) { 165 console.warn("AudioRecorder.on interface mocked in the Previewer. How this interface works on the Previewer" + 166 " may be different from that on a real device.") 167 const len = args.length 168 if (typeof args[len - 1] === 'function') { 169 if (args[0] == 'error') { 170 args[len - 1].call(this, paramMock.businessErrorMock); 171 } else { 172 args[len - 1].call(this); 173 } 174 } 175 } 176 } 177 global.systemplugin.multimedia.media = { 178 createAudioPlayer: function () { 179 console.warn("multimedia.media.createAudioPlayer interface mocked in the Previewer. How this interface works" + 180 " on the Previewer may be different from that on a real device.") 181 return audioPlayerMock; 182 }, 183 createAudioRecorder: function () { 184 console.warn("multimedia.media.createAudioRecorder interface mocked in the Previewer. How this interface works" + 185 " on the Previewer may be different from that on a real device.") 186 return audioRecorderMock; 187 } 188 } 189} 190 191export function mockMultimediaMedialibrary() { 192 const MediaLibraryMock = { 193 storeMediaAsset: function (...args) { 194 console.warn("MediaLibrary.storeMediaAsset interface mocked in the Previewer. How this interface works on the" + 195 " Previewer may be different from that on a real device.") 196 const len = args.length 197 if (typeof args[len - 1] === 'function') { 198 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 199 } else { 200 return new Promise((resolve, reject) => { 201 resolve(paramMock.paramStringMock); 202 }) 203 } 204 }, 205 startImagePreview: function (...args) { 206 console.warn("MediaLibrary.startImagePreview interface mocked in the Previewer. How this interface works on" + 207 " the Previewer may be different from that on a real device.") 208 const len = args.length 209 if (typeof args[len - 1] === 'function') { 210 args[len - 1].call(this, paramMock.businessErrorMock); 211 } else { 212 return new Promise((resolve, reject) => { 213 resolve(); 214 }) 215 } 216 }, 217 startMediaSelect: function (...args) { 218 console.warn("MediaLibrary.startMediaSelect interface mocked in the Previewer. How this interface works on the" + 219 " Previewer may be different from that on a real device.") 220 const len = args.length 221 if (typeof args[len - 1] === 'function') { 222 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramArrayMock); 223 } else { 224 return new Promise((resolve, reject) => { 225 resolve(paramMock.paramArrayMock); 226 }) 227 } 228 } 229 } 230 global.systemplugin.multimedia.mediaLibrary = { 231 getMediaLibrary: function () { 232 console.warn("multimedia.mediaLibrary.getMediaLibrary interface mocked in the Previewer. How this interface" + 233 " works on the Previewer may be different from that on a real device.") 234 return MediaLibraryMock; 235 } 236 } 237}