diff --git a/multimedia/media/media_js_standard/AudioPlayerTestBase.js b/multimedia/media/media_js_standard/AudioPlayerTestBase.js new file mode 100644 index 0000000000000000000000000000000000000000..40986f7796158419b09308e2b1c4cfe838fa697a --- /dev/null +++ b/multimedia/media/media_js_standard/AudioPlayerTestBase.js @@ -0,0 +1,153 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import media from '@ohos.multimedia.media' +import * as mediaTestBase from './MediaTestBase.js'; + +export function playAudioSource(src, duration, playTime, checkSeekTime, done) { + console.info(`case media source url: ${src}`) + let volumeChanged = false; + let playCount = 0; + let pauseCount = 0; + let stopCount = 0; + let seekCount = 0; + let audioPlayer = media.createAudioPlayer(); + if (audioPlayer == null) { + console.error('case createAudioPlayer failed'); + expect().assertFail(); + done(); + } + audioPlayer.src = src; + audioPlayer.on('dataLoad', () => { + console.info('case set source success'); + expect(audioPlayer.state).assertEqual('paused'); + expect(audioPlayer.currentTime).assertEqual(0); + expect(audioPlayer.duration).assertClose(duration, 500); + // step 0: dataLoad -> play + audioPlayer.play(); + }); + audioPlayer.on('play', () => { + console.info('case start to play'); + expect(audioPlayer.state).assertEqual('playing'); + playCount++; + if (playCount == 1) { + // step 1: play -> seek duration/3 + mediaTestBase.msleep(playTime); + audioPlayer.seek(audioPlayer.duration / 3); + } else if (playCount == 2) { + // step 5: play -> seek duration when loop is true + audioPlayer.loop = true; + audioPlayer.seek(audioPlayer.duration); + } else if (playCount == 3) { + // step 9: play -> stop + audioPlayer.stop(); + } else { + // step 12: play -> pause + audioPlayer.pause(); + } + }); + audioPlayer.on('pause', () => { + console.info('case now is paused'); + expect(audioPlayer.state).assertEqual('paused'); + pauseCount++; + if (pauseCount == 1) { + // step 3: pause -> seek 0 + audioPlayer.seek(0); + } else { + // step 13: pause -> stop + audioPlayer.stop(); + } + }); + audioPlayer.on('stop', () => { + console.info('case stop success'); + expect(audioPlayer.state).assertEqual('stopped'); + stopCount++; + if (stopCount == 1) { + // step 10: stop -> reset + audioPlayer.reset(); + } else { + // step 14: stop -> release + expect(volumeChanged).assertEqual(true); + audioPlayer.release(); + done(); + } + }); + audioPlayer.on('reset', () => { + console.info('case reset success'); + expect(audioPlayer.state).assertEqual('idle'); + // step 11: reset -> dataLoad + audioPlayer.src = src; + }); + audioPlayer.on('timeUpdate', (seekDoneTime) => { + seekCount++; + if (seekDoneTime == null) { + console.info(`case seek filed`); + audioPlayer.release(); + expect().assertFail(); + done(); + return; + } + console.info('case seek success, and seek time is ' + seekDoneTime); + if (seekCount == 1) { + // step 2: seek duration/3 -> pause + expect(audioPlayer.state).assertEqual('playing'); + if (checkSeekTime) { + expect(audioPlayer.duration / 3).assertEqual(seekDoneTime); + } + mediaTestBase.msleep(playTime); + audioPlayer.pause(); + } else if (seekCount == 2){ + // step 4: seek 0 -> play + if (checkSeekTime) { + expect(0).assertEqual(seekDoneTime); + } + expect(audioPlayer.state).assertEqual('paused'); + audioPlayer.play(); + } else if (seekCount == 3){ + // step 6: seek duration -> setVolume + seek duration when loop is false + if (checkSeekTime) { + expect(audioPlayer.duration).assertEqual(seekDoneTime); + } + mediaTestBase.msleep(playTime); + expect(audioPlayer.state).assertEqual('playing'); + audioPlayer.loop = false; + audioPlayer.setVolume(0.5); + audioPlayer.seek(audioPlayer.duration); + } else if (seekCount == 4){ + // step 7: seek duration -> setVolume + seek duration when loop is false + if (checkSeekTime) { + expect(audioPlayer.duration).assertEqual(seekDoneTime); + } + mediaTestBase.msleep(playTime); + expect(audioPlayer.state).assertEqual('stopped'); + } + }); + audioPlayer.on('volumeChange', () => { + console.info('case set volume success '); + volumeChanged = true; + }); + audioPlayer.on('finish', () => { + console.info('case play end'); + expect(audioPlayer.state).assertEqual('stopped'); + // step 8: play when stream is end + audioPlayer.play(); + }); + audioPlayer.on('error', (err) => { + console.error(`case error called,errMessage is ${err.message}`); + audioPlayer.release(); + expect().assertFail(); + done(); + }); +} \ No newline at end of file diff --git a/multimedia/media/media_js_standard/VideoPlayerTestBase.js b/multimedia/media/media_js_standard/VideoPlayerTestBase.js index 351f367ae588f3dee63d8c2524f094099ab44100..7eda18ac4b88632d0ca0ef7958476fd17111c6a4 100644 --- a/multimedia/media/media_js_standard/VideoPlayerTestBase.js +++ b/multimedia/media/media_js_standard/VideoPlayerTestBase.js @@ -38,7 +38,7 @@ export async function clearRouter() { await router.clear(); } -export async function playVideoSource(url, width, height, duration, playTime) { +export async function playVideoSource(url, width, height, duration, playTime, done) { console.info(`case media source url: ${url}`) let videoPlayer = null; let surfaceID = globalThis.value; @@ -49,6 +49,7 @@ export async function playVideoSource(url, width, height, duration, playTime) { } else { console.error('case createVideoPlayer failed'); expect().assertFail(); + done(); } }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback); @@ -59,13 +60,14 @@ export async function playVideoSource(url, width, height, duration, playTime) { videoPlayer.on('error', (err) => { console.error(`case error called, errMessage is ${err.message}`); expect().assertFail(); + videoPlayer.release(); + done(); }); videoPlayer.url = url; - if (width != null & height != null) { - await videoPlayer.setDisplaySurface(surfaceID).then(() => { - console.info('case setDisplaySurface success, surfaceID: ' + surfaceID); - }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback); - } + await videoPlayer.setDisplaySurface(surfaceID).then(() => { + console.info('case setDisplaySurface success, surfaceID: ' + surfaceID); + }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback); + await videoPlayer.prepare().then(() => { console.info('case prepare called'); diff --git a/multimedia/media/media_js_standard/audioPlayer/src/main/config.json b/multimedia/media/media_js_standard/audioPlayer/src/main/config.json index bdca282276cfed06c18ce52e4169465a6dd3cba9..42108b2fadc747ecedb18731e58c5277da672b72 100644 --- a/multimedia/media/media_js_standard/audioPlayer/src/main/config.json +++ b/multimedia/media/media_js_standard/audioPlayer/src/main/config.json @@ -44,7 +44,7 @@ } ], "deviceType": [ - "phone", + "default", "tablet", "tv", "wearable" diff --git a/multimedia/media/media_js_standard/audioRecorder/src/main/config.json b/multimedia/media/media_js_standard/audioRecorder/src/main/config.json index 3d5b3d7f681eb136a9328893f82c46f49a5a27d7..938e76200054f1cfc03e7c0f3f8dd56eba6a4e30 100644 --- a/multimedia/media/media_js_standard/audioRecorder/src/main/config.json +++ b/multimedia/media/media_js_standard/audioRecorder/src/main/config.json @@ -44,7 +44,7 @@ } ], "deviceType": [ - "phone", + "default", "tablet", "tv", "wearable" diff --git a/multimedia/media/media_js_standard/recorderFormat/BUILD.gn b/multimedia/media/media_js_standard/recorderFormat/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..808bdf8262465acd5dee1ca8dc4003d1b0f0e64e --- /dev/null +++ b/multimedia/media/media_js_standard/recorderFormat/BUILD.gn @@ -0,0 +1,31 @@ +# Copyright (C) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("recorder_format_js_hap") { + hap_profile = "./src/main/config.json" + deps = [ + ":recorder_format_js_assets", + ":recorder_format_resources", + ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsRecorderFormatJsTest" +} +ohos_js_assets("recorder_format_js_assets") { + source_dir = "./src/main/js/default" +} +ohos_resources("recorder_format_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" +} diff --git a/multimedia/media/media_js_standard/recorderFormat/Test.json b/multimedia/media/media_js_standard/recorderFormat/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..6183e3e9292be80001bfeb448d768bc747756d21 --- /dev/null +++ b/multimedia/media/media_js_standard/recorderFormat/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Configuration for audioRecorder Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "1000000", + "package": "ohos.acts.multimedia.audio.recorderformat", + "shell-timeout": "60000" + }, + "kits": [ + { + "type": "ShellKit", + "run-command": [ + ], + "teardown-command":[ + ] + }, + { + "test-file-name": [ + "ActsRecorderFormatJsTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/multimedia/media/media_js_standard/recorderFormat/signature/openharmony_sx.p7b b/multimedia/media/media_js_standard/recorderFormat/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..9f5b11e79355fb9d6f7cf7be4b2e60d661b2f33e Binary files /dev/null and b/multimedia/media/media_js_standard/recorderFormat/signature/openharmony_sx.p7b differ diff --git a/multimedia/media/media_js_standard/recorderFormat/src/main/config.json b/multimedia/media/media_js_standard/recorderFormat/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..a7e86cc7bd8c35956a2bfc84769b725db270b66d --- /dev/null +++ b/multimedia/media/media_js_standard/recorderFormat/src/main/config.json @@ -0,0 +1,100 @@ +{ + "app": { + "apiVersion": { + "compatible": 6, + "releaseType": "Beta1", + "target": 7 + }, + "vendor": "acts", + "bundleName": "ohos.acts.multimedia.audio.recorderformat", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": { + "default": { + "debug": true + } + }, + "module": { + "abilities": [ + { + "iconId": 16777218, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "descriptionId": 16777217, + "visible": true, + "labelId": 16777216, + "icon": "$media:icon", + "name": "ohos.acts.multimedia.audio.recorderformat.MainAbility", + "description": "$string:mainability_description", + "label": "$string:entry_MainAbility", + "type": "page", + "homeAbility": true, + "launchType": "standard" + } + ], + "deviceType": [ + "default", + "tablet", + "tv", + "wearable" + ], + "reqPermissions": [ + { + "name" : "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", + "reason" : "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS" + }, + { + "name" : "ohos.permission.REVOKE_SENSITIVE_PERMISSIONS", + "reason" : "use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS" + }, + { + "name" : "ohos.permission.MICROPHONE", + "reason" : "use ohos.permission.MICROPHONE" + }, + { + "name" : "ohos.permission.MEDIA_LOCATION", + "reason" : "use ohos.permission.MEDIA_LOCATION" + }, + { + "name" : "ohos.permission.READ_MEDIA", + "reason" : "use ohos.permission.READ_MEDIA" + }, + { + "name" : "ohos.permission.WRITE_MEDIA", + "reason" : "use ohos.permission.WRITE_MEDIA" + } + ], + "mainAbility": "ohos.acts.multimedia.audio.recorderformat.MainAbility", + "distro": { + "moduleType": "entry", + "installationFree": false, + "deliveryWithInstall": true, + "moduleName": "entry" + }, + "package": "ohos.acts.multimedia.audio.recorderformat", + "name": ".MyApplication", + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": true + } + } + ] + } +} \ No newline at end of file diff --git a/multimedia/media/media_js_standard/recorderFormat/src/main/java/ohos/acts/multimedia/audio/audioplayer/MainAbility.java b/multimedia/media/media_js_standard/recorderFormat/src/main/java/ohos/acts/multimedia/audio/audioplayer/MainAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..c3adacfc7a7e0e86651b857ee2f6e857d5c173be --- /dev/null +++ b/multimedia/media/media_js_standard/recorderFormat/src/main/java/ohos/acts/multimedia/audio/audioplayer/MainAbility.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package ohos.acts.multimedia.audio.audioplayer; + + import ohos.ace.ability.AceAbility; + import ohos.aafwk.content.Intent; + +/* + * java MainAbility + */ + + public class MainAbility extends AceAbility { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + } + + @Override + public void onStop() { + super.onStop(); + } + } diff --git a/multimedia/media/media_js_standard/recorderFormat/src/main/java/ohos/acts/multimedia/audio/audioplayer/MyApplication.java b/multimedia/media/media_js_standard/recorderFormat/src/main/java/ohos/acts/multimedia/audio/audioplayer/MyApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..956bc88979f54b82cf83932c34081ad9f26e8588 --- /dev/null +++ b/multimedia/media/media_js_standard/recorderFormat/src/main/java/ohos/acts/multimedia/audio/audioplayer/MyApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + package ohos.acts.multimedia.audio.audioplayer; + + import ohos.aafwk.ability.AbilityPackage; + +/* + * java MyApplication + */ + + public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } + } diff --git a/multimedia/media/media_js_standard/recorderFormat/src/main/js/default/app.js b/multimedia/media/media_js_standard/recorderFormat/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..830070d196d86b127cea947d168bfd116f446205 --- /dev/null +++ b/multimedia/media/media_js_standard/recorderFormat/src/main/js/default/app.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default { + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/multimedia/media/media_js_standard/recorderFormat/src/main/js/default/i18n/en-US.json b/multimedia/media/media_js_standard/recorderFormat/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/multimedia/media/media_js_standard/recorderFormat/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/multimedia/media/media_js_standard/recorderFormat/src/main/js/default/i18n/zh-CN.json b/multimedia/media/media_js_standard/recorderFormat/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/multimedia/media/media_js_standard/recorderFormat/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/multimedia/media/media_js_standard/recorderFormat/src/main/js/default/pages/index/index.css b/multimedia/media/media_js_standard/recorderFormat/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..c9195944a956c0d5628c701b7a3d9d2ed525cd2d --- /dev/null +++ b/multimedia/media/media_js_standard/recorderFormat/src/main/js/default/pages/index/index.css @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +.container { + flex-direction: column; + justify-content: center; + align-items: center; + width: 100%; + height: 100%; +} + +.title { + font-size: 40px; + color: #000000; + opacity: 0.9; +} + +@media screen and (device-type: tablet) and (orientation: landscape) { + .title { + font-size: 100px; + } +} + +@media screen and (device-type: wearable) { + .title { + font-size: 28px; + color: #FFFFFF; + } +} + +@media screen and (device-type: tv) { + .container { + background-image: url("/common/images/Wallpaper.png"); + background-size: cover; + background-repeat: no-repeat; + background-position: center; + } + + .title { + font-size: 100px; + color: #FFFFFF; + } +} + +@media screen and (device-type: phone) and (orientation: landscape) { + .title { + font-size: 60px; + } +} diff --git a/multimedia/media/media_js_standard/recorderFormat/src/main/js/default/pages/index/index.hml b/multimedia/media/media_js_standard/recorderFormat/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..8d0e2061b88c99c91488405f0f2ead0c77de1a9e --- /dev/null +++ b/multimedia/media/media_js_standard/recorderFormat/src/main/js/default/pages/index/index.hml @@ -0,0 +1,20 @@ + + +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/multimedia/media/media_js_standard/recorderFormat/src/main/js/default/pages/index/index.js b/multimedia/media/media_js_standard/recorderFormat/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..67f8b8567ccc4932331b7a18a6b947340d84fb40 --- /dev/null +++ b/multimedia/media/media_js_standard/recorderFormat/src/main/js/default/pages/index/index.js @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {Core, ExpectExtend} from 'deccjsunit/index' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + core.init() + const configService = core.getDefaultService('config') + this.timeout = 60000 + configService.setConfig(this) + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, +} \ No newline at end of file diff --git a/multimedia/media/media_js_standard/recorderFormat/src/main/js/test/AudioRecorderFormatCompatibilityTest.test.js b/multimedia/media/media_js_standard/recorderFormat/src/main/js/test/AudioRecorderFormatCompatibilityTest.test.js new file mode 100644 index 0000000000000000000000000000000000000000..6e1b25a5390d7378a29219299a5aac4a2b083e12 --- /dev/null +++ b/multimedia/media/media_js_standard/recorderFormat/src/main/js/test/AudioRecorderFormatCompatibilityTest.test.js @@ -0,0 +1,368 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import media from '@ohos.multimedia.media' +import abilityAccessCtrl from '@ohos.abilityAccessCtrl' +import bundle from '@ohos.bundle' +import mediaLibrary from '@ohos.multimedia.mediaLibrary' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('AudioRecorderFormatCompatibilityTest', function () { + const END_STATE = 0; + const PRE_STATE = 1; + const START_STATE = 2; + const PAUSE_STATE = 3; + const RESUME_STATE = 4; + const STOP_STATE = 5; + const RESET_STATE = 6; + const RELEASE_STATE = 7; + const ERROR_STATE = 8; + const RECORDER_TIME = 1000; + let fdPath; + let fileAsset; + let fdNumber; + let audioRecorder; + let audioConfig = { + audioSourceType : media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC, + audioEncoder : media.AudioSourceType.AAC_LC, + audioEncodeBitRate : 22050, + audioSampleRate : 22050, + numberOfChannels : 2, + format : media.AudioOutputFormat.AAC_ADTS, + uri : 'file:///data/accounts/account_0/appdata/appdata/recorder/test.m4a', + location : { latitude : 1, longitude : 1 }, + } + + function sleep(time) { + for(let t = Date.now();Date.now() - t <= time;); + } + + function initAudioRecorder() { + if (typeof (audioRecorder) != 'undefined') { + audioRecorder.release(); + audioRecorder = undefined; + } + audioRecorder = media.createAudioRecorder(); + } + + beforeAll(async function () { + await applyPermission(); + console.info('beforeAll case'); + }) + + beforeEach(function () { + console.info('beforeEach case'); + }) + + afterEach(async function () { + await closeFd(); + console.info('afterEach case'); + }) + + afterAll(function () { + console.info('afterAll case'); + }) + + async function applyPermission() { + let appInfo = await bundle.getApplicationInfo('ohos.acts.multimedia.audio.recorderformat', 0, 100); + let atManager = abilityAccessCtrl.createAtManager(); + if (atManager != null) { + let tokenID = appInfo.accessTokenId; + console.info('[permission] case accessTokenID is ' + tokenID); + let permissionName1 = 'ohos.permission.MICROPHONE'; + let permissionName2 = 'ohos.permission.MEDIA_LOCATION'; + let permissionName3 = 'ohos.permission.READ_MEDIA'; + let permissionName4 = 'ohos.permission.WRITE_MEDIA'; + await atManager.grantUserGrantedPermissi + + + + + + + on(tokenID, permissionName1, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + result); + }).catch((err) => { + console.error('[permission] case grantUserGrantedPermission failed :' + err); + }); + await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + result); + }).catch((err) => { + console.error('[permission] case grantUserGrantedPermission failed :' + err); + }); + await atManager.grantUserGrantedPermission(tokenID, permissionName3, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + result); + }).catch((err) => { + console.error('[permission] case grantUserGrantedPermission failed :' + err); + }); + await atManager.grantUserGrantedPermission(tokenID, permissionName4, 1).then((result) => { + console.info('[permission] case grantUserGrantedPermission success :' + result); + }).catch((err) => { + console.error('[permission] case grantUserGrantedPermission failed :' + err); + }); + } else { + console.error('[permission] case apply permission failed, createAtManager failed'); + } + } + + async function getFd(pathName) { + let displayName = pathName; + const mediaTest = mediaLibrary.getMediaLibrary(); + let fileKeyObj = mediaLibrary.FileKey; + let mediaType = mediaLibrary.MediaType.VIDEO; + let publicPath = await mediaTest.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); + let dataUri = await mediaTest.createAsset(mediaType, displayName, publicPath); + if (dataUri != undefined) { + let args = dataUri.id.toString(); + let fetchOp = { + selections : fileKeyObj.ID + "=?", + selectionArgs : [args], + } + let fetchFileResult = await mediaTest.getFileAssets(fetchOp); + fileAsset = await fetchFileResult.getAllObject(); + fdNumber = await fileAsset[0].open('Rw'); + fdPath = "fd://" + fdNumber.toString(); + console.info(`[mediaLibrary] case fdPath: ${fdPath}`); + } else { + console.error('[mediaLibrary] case dataUri is null') + } + } + + async function closeFd() { + if (fileAsset != null) { + await fileAsset[0].close(fdNumber).then(() => { + console.info('[mediaLibrary] case close fd success'); + }).catch((err) => { + console.error('[mediaLibrary] case close fd failed'); + }); + } else { + console.error('[mediaLibrary] case fileAsset is null'); + } + } + + function nextStep(mySteps, done) { + if (mySteps[0] == END_STATE) { + done(); + console.info('case to done'); + return; + } + switch (mySteps[0]) { + case PRE_STATE: + console.info('case to prepare'); + audioRecorder.prepare(audioConfig); + break; + case START_STATE: + console.info('case to start'); + audioRecorder.start(); + break; + case PAUSE_STATE: + console.info('case to pause'); + audioRecorder.pause(); + break; + case RESUME_STATE: + console.info('case to resume'); + audioRecorder.resume(); + break; + case STOP_STATE: + console.info('case to stop'); + audioRecorder.stop(); + break; + case RESET_STATE: + console.info('case to reset'); + audioRecorder.reset(); + break; + case RELEASE_STATE: + console.info('case to release'); + audioRecorder.release(); + audioRecorder = undefined; + break; + case ERROR_STATE: + console.info('case to wait error callback'); + break; + default: + break; + } + } + + function setCallback(mySteps, done) { + audioRecorder.on('prepare', () => { + console.info('setCallback prepare() case callback is called'); + mySteps.shift(); + nextStep(mySteps, done); + }); + + audioRecorder.on('start', () => { + console.info('setCallback start() case callback is called'); + sleep(RECORDER_TIME); + mySteps.shift(); + nextStep(mySteps, done); + }); + + audioRecorder.on('pause', () => { + console.info('setCallback pause() case callback is called'); + sleep(RECORDER_TIME); + mySteps.shift(); + nextStep(mySteps, done); + }); + + audioRecorder.on('resume', () => { + console.info('setCallback resume() case callback is called'); + sleep(RECORDER_TIME); + mySteps.shift(); + nextStep(mySteps, done); + }); + + audioRecorder.on('stop', () => { + console.info('setCallback stop() case callback is called'); + mySteps.shift(); + nextStep(mySteps, done); + }); + + audioRecorder.on('reset', () => { + console.info('setCallback reset() case callback is called'); + mySteps.shift(); + nextStep(mySteps, done); + }); + + audioRecorder.on('release', () => { + console.info('setCallback release() case callback is called'); + mySteps.shift(); + nextStep(mySteps, done); + }); + audioRecorder.on('error', (err) => { + console.info(`case error called,errName is ${err.name}`); + console.info(`case error called,errCode is ${err.code}`); + console.info(`case error called,errMessage is ${err.message}`); + mySteps.shift(); + expect(mySteps[0]).assertEqual(ERROR_STATE); + mySteps.shift(); + nextStep(mySteps, done); + }); + } + + /* * + * @tc.number : SUB_MEDIA_AUDIO_RECORDER_FORMAT_COMPATIBILITY_0100 + * @tc.name : location: {latitude: -90, longitude: -180} + * @tc.desc : location test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_RECORDER_FORMAT_COMPATIBILITY_0100', 0, async function (done) { + await getFd('COMPATIBILITY_0100.m4a'); + audioConfig.uri = fdPath; + audioConfig.location.latitude = -90; + audioConfig.location.longitude = -180; + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, RELEASE_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_RECORDER_FORMAT_COMPATIBILITY_0200 + * @tc.name : location: {latitude: 90, longitude: 180} + * @tc.desc : location test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_RECORDER_FORMAT_COMPATIBILITY_0200', 0, async function (done) { + await getFd('COMPATIBILITY_0200.m4a'); + audioConfig.uri = fdPath; + audioConfig.location.latitude = 90; + audioConfig.location.longitude = 180; + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, RELEASE_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_RECORDER_FORMAT_COMPATIBILITY_0300 + * @tc.name : location: {latitude: 0, longitude: 0} + * @tc.desc : location test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_RECORDER_FORMAT_COMPATIBILITY_0300', 0, async function (done) { + await getFd('COMPATIBILITY_0300.m4a'); + audioConfig.uri = fdPath; + audioConfig.location.latitude = 0; + audioConfig.location.longitude = 0; + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, RELEASE_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_RECORDER_FORMAT_COMPATIBILITY_0400 + * @tc.name : location: {latitude: 0, longitude: 180} + * @tc.desc : location test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_RECORDER_FORMAT_COMPATIBILITY_0400', 0, async function (done) { + await getFd('COMPATIBILITY_0400.m4a'); + audioConfig.uri = fdPath; + audioConfig.location.latitude = 0; + audioConfig.location.longitude = 180; + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, RELEASE_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_RECORDER_FORMAT_COMPATIBILITY_0500 + * @tc.name : location: {latitude: -30, longitude: 60} + * @tc.desc : location test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_RECORDER_FORMAT_COMPATIBILITY_0500', 0, async function (done) { + await getFd('COMPATIBILITY_0500.m4a'); + audioConfig.uri = fdPath; + audioConfig.location.latitude = -30; + audioConfig.location.longitude = 60; + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, RELEASE_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_RECORDER_FORMAT_COMPATIBILITY_0600 + * @tc.name : location: {latitude: 60, longitude: -90} + * @tc.desc : location test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_RECORDER_FORMAT_COMPATIBILITY_0600', 0, async function (done) { + await getFd('COMPATIBILITY_0600.m4a'); + audioConfig.uri = fdPath; + audioConfig.location.latitude = 60; + audioConfig.location.longitude = -90; + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, RELEASE_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) +}) diff --git a/multimedia/media/media_js_standard/recorderFormat/src/main/js/test/List.test.js b/multimedia/media/media_js_standard/recorderFormat/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..46b0df3e2ec469c1df93142166d2f408f3f9c5d1 --- /dev/null +++ b/multimedia/media/media_js_standard/recorderFormat/src/main/js/test/List.test.js @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +require('./AudioRecorderFormatCompatibilityTest.test.js') diff --git a/multimedia/media/media_js_standard/recorderFormat/src/main/resources/base/element/string.json b/multimedia/media/media_js_standard/recorderFormat/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..0bae6bd40f7360d5d818998221b199d3ec0f69c0 --- /dev/null +++ b/multimedia/media/media_js_standard/recorderFormat/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "entry_MainAbility" + }, + { + "name": "mainability_description", + "value": "JS_Empty Ability" + } + ] +} \ No newline at end of file diff --git a/multimedia/media/media_js_standard/recorderFormat/src/main/resources/base/media/icon.png b/multimedia/media/media_js_standard/recorderFormat/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/media/media_js_standard/recorderFormat/src/main/resources/base/media/icon.png differ diff --git a/multimedia/media/media_js_standard/videoPlayer/src/main/config.json b/multimedia/media/media_js_standard/videoPlayer/src/main/config.json index 530e15bd8d294c2662bb6a645b1747ebc3fbab47..4ce9b1cbe11bd5a006a2e7bc15b4f8b6484f97d6 100644 --- a/multimedia/media/media_js_standard/videoPlayer/src/main/config.json +++ b/multimedia/media/media_js_standard/videoPlayer/src/main/config.json @@ -44,7 +44,7 @@ } ], "deviceType": [ - "phone", + "default", "tablet", "tv", "wearable" diff --git a/multimedia/media/media_js_standard/videoRecorder/src/main/config.json b/multimedia/media/media_js_standard/videoRecorder/src/main/config.json index 11b7249ea014655cfdeab8408f1753c69067b242..918c96f32043da55bbc3ab439da7fe253f6695a8 100644 --- a/multimedia/media/media_js_standard/videoRecorder/src/main/config.json +++ b/multimedia/media/media_js_standard/videoRecorder/src/main/config.json @@ -44,7 +44,7 @@ } ], "deviceType": [ - "phone", + "default", "tablet", "tv", "wearable"