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 @@ + + +