1/* 2 * Copyright (c) 2022 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 16import { paramMock } from "../utils" 17 18export function mockMultimediaMedia() { 19 const audioPlayerMock = { 20 play: function () { 21 console.warn("AudioPlayer.play interface mocked in the Previewer. How this interface works on the Previewer" + 22 " may be different from that on a real device.") 23 }, 24 pause: function () { 25 console.warn("AudioPlayer.pause interface mocked in the Previewer. How this interface works on the Previewer" + 26 " may be different from that on a real device.") 27 }, 28 stop: function () { 29 console.warn("AudioPlayer.stop interface mocked in the Previewer. How this interface works on the Previewer" + 30 " may be different from that on a real device.") 31 }, 32 reset: function () { 33 console.warn("AudioPlayer.reset interface mocked in the Previewer. How this interface works on the Previewer" + 34 " may be different from that on a real device.") 35 }, 36 seek: function (...args) { 37 console.warn("AudioPlayer.seek interface mocked in the Previewer. How this interface works on the Previewer" + 38 " may be different from that on a real device.") 39 }, 40 setVolume: function (...args) { 41 console.warn("AudioPlayer.setVolume interface mocked in the Previewer. How this interface works on the" + 42 " Previewer may be different from that on a real device.") 43 }, 44 release: function () { 45 console.warn("AudioPlayer.release interface mocked in the Previewer. How this interface works on the Previewer" + 46 " may be different from that on a real device.") 47 }, 48 getTrackDescription: function(...args) { 49 console.warn("AudioPlayer.getTrackDescription interface mocked in the Previewer. How this interface works on the" + 50 " Previewer may be different from that on a real device.") 51 const len = args.length; 52 if (typeof args[len - 1] === 'function') { 53 args[len - 1].call(this, paramMock.businessErrorMock, [mediaDescriptionMock]); 54 } else { 55 return new Promise((resolve) => { 56 resolve([mediaDescriptionMock]); 57 }); 58 } 59 }, 60 src: '[PC Preview] unknow src', 61 loop: '[PC Preview] unknow loop', 62 currentTime: '[PC Preview] unknow currentTime', 63 duration: '[PC Preview] unknow duration', 64 state: '[PC Preview] unknow state', 65 on: function (...args) { 66 console.warn("AudioPlayer.on interface mocked in the Previewer. How this interface works on the Previewer may" + 67 " be different from that on a real device.") 68 } 69 } 70 const locationMock = { 71 latitude: '[PC Preview] unknow latitude', 72 longitude: '[PC Preview] unknow longitude', 73 } 74 const audioRecorderConfigMock = { 75 audioEncoder: '[PC Preview] unknow audioEncoder', 76 audioEncodeBitRate: '[PC Preview] unknow audioEncodeBitRate', 77 audioSampleRate: '[PC Preview] unknow audioSampleRate', 78 numberOfChannels: '[PC Preview] unknow numberOfChannels', 79 format: '[PC Preview] unknow format', 80 uri: '[PC Preview] unknow uri', 81 location: locationMock, 82 audioEncoderMime: '[PC Preview] unknow audioEncoderMime', 83 fileFormat: '[PC Preview] unknow fileFormat', 84 } 85 const audioRecorderMock = { 86 prepare: function (...args) { 87 console.warn("AudioRecorder.prepare interface mocked in the Previewer. How this interface works on the" + 88 " Previewer may be different from that on a real device.") 89 }, 90 start: function () { 91 console.warn("AudioRecorder.start interface mocked in the Previewer. How this interface works on the Previewer" + 92 " may be different from that on a real device.") 93 }, 94 pause: function () { 95 console.warn("AudioRecorder.pause interface mocked in the Previewer. How this interface works on the Previewer" + 96 " may be different from that on a real device.") 97 }, 98 resume: function () { 99 console.warn("AudioRecorder.resume interface mocked in the Previewer. How this interface works on the" + 100 " Previewer may be different from that on a real device.") 101 }, 102 stop: function () { 103 console.warn("AudioRecorder.stop interface mocked in the Previewer. How this interface works on the Previewer" + 104 " may be different from that on a real device.") 105 }, 106 release: function () { 107 console.warn("AudioRecorder.release interface mocked in the Previewer. How this interface works on the" + 108 " Previewer may be different from that on a real device.") 109 }, 110 reset: function () { 111 console.warn("AudioRecorder.reset interface mocked in the Previewer. How this interface works on the Previewer" + 112 " may be different from that on a real device.") 113 }, 114 on: function (...args) { 115 console.warn("AudioRecorder.on interface mocked in the Previewer. How this interface works on the Previewer" + 116 " may be different from that on a real device.") 117 } 118 } 119 const videoRecorderMock = { 120 prepare: function (...args) { 121 console.warn("VideoRecorder.prepare interface mocked in the Previewer. How this interface works on the Previewer" + 122 " may be different from that on a real device.") 123 const len = args.length; 124 if (typeof args[len - 1] === 'function') { 125 args[len - 1].call(this, paramMock.businessErrorMock); 126 } else { 127 return new Promise((resolve) => { 128 resolve(); 129 }); 130 } 131 }, 132 getInputSurface: function (...args) { 133 console.warn("VideoRecorder.getInputSurface interface mocked in the Previewer. How this interface works on the Previewer" + 134 " may be different from that on a real device.") 135 const len = args.length; 136 if (typeof args[len - 1] === 'function') { 137 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 138 } else { 139 return new Promise((resolve) => { 140 resolve(paramMock.paramStringMock); 141 }); 142 } 143 }, 144 start: function (...args) { 145 console.warn("VideoRecorder.start interface mocked in the Previewer. How this interface works on the Previewer" + 146 " may be different from that on a real device.") 147 const len = args.length; 148 if (typeof args[len - 1] === 'function') { 149 args[len - 1].call(this, paramMock.businessErrorMock); 150 } else { 151 return new Promise((resolve) => { 152 resolve(); 153 }); 154 } 155 }, 156 pause: function (...args) { 157 console.warn("VideoRecorder.pause interface mocked in the Previewer. How this interface works on the Previewer" + 158 " may be different from that on a real device.") 159 const len = args.length; 160 if (typeof args[len - 1] === 'function') { 161 args[len - 1].call(this, paramMock.businessErrorMock); 162 } else { 163 return new Promise((resolve) => { 164 resolve(); 165 }); 166 } 167 }, 168 resume: function (...args) { 169 console.warn("VideoRecorder.resume interface mocked in the Previewer. How this interface works on the Previewer" + 170 " may be different from that on a real device.") 171 const len = args.length; 172 if (typeof args[len - 1] === 'function') { 173 args[len - 1].call(this, paramMock.businessErrorMock); 174 } else { 175 return new Promise((resolve) => { 176 resolve(); 177 }); 178 } 179 }, 180 stop: function (...args) { 181 console.warn("VideoRecorder.stop interface mocked in the Previewer. How this interface works on the Previewer" + 182 " may be different from that on a real device.") 183 const len = args.length; 184 if (typeof args[len - 1] === 'function') { 185 args[len - 1].call(this, paramMock.businessErrorMock); 186 } else { 187 return new Promise((resolve) => { 188 resolve(); 189 }); 190 } 191 }, 192 release: function (...args) { 193 console.warn("VideoRecorder.release interface mocked in the Previewer. How this interface works on the Previewer" + 194 " may be different from that on a real device.") 195 const len = args.length; 196 if (typeof args[len - 1] === 'function') { 197 args[len - 1].call(this, paramMock.businessErrorMock); 198 } else { 199 return new Promise((resolve) => { 200 resolve(); 201 }); 202 } 203 }, 204 reset: function (...args) { 205 console.warn("VideoRecorder.reset interface mocked in the Previewer. How this interface works on the Previewer" + 206 " may be different from that on a real device.") 207 const len = args.length; 208 if (typeof args[len - 1] === 'function') { 209 args[len - 1].call(this, paramMock.businessErrorMock); 210 } else { 211 return new Promise((resolve) => { 212 resolve(); 213 }); 214 } 215 }, 216 on: function (...args) { 217 console.warn("AudioRecorder.on interface mocked in the Previewer. How this interface works on the Previewer" + 218 " may be different from that on a real device.") 219 }, 220 state: paramMock.paramStringMock, 221 } 222 const videoPlayerMock = { 223 url: '[PC Preview] unknow url', 224 loop: '[PC Preview] unknow loop', 225 currentTime: '[PC Preview] unknow currentTime', 226 duration: '[PC Preview] unknow duration', 227 state: '[PC Preview] unknow state', 228 width: '[PC Preview] unknow width', 229 height: '[PC Preview] unknow height', 230 setDisplaySurface: function (...args) { 231 console.warn("VideoPlayer.setDisplaySurface interface mocked in the Previewer. How this interface works on the Previewer" + 232 " may be different from that on a real device.") 233 const len = args.length; 234 if (typeof args[len - 1] === 'function') { 235 args[len - 1].call(this, paramMock.businessErrorMock); 236 } else { 237 return new Promise((resolve) => { 238 resolve(); 239 }); 240 } 241 }, 242 prepare: function (...args) { 243 console.warn("VideoPlayer.prepare interface mocked in the Previewer. How this interface works on the Previewer" + 244 " may be different from that on a real device.") 245 const len = args.length; 246 if (typeof args[len - 1] === 'function') { 247 args[len - 1].call(this, paramMock.businessErrorMock); 248 } else { 249 return new Promise((resolve) => { 250 resolve(); 251 }); 252 } 253 }, 254 play: function (...args) { 255 console.warn("VideoPlayer.play interface mocked in the Previewer. How this interface works on the Previewer" + 256 " may be different from that on a real device.") 257 const len = args.length; 258 if (typeof args[len - 1] === 'function') { 259 args[len - 1].call(this, paramMock.businessErrorMock); 260 } else { 261 return new Promise((resolve) => { 262 resolve(); 263 }); 264 } 265 }, 266 pause: function (...args) { 267 console.warn("VideoPlayer.pause interface mocked in the Previewer. How this interface works on the Previewer" + 268 " may be different from that on a real device.") 269 const len = args.length; 270 if (typeof args[len - 1] === 'function') { 271 args[len - 1].call(this, paramMock.businessErrorMock); 272 } else { 273 return new Promise((resolve) => { 274 resolve(); 275 }); 276 } 277 }, 278 stop: function (...args) { 279 console.warn("VideoPlayer.stop interface mocked in the Previewer. How this interface works on the Previewer" + 280 " may be different from that on a real device.") 281 const len = args.length; 282 if (typeof args[len - 1] === 'function') { 283 args[len - 1].call(this, paramMock.businessErrorMock); 284 } else { 285 return new Promise((resolve) => { 286 resolve(); 287 }); 288 } 289 }, 290 reset: function (...args) { 291 console.warn("VideoPlayer.reset interface mocked in the Previewer. How this interface works on the Previewer" + 292 " may be different from that on a real device.") 293 const len = args.length; 294 if (typeof args[len - 1] === 'function') { 295 args[len - 1].call(this, paramMock.businessErrorMock); 296 } else { 297 return new Promise((resolve) => { 298 resolve(); 299 }); 300 } 301 }, 302 seek: function (...args) { 303 console.warn("VideoPlayer.seek interface mocked in the Previewer. How this interface works on the Previewer" + 304 " may be different from that on a real device.") 305 const len = args.length; 306 if (typeof args[len - 1] === 'function') { 307 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); 308 } else { 309 return new Promise((resolve) => { 310 resolve(paramMock.paramNumberMock); 311 }); 312 } 313 }, 314 setVolume: function (...args) { 315 console.warn("VideoPlayer.setVolume interface mocked in the Previewer. How this interface works on the Previewer" + 316 " may be different from that on a real device.") 317 const len = args.length; 318 if (typeof args[len - 1] === 'function') { 319 args[len - 1].call(this, paramMock.businessErrorMock); 320 } else { 321 return new Promise((resolve) => { 322 resolve(); 323 }); 324 } 325 }, 326 release: function (...args) { 327 console.warn("VideoPlayer.release interface mocked in the Previewer. How this interface works on the Previewer" + 328 " may be different from that on a real device.") 329 const len = args.length; 330 if (typeof args[len - 1] === 'function') { 331 args[len - 1].call(this, paramMock.businessErrorMock); 332 } else { 333 return new Promise((resolve) => { 334 resolve(); 335 }); 336 } 337 }, 338 getTrackDescription: function (...args) { 339 console.warn("VideoPlayer.getTrackDescription interface mocked in the Previewer. How this interface works on the Previewer" + 340 " may be different from that on a real device.") 341 const len = args.length; 342 if (typeof args[len - 1] === 'function') { 343 args[len - 1].call(this, paramMock.businessErrorMock, [mediaDescriptionMock]); 344 } else { 345 return new Promise((resolve) => { 346 resolve([mediaDescriptionMock]); 347 }); 348 } 349 }, 350 setSpeed: function (...args) { 351 console.warn("VideoPlayer.setSpeed interface mocked in the Previewer. How this interface works on the Previewer" + 352 " may be different from that on a real device.") 353 const len = args.length; 354 if (typeof args[len - 1] === 'function') { 355 args[len - 1].call(this, paramMock.paramNumberMock, paramMock.paramNumberMock); 356 } else { 357 return new Promise((resolve) => { 358 resolve(); 359 }); 360 } 361 }, 362 on: function (...args) { 363 console.warn("VideoPlayer.on interface mocked in the Previewer. How this interface works on the Previewer" + 364 " may be different from that on a real device.") 365 }, 366 } 367 const videoRecorderProfileMock = { 368 audioBitrate: '[PC Preview] unknow audioBitrate', 369 audioChannels: '[PC Preview] unknow audioChannels', 370 audioCodec: '[PC Preview] unknow audioCodec', 371 audioSampleRate: '[PC Preview] unknow audioSampleRate', 372 fileFormat: '[PC Preview] unknow fileFormat', 373 videoBitrate: '[PC Preview] unknow videoBitrate', 374 videoCodec: '[PC Preview] unknow videoCodec', 375 videoFrameWidth: '[PC Preview] unknow videoFrameWidth', 376 videoFrameHeight: '[PC Preview] unknow videoFrameHeight', 377 videoFrameRate: '[PC Preview] unknow videoFrameRate', 378 } 379 const videoRecorderConfigMock = { 380 audioSourceType: '[PC Preview] unknow audioSourceType', 381 videoSourceType: '[PC Preview] unknow videoSourceType', 382 profile: '[PC Preview] unknow profile', 383 url: '[PC Preview] unknow url', 384 rotation: '[PC Preview] unknow rotation', 385 location: locationMock, 386 } 387 const mediaDescriptionMock = { 388 key: '[PC Preview] unknow key', 389 } 390 const multimediaMediaMock = { 391 MediaErrorCode : { 392 MSERR_OK: 0, 393 MSERR_NO_MEMORY: 1, 394 MSERR_OPERATION_NOT_PERMIT: 2, 395 MSERR_INVALID_VAL: 3, 396 MSERR_IO: 4, 397 MSERR_TIMEOUT: 5, 398 MSERR_UNKNOWN: 6, 399 MSERR_SERVICE_DIED: 7, 400 MSERR_INVALID_STATE: 8, 401 MSERR_UNSUPPORTED: 9 402 }, 403 BufferingInfoType : { 404 BUFFERING_START: 1, 405 BUFFERING_END: 2, 406 BUFFERING_PERCENT: 3, 407 CACHED_DURATION: 4 408 }, 409 AudioEncoder : { 410 DEFAULT: 0, 411 AMR_NB: 1, 412 AMR_WB: 2, 413 AAC_LC: 3, 414 HE_AAC: 4 415 }, 416 AudioOutputFormat : { 417 DEFAULT: 0, 418 MPEG_4: 2, 419 AMR_NB: 3, 420 AMR_WB: 4, 421 AAC_ADTS: 6 422 }, 423 CodecMimeType : { 424 VIDEO_H263: 'video/h263', 425 VIDEO_AVC: 'video/avc', 426 VIDEO_MPEG2: 'video/mpeg2', 427 VIDEO_MPEG4: 'video/mp4v-es', 428 VIDEO_VP8: 'video/x-vnd.on2.vp8', 429 AUDIO_AAC: 'audio/mp4a-latm', 430 AUDIO_VORBIS: 'audio/vorbis', 431 AUDIO_FLAC: 'audio/flac', 432 }, 433 PlaybackSpeed : { 434 SPEED_FORWARD_0_75_X: 0, 435 SPEED_FORWARD_1_00_X: 1, 436 SPEED_FORWARD_1_25_X: 2, 437 SPEED_FORWARD_1_75_X: 3, 438 SPEED_FORWARD_2_00_X: 4, 439 }, 440 ContainerFormatType : { 441 CFT_MPEG_4: "mp4", 442 CFT_MPEG_4A: "m4a", 443 }, 444 MediaType : { 445 MEDIA_TYPE_AUD: 0, 446 MEDIA_TYPE_VID: 1, 447 }, 448 MediaDescriptionKey : { 449 MD_KEY_TRACK_INDEX: "track_index", 450 MD_KEY_TRACK_TYPE: "track_type", 451 MD_KEY_CODEC_MIME: "codec_mime", 452 MD_KEY_DURATION: "duration", 453 MD_KEY_BITRATE: "bitrate", 454 MD_KEY_WIDTH: "width", 455 MD_KEY_HEIGHT: "height", 456 MD_KEY_FRAME_RATE: "frame_rate", 457 MD_KEY_AUD_CHANNEL_COUNT: "channel_count", 458 MD_KEY_AUD_SAMPLE_RATE: "sample_rate", 459 }, 460 AudioSourceType : { 461 AUDIO_SOURCE_TYPE_DEFAULT: 0, 462 AUDIO_SOURCE_TYPE_MIC: 1, 463 }, 464 VideoSourceType : { 465 VIDEO_SOURCE_TYPE_SURFACE_YUV: 0, 466 VIDEO_SOURCE_TYPE_SURFACE_ES: 1, 467 }, 468 SeekMode : { 469 SEEK_NEXT_SYNC: 0, 470 SEEK_PREV_SYNC: 1, 471 }, 472 AudioState: '[PC Preview] unknow AudioState', 473 VideoRecordState: '[PC Preview] unknow VideoRecordState', 474 VideoPlayState: '[PC Preview] unknow VideoPlayState', 475 createAudioPlayer: function () { 476 console.warn("media.createAudioPlayer interface mocked in the Previewer. How this interface works" + 477 " on the Previewer may be different from that on a real device.") 478 return audioPlayerMock; 479 }, 480 createAudioRecorder: function () { 481 console.warn("media.createAudioRecorder interface mocked in the Previewer. How this interface works" + 482 " on the Previewer may be different from that on a real device.") 483 return audioRecorderMock; 484 }, 485 createVideoPlayer: function () { 486 console.warn("media.createVideoPlayer interface mocked in the Previewer. How this interface works" + 487 " on the Previewer may be different from that on a real device.") 488 const len = args.length; 489 if (typeof args[len - 1] === 'function') { 490 args[len - 1].call(this, paramMock.businessErrorMock, videoPlayerMock); 491 } else { 492 return new Promise((resolve) => { 493 resolve(videoPlayerMock); 494 }); 495 } 496 }, 497 createVideoRecorder: function () { 498 console.warn("media.createVideoRecorder interface mocked in the Previewer. How this interface works" + 499 " on the Previewer may be different from that on a real device.") 500 const len = args.length; 501 if (typeof args[len - 1] === 'function') { 502 args[len - 1].call(this, paramMock.businessErrorMock, videoRecorderMock); 503 } else { 504 return new Promise((resolve) => { 505 resolve(videoRecorderMock); 506 }); 507 } 508 }, 509 } 510 return multimediaMediaMock; 511} 512