1f6603c60Sopenharmony_ci/*
2f6603c60Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd.
3f6603c60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4f6603c60Sopenharmony_ci * you may not use this file except in compliance with the License.
5f6603c60Sopenharmony_ci * You may obtain a copy of the License at
6f6603c60Sopenharmony_ci *
7f6603c60Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8f6603c60Sopenharmony_ci *
9f6603c60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10f6603c60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11f6603c60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12f6603c60Sopenharmony_ci * See the License for the specific language governing permissions and
13f6603c60Sopenharmony_ci * limitations under the License.
14f6603c60Sopenharmony_ci */
15f6603c60Sopenharmony_ci
16f6603c60Sopenharmony_ciimport media from '@ohos.multimedia.media'
17f6603c60Sopenharmony_ciimport * as mediaTestBase from './MediaTestBase.js';
18f6603c60Sopenharmony_ci
19f6603c60Sopenharmony_ciexport const AV_PLAYER_STATE = {
20f6603c60Sopenharmony_ci    IDLE : 'idle',
21f6603c60Sopenharmony_ci    INITIALIZED : 'initialized',
22f6603c60Sopenharmony_ci    PREPARED : 'prepared',
23f6603c60Sopenharmony_ci    PLAYING : 'playing',
24f6603c60Sopenharmony_ci    PAUSED : 'paused',
25f6603c60Sopenharmony_ci    COMPLETED : 'completed',
26f6603c60Sopenharmony_ci    STOPPED : 'stopped',
27f6603c60Sopenharmony_ci    RELEASED : 'released',
28f6603c60Sopenharmony_ci    ERROR : 'error',
29f6603c60Sopenharmony_ci}
30f6603c60Sopenharmony_ci
31f6603c60Sopenharmony_cilet playTest = {
32f6603c60Sopenharmony_ci    width: 0,
33f6603c60Sopenharmony_ci    height: 0,
34f6603c60Sopenharmony_ci    duration: -1
35f6603c60Sopenharmony_ci}
36f6603c60Sopenharmony_ciexport {playTest};
37f6603c60Sopenharmony_ci
38f6603c60Sopenharmony_ciexport function setSource(avPlayer, src) {
39f6603c60Sopenharmony_ci    if (typeof(avPlayer) == 'undefined') {
40f6603c60Sopenharmony_ci        console.error('case avPlayer is undefined');
41f6603c60Sopenharmony_ci        return;
42f6603c60Sopenharmony_ci    }
43f6603c60Sopenharmony_ci    if (typeof(src) == 'string') {
44f6603c60Sopenharmony_ci        console.info('case src test');
45f6603c60Sopenharmony_ci        avPlayer.url = src;
46f6603c60Sopenharmony_ci    } else {
47f6603c60Sopenharmony_ci        console.info('case fdsrc test');
48f6603c60Sopenharmony_ci        avPlayer.fdSrc = src;
49f6603c60Sopenharmony_ci    }
50f6603c60Sopenharmony_ci}
51f6603c60Sopenharmony_ci
52f6603c60Sopenharmony_ciexport function setSubtitle(avPlayer, src) {
53f6603c60Sopenharmony_ci    if (typeof(avPlayer) === 'undefined') {
54f6603c60Sopenharmony_ci        console.error('case avPlayer is undefined');
55f6603c60Sopenharmony_ci        return;
56f6603c60Sopenharmony_ci    }
57f6603c60Sopenharmony_ci    if (typeof(src) === 'string') {
58f6603c60Sopenharmony_ci        console.info('case src test');
59f6603c60Sopenharmony_ci        avPlayer.addSubtitleFromUrl(src);
60f6603c60Sopenharmony_ci    } else {
61f6603c60Sopenharmony_ci        console.info('case fdsrc test');
62f6603c60Sopenharmony_ci        avPlayer.addSubtitleFromFd(src.fd, src.offset, src.length);
63f6603c60Sopenharmony_ci    }
64f6603c60Sopenharmony_ci}
65f6603c60Sopenharmony_ci
66f6603c60Sopenharmony_cifunction checkPlayTest(avPlayer, playTest) {
67f6603c60Sopenharmony_ci    if (avPlayer == null) {
68f6603c60Sopenharmony_ci        return;
69f6603c60Sopenharmony_ci    }
70f6603c60Sopenharmony_ci    expect(Math.abs(avPlayer.duration - playTest.duration)).assertLess(500);
71f6603c60Sopenharmony_ci    if (playTest.width > 0) {
72f6603c60Sopenharmony_ci        expect(avPlayer.width).assertEqual(playTest.width);
73f6603c60Sopenharmony_ci        expect(avPlayer.height).assertEqual(playTest.height);
74f6603c60Sopenharmony_ci    }
75f6603c60Sopenharmony_ci}
76f6603c60Sopenharmony_ci
77f6603c60Sopenharmony_cifunction toPreparePromise(avPlayer, playTest) {
78f6603c60Sopenharmony_ci    if (typeof(avPlayer) == 'undefined') {
79f6603c60Sopenharmony_ci        return;
80f6603c60Sopenharmony_ci    }
81f6603c60Sopenharmony_ci    avPlayer.prepare().then(() => {
82f6603c60Sopenharmony_ci        console.info('case prepare called');
83f6603c60Sopenharmony_ci        console.info('case avPlayer.duration: ' + avPlayer.duration);
84f6603c60Sopenharmony_ci        checkPlayTest(avPlayer, playTest);
85f6603c60Sopenharmony_ci    }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
86f6603c60Sopenharmony_ci}
87f6603c60Sopenharmony_ci
88f6603c60Sopenharmony_ciasync function preparePromise(avPlayer) {
89f6603c60Sopenharmony_ci    if (typeof(avPlayer) == 'undefined') {
90f6603c60Sopenharmony_ci        return;
91f6603c60Sopenharmony_ci    }
92f6603c60Sopenharmony_ci    await avPlayer.prepare().then(() => {
93f6603c60Sopenharmony_ci        console.info('case prepare called');
94f6603c60Sopenharmony_ci        console.info('case avPlayer.duration: ' + avPlayer.duration);
95f6603c60Sopenharmony_ci    }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
96f6603c60Sopenharmony_ci}
97f6603c60Sopenharmony_ci
98f6603c60Sopenharmony_cifunction addCnt(countArr) {
99f6603c60Sopenharmony_ci    if (countArr != null) {
100f6603c60Sopenharmony_ci        countArr[0]++;
101f6603c60Sopenharmony_ci    }
102f6603c60Sopenharmony_ci}
103f6603c60Sopenharmony_ci
104f6603c60Sopenharmony_ciexport function setCallback(avPlayer, type, countArr) {
105f6603c60Sopenharmony_ci    if (avPlayer == null) {
106f6603c60Sopenharmony_ci        return;
107f6603c60Sopenharmony_ci    }
108f6603c60Sopenharmony_ci    switch (type) {
109f6603c60Sopenharmony_ci        case 'volumeChange':
110f6603c60Sopenharmony_ci            avPlayer.on('volumeChange', (volume) => {
111f6603c60Sopenharmony_ci                console.info(`case volumeChange called, volume is ${volume}`);
112f6603c60Sopenharmony_ci                addCnt(countArr);
113f6603c60Sopenharmony_ci            });
114f6603c60Sopenharmony_ci            break;
115f6603c60Sopenharmony_ci        case 'endOfStream':
116f6603c60Sopenharmony_ci            avPlayer.on('endOfStream', () => {
117f6603c60Sopenharmony_ci                console.info(`case endOfStream called`);
118f6603c60Sopenharmony_ci                addCnt(countArr);
119f6603c60Sopenharmony_ci            });
120f6603c60Sopenharmony_ci            break;
121f6603c60Sopenharmony_ci        case 'speedDone':
122f6603c60Sopenharmony_ci            avPlayer.on('speedDone', (speedMode) => {
123f6603c60Sopenharmony_ci                console.info(`case speedDone called, speedMode is ${speedMode}`);
124f6603c60Sopenharmony_ci                addCnt(countArr);
125f6603c60Sopenharmony_ci            });
126f6603c60Sopenharmony_ci            break;
127f6603c60Sopenharmony_ci        case 'bitrateDone':
128f6603c60Sopenharmony_ci            avPlayer.on('bitrateDone', (bitrate) => {
129f6603c60Sopenharmony_ci                console.info(`case bitrateDone called, bitrate is ${bitrate}`);
130f6603c60Sopenharmony_ci            });
131f6603c60Sopenharmony_ci            break;
132f6603c60Sopenharmony_ci        case 'timeUpdate':
133f6603c60Sopenharmony_ci            avPlayer.on('timeUpdate', (time) => {
134f6603c60Sopenharmony_ci                console.info('case timeUpdate callback, time:' + time);
135f6603c60Sopenharmony_ci            });
136f6603c60Sopenharmony_ci            break;
137f6603c60Sopenharmony_ci        case 'bufferingUpdate':
138f6603c60Sopenharmony_ci            avPlayer.on('bufferingUpdate', (infoType, value) => {
139f6603c60Sopenharmony_ci            });
140f6603c60Sopenharmony_ci            break;
141f6603c60Sopenharmony_ci        case  'durationUpdate':
142f6603c60Sopenharmony_ci            avPlayer.on('durationUpdate', (duration) => {
143f6603c60Sopenharmony_ci                console.info('case durationUpdate called,duration:' + duration);
144f6603c60Sopenharmony_ci                addCnt(countArr);
145f6603c60Sopenharmony_ci            });
146f6603c60Sopenharmony_ci            break;
147f6603c60Sopenharmony_ci        case 'startRenderFrame':
148f6603c60Sopenharmony_ci            avPlayer.on('startRenderFrame', () => {
149f6603c60Sopenharmony_ci                console.info('case startRenderFrame called');
150f6603c60Sopenharmony_ci                addCnt(countArr);
151f6603c60Sopenharmony_ci            });
152f6603c60Sopenharmony_ci            break;
153f6603c60Sopenharmony_ci        case 'videoSizeChange':
154f6603c60Sopenharmony_ci            avPlayer.on('videoSizeChange', (w, h) => {
155f6603c60Sopenharmony_ci                console.info(`case videoSizeChange called, weight is ${w}, height is ${h}`);
156f6603c60Sopenharmony_ci                addCnt(countArr);
157f6603c60Sopenharmony_ci            });
158f6603c60Sopenharmony_ci            break;
159f6603c60Sopenharmony_ci        case  'audioInterrupt':
160f6603c60Sopenharmony_ci            avPlayer.on('audioInterrupt', (info) => {
161f6603c60Sopenharmony_ci                console.info(`case audioInterrupt called, info is ${info}`);
162f6603c60Sopenharmony_ci            });
163f6603c60Sopenharmony_ci            break;
164f6603c60Sopenharmony_ci        case  'availableBitrates':
165f6603c60Sopenharmony_ci            avPlayer.on('availableBitrates', (bitrates) => {
166f6603c60Sopenharmony_ci                for (let i = 0; i < bitrates.length; i++) {
167f6603c60Sopenharmony_ci                    console.info('case availableBitrates : '  + bitrates[i]);
168f6603c60Sopenharmony_ci                }
169f6603c60Sopenharmony_ci                addCnt(countArr);
170f6603c60Sopenharmony_ci            });
171f6603c60Sopenharmony_ci            break;
172f6603c60Sopenharmony_ci        default:
173f6603c60Sopenharmony_ci            break;
174f6603c60Sopenharmony_ci    }
175f6603c60Sopenharmony_ci}
176f6603c60Sopenharmony_ci
177f6603c60Sopenharmony_ciexport function offCallback(avPlayer, typeArr)
178f6603c60Sopenharmony_ci{
179f6603c60Sopenharmony_ci    if (avPlayer == null) {
180f6603c60Sopenharmony_ci        return;
181f6603c60Sopenharmony_ci    }
182f6603c60Sopenharmony_ci    for (let i = 0; i < typeArr.length; i++) {
183f6603c60Sopenharmony_ci        switch (typeArr[i]) {
184f6603c60Sopenharmony_ci            case 'stateChange':
185f6603c60Sopenharmony_ci                avPlayer.off('stateChange');
186f6603c60Sopenharmony_ci                break;
187f6603c60Sopenharmony_ci            case 'volumeChange':
188f6603c60Sopenharmony_ci                avPlayer.off('volumeChange');
189f6603c60Sopenharmony_ci                break;
190f6603c60Sopenharmony_ci            case 'endOfStream':
191f6603c60Sopenharmony_ci                avPlayer.off('endOfStream');
192f6603c60Sopenharmony_ci                break;
193f6603c60Sopenharmony_ci            case 'seekDone':
194f6603c60Sopenharmony_ci                avPlayer.off('seekDone');
195f6603c60Sopenharmony_ci                break;
196f6603c60Sopenharmony_ci            case 'speedDone':
197f6603c60Sopenharmony_ci                avPlayer.off('speedDone');
198f6603c60Sopenharmony_ci                break;
199f6603c60Sopenharmony_ci            case 'speedDone':
200f6603c60Sopenharmony_ci                avPlayer.off('speedDone');
201f6603c60Sopenharmony_ci                break;
202f6603c60Sopenharmony_ci            case 'timeUpdate':
203f6603c60Sopenharmony_ci                avPlayer.off('timeUpdate');
204f6603c60Sopenharmony_ci                break;
205f6603c60Sopenharmony_ci            case 'durationUpdate':
206f6603c60Sopenharmony_ci                avPlayer.off('durationUpdate');
207f6603c60Sopenharmony_ci                break;
208f6603c60Sopenharmony_ci            case 'bufferingUpdate':
209f6603c60Sopenharmony_ci                avPlayer.off('bufferingUpdate');
210f6603c60Sopenharmony_ci                break;
211f6603c60Sopenharmony_ci            case 'startRenderFrame':
212f6603c60Sopenharmony_ci                avPlayer.off('startRenderFrame');
213f6603c60Sopenharmony_ci                break;
214f6603c60Sopenharmony_ci            case 'videoSizeChange':
215f6603c60Sopenharmony_ci                avPlayer.off('videoSizeChange');
216f6603c60Sopenharmony_ci                break;
217f6603c60Sopenharmony_ci            case 'audioInterrupt':
218f6603c60Sopenharmony_ci                avPlayer.off('audioInterrupt');
219f6603c60Sopenharmony_ci                break;
220f6603c60Sopenharmony_ci            case 'availableBitrates':
221f6603c60Sopenharmony_ci                avPlayer.off('availableBitrates');
222f6603c60Sopenharmony_ci                break;
223f6603c60Sopenharmony_ci            case 'error':
224f6603c60Sopenharmony_ci                avPlayer.off('error');
225f6603c60Sopenharmony_ci                break;
226f6603c60Sopenharmony_ci            default:
227f6603c60Sopenharmony_ci                break;
228f6603c60Sopenharmony_ci        }
229f6603c60Sopenharmony_ci    }
230f6603c60Sopenharmony_ci}
231f6603c60Sopenharmony_ci
232f6603c60Sopenharmony_ciexport function setAVPlayerFunCb(src, avPlayer, playTest, playTime, done) {
233f6603c60Sopenharmony_ci    let volumeCnt = [0];
234f6603c60Sopenharmony_ci    let endOfStreamCnt = [0];
235f6603c60Sopenharmony_ci    let speedDoneCnt = [0];
236f6603c60Sopenharmony_ci    let videoSizeCnt = [0];
237f6603c60Sopenharmony_ci    let startRenderFrameCnt = [0];
238f6603c60Sopenharmony_ci    let durationUpdateCnt = [0];
239f6603c60Sopenharmony_ci    let seekDoneCnt = [0];
240f6603c60Sopenharmony_ci    let prepareCnt = 0;
241f6603c60Sopenharmony_ci    let playCnt = 0;
242f6603c60Sopenharmony_ci    let completedCnt = 0;
243f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
244f6603c60Sopenharmony_ci    console.info(`case setAVPlayerFunCb in, surfaceID is ${surfaceID}`);
245f6603c60Sopenharmony_ci    avPlayer.on('stateChange', async (state, reason) => {
246f6603c60Sopenharmony_ci        console.info(`case stateChange called, state is ${state}, reason is ${reason}`);
247f6603c60Sopenharmony_ci        if (reason == media.StateChangeReason.BACKGROUND) {
248f6603c60Sopenharmony_ci            console.info(`case media.StateChangeReason.BACKGROUND`);
249f6603c60Sopenharmony_ci            await avPlayer.release().then(() => {
250f6603c60Sopenharmony_ci            }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
251f6603c60Sopenharmony_ci        }
252f6603c60Sopenharmony_ci        console.info(`case state is ${state}`);
253f6603c60Sopenharmony_ci        switch (state) {
254f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.INITIALIZED:
255f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.INITIALIZED);
256f6603c60Sopenharmony_ci                avPlayer.surfaceId = surfaceID;
257f6603c60Sopenharmony_ci                try{
258f6603c60Sopenharmony_ci                    avPlayer.audioRendererInfo = {
259f6603c60Sopenharmony_ci                        content:audio.AudioRendererInfo.CONTENT_TYPE_MUSIC,
260f6603c60Sopenharmony_ci                        usage:audio.AudioRendererInfo.STREAM_USAGE_MEDIA,
261f6603c60Sopenharmony_ci                    }
262f6603c60Sopenharmony_ci                }catch(e){
263f6603c60Sopenharmony_ci                    console.error(`case stateChange error, e is ${e} ,message:${e.message}`);
264f6603c60Sopenharmony_ci                }
265f6603c60Sopenharmony_ci                // step 1, 13: initialized -> prepared
266f6603c60Sopenharmony_ci                toPreparePromise(avPlayer, playTest);
267f6603c60Sopenharmony_ci                break;
268f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PREPARED:
269f6603c60Sopenharmony_ci                prepareCnt++;
270f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
271f6603c60Sopenharmony_ci                checkPlayTest(avPlayer, playTest);
272f6603c60Sopenharmony_ci                expect(avPlayer.currentTime).assertEqual(0);
273f6603c60Sopenharmony_ci                if (prepareCnt == 1) {
274f6603c60Sopenharmony_ci                    // step 2: prepared -> playing
275f6603c60Sopenharmony_ci                    avPlayer.play().then(() => {
276f6603c60Sopenharmony_ci                    }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
277f6603c60Sopenharmony_ci                } else {
278f6603c60Sopenharmony_ci                    // step 14: prepared -> seek
279f6603c60Sopenharmony_ci                    avPlayer.seek(avPlayer.duration);
280f6603c60Sopenharmony_ci                }
281f6603c60Sopenharmony_ci                break;
282f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PLAYING:
283f6603c60Sopenharmony_ci                playCnt++;
284f6603c60Sopenharmony_ci                if (playCnt == 1) {
285f6603c60Sopenharmony_ci                    expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
286f6603c60Sopenharmony_ci                    // step 3: playing -> seek duration/3
287f6603c60Sopenharmony_ci                    await mediaTestBase.msleepAsync(playTime);
288f6603c60Sopenharmony_ci                    avPlayer.seek(avPlayer.duration / 3);
289f6603c60Sopenharmony_ci                } else if (playCnt == 2) {
290f6603c60Sopenharmony_ci                    expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
291f6603c60Sopenharmony_ci                    //  step 7: playing -> seek duration when loop true
292f6603c60Sopenharmony_ci                    avPlayer.seek(avPlayer.duration, media.SeekMode.SEEK_NEXT_SYNC);
293f6603c60Sopenharmony_ci                } else if (playCnt == 3) {
294f6603c60Sopenharmony_ci                    // step 10: playing -> stop
295f6603c60Sopenharmony_ci                    avPlayer.stop().then(() => {
296f6603c60Sopenharmony_ci                    }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
297f6603c60Sopenharmony_ci                }
298f6603c60Sopenharmony_ci                break;
299f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PAUSED:
300f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PAUSED);
301f6603c60Sopenharmony_ci                // step 5: pause -> seek 0
302f6603c60Sopenharmony_ci                avPlayer.loop = true;
303f6603c60Sopenharmony_ci                avPlayer.seek(0, media.SeekMode.SEEK_NEXT_SYNC);
304f6603c60Sopenharmony_ci                break;
305f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.COMPLETED:
306f6603c60Sopenharmony_ci                completedCnt++;
307f6603c60Sopenharmony_ci                expect(avPlayer.currentTime).assertEqual(avPlayer.duration);
308f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.COMPLETED);
309f6603c60Sopenharmony_ci                if (completedCnt == 1 && seekDoneCnt[0] < 5) {
310f6603c60Sopenharmony_ci                    // step 9: completed -> play
311f6603c60Sopenharmony_ci                    avPlayer.play();
312f6603c60Sopenharmony_ci                } else {
313f6603c60Sopenharmony_ci                    // step 16: completed -> reset
314f6603c60Sopenharmony_ci                    avPlayer.reset().then(() => {
315f6603c60Sopenharmony_ci                        expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.IDLE);
316f6603c60Sopenharmony_ci                        // step 17: reset -> release
317f6603c60Sopenharmony_ci                        avPlayer.release().then(() => {
318f6603c60Sopenharmony_ci                        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
319f6603c60Sopenharmony_ci                    }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
320f6603c60Sopenharmony_ci                }
321f6603c60Sopenharmony_ci                break;
322f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.STOPPED:
323f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.STOPPED);
324f6603c60Sopenharmony_ci                // step 11: stop -> reset
325f6603c60Sopenharmony_ci                avPlayer.reset().then(() => {
326f6603c60Sopenharmony_ci                    expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.IDLE);
327f6603c60Sopenharmony_ci                    // step 12: reset -> initialized
328f6603c60Sopenharmony_ci                    setSource(avPlayer, src);
329f6603c60Sopenharmony_ci                }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
330f6603c60Sopenharmony_ci                break;
331f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.RELEASED:
332f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
333f6603c60Sopenharmony_ci                // step 18: release -> done
334f6603c60Sopenharmony_ci                avPlayer = null;
335f6603c60Sopenharmony_ci                expect(volumeCnt[0]).assertLarger(0);
336f6603c60Sopenharmony_ci                expect(endOfStreamCnt[0]).assertLarger(0);
337f6603c60Sopenharmony_ci                expect(seekDoneCnt[0]).assertLarger(0);
338f6603c60Sopenharmony_ci                expect(speedDoneCnt[0]).assertLarger(0);
339f6603c60Sopenharmony_ci                expect(completedCnt).assertLarger(0);
340f6603c60Sopenharmony_ci                if (playTest.width != 0) {
341f6603c60Sopenharmony_ci                    expect(startRenderFrameCnt[0]).assertLarger(0);
342f6603c60Sopenharmony_ci                    expect(videoSizeCnt[0]).assertLarger(0);
343f6603c60Sopenharmony_ci                } else {
344f6603c60Sopenharmony_ci                    expect(startRenderFrameCnt[0]).assertEqual(0);
345f6603c60Sopenharmony_ci                    expect(videoSizeCnt[0]).assertEqual(0);
346f6603c60Sopenharmony_ci                }
347f6603c60Sopenharmony_ci                expect(durationUpdateCnt[0]).assertLarger(0)
348f6603c60Sopenharmony_ci                done();
349f6603c60Sopenharmony_ci                break;
350f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.ERROR:
351f6603c60Sopenharmony_ci                expect().assertFail();
352f6603c60Sopenharmony_ci                avPlayer.release().then(() => {
353f6603c60Sopenharmony_ci                }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
354f6603c60Sopenharmony_ci                break;
355f6603c60Sopenharmony_ci            default:
356f6603c60Sopenharmony_ci                break;
357f6603c60Sopenharmony_ci        }
358f6603c60Sopenharmony_ci    });
359f6603c60Sopenharmony_ci    avPlayer.on('seekDone', async (seekDoneTime) => {
360f6603c60Sopenharmony_ci        seekDoneCnt[0]++;
361f6603c60Sopenharmony_ci        console.info(`case seekDone called, seekDoneCnt is ${seekDoneCnt}, seekDoneTime is ${seekDoneTime}`);
362f6603c60Sopenharmony_ci        switch (seekDoneCnt[0]) {
363f6603c60Sopenharmony_ci            case 2:
364f6603c60Sopenharmony_ci                // step 6: seek(paused) -> play
365f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PAUSED);
366f6603c60Sopenharmony_ci                avPlayer.play();
367f6603c60Sopenharmony_ci                avPlayer.setSpeed(media.PlaybackSpeed.SPEED_FORWARD_2_00_X);
368f6603c60Sopenharmony_ci                avPlayer.setVolume(0.5);
369f6603c60Sopenharmony_ci                break;
370f6603c60Sopenharmony_ci            case 1:
371f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
372f6603c60Sopenharmony_ci                // step 4: seek(playing) -> pause
373f6603c60Sopenharmony_ci                avPlayer.pause().then(() => {
374f6603c60Sopenharmony_ci                }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
375f6603c60Sopenharmony_ci                break;
376f6603c60Sopenharmony_ci            case 3:
377f6603c60Sopenharmony_ci            case 4:
378f6603c60Sopenharmony_ci            case 5:
379f6603c60Sopenharmony_ci                let nowTime = avPlayer.currentTime;
380f6603c60Sopenharmony_ci                if (avPlayer.state == AV_PLAYER_STATE.PREPARED) {
381f6603c60Sopenharmony_ci                    // step 15: prepared -> play
382f6603c60Sopenharmony_ci                    avPlayer.play();
383f6603c60Sopenharmony_ci                }
384f6603c60Sopenharmony_ci                if (nowTime > avPlayer.duration / 2) {
385f6603c60Sopenharmony_ci                    avPlayer.setSpeed(media.PlaybackSpeed.SPEED_FORWARD_1_00_X);
386f6603c60Sopenharmony_ci                    await mediaTestBase.msleepAsync(avPlayer.duration - nowTime + playTime);
387f6603c60Sopenharmony_ci                }
388f6603c60Sopenharmony_ci                if (avPlayer.loop == true) {
389f6603c60Sopenharmony_ci                    // step 8: playing -> seek duration when loop false
390f6603c60Sopenharmony_ci                    expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
391f6603c60Sopenharmony_ci                    avPlayer.loop = false;
392f6603c60Sopenharmony_ci                    avPlayer.seek(avPlayer.duration, media.SeekMode.SEEK_NEXT_SYNC);
393f6603c60Sopenharmony_ci                }
394f6603c60Sopenharmony_ci                break;
395f6603c60Sopenharmony_ci        }
396f6603c60Sopenharmony_ci    });
397f6603c60Sopenharmony_ci    setCallback(avPlayer, 'volumeChange', volumeCnt);
398f6603c60Sopenharmony_ci    setCallback(avPlayer, 'endOfStream', endOfStreamCnt);
399f6603c60Sopenharmony_ci    setCallback(avPlayer, 'speedDone', speedDoneCnt);
400f6603c60Sopenharmony_ci    setCallback(avPlayer, 'bitrateDone', null);
401f6603c60Sopenharmony_ci    setCallback(avPlayer, 'timeUpdate', null);
402f6603c60Sopenharmony_ci    setCallback(avPlayer, 'bufferingUpdate', null);
403f6603c60Sopenharmony_ci    setCallback(avPlayer, 'durationUpdate', durationUpdateCnt);
404f6603c60Sopenharmony_ci    setCallback(avPlayer, 'startRenderFrame', startRenderFrameCnt);
405f6603c60Sopenharmony_ci    setCallback(avPlayer, 'videoSizeChange', videoSizeCnt);
406f6603c60Sopenharmony_ci    setCallback(avPlayer, 'audioInterrupt', null);
407f6603c60Sopenharmony_ci    setCallback(avPlayer, 'availableBitrates', null);
408f6603c60Sopenharmony_ci    avPlayer.on('error', async (err) => {
409f6603c60Sopenharmony_ci        console.error(`case error called, errMessage is ${err.message}`);
410f6603c60Sopenharmony_ci        expect().assertFail();
411f6603c60Sopenharmony_ci        await avPlayer.release().then(() => {
412f6603c60Sopenharmony_ci            avPlayer = null;
413f6603c60Sopenharmony_ci            done();
414f6603c60Sopenharmony_ci        });
415f6603c60Sopenharmony_ci    });
416f6603c60Sopenharmony_ci}
417f6603c60Sopenharmony_ci
418f6603c60Sopenharmony_ciexport function sleep(ms) {
419f6603c60Sopenharmony_ci    return new Promise(resolve => setTimeout(resolve, ms));
420f6603c60Sopenharmony_ci}
421f6603c60Sopenharmony_ci
422f6603c60Sopenharmony_cifunction setAVPlayerPlayAndPauseWithCallBack(src, avPlayer, playTime, done) {
423f6603c60Sopenharmony_ci    let playPauseCount = 0;
424f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
425f6603c60Sopenharmony_ci    console.info(`case setAVPlayerPlayAndPauseWithCallBack in, surfaceID is ${surfaceID}`);
426f6603c60Sopenharmony_ci    avPlayer.on('stateChange', async (state, reason) => {
427f6603c60Sopenharmony_ci        console.info(`case stateChange called, state is ${state}, reason is ${reason}`);
428f6603c60Sopenharmony_ci        console.info(`case state is ${state}`);
429f6603c60Sopenharmony_ci        switch (state) {
430f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.INITIALIZED:
431f6603c60Sopenharmony_ci                avPlayer.surfaceId = surfaceID;
432f6603c60Sopenharmony_ci                console.info('playPauseLoopWithCallBack play state is INITIALIZED')
433f6603c60Sopenharmony_ci                preparePromise(avPlayer);
434f6603c60Sopenharmony_ci                break;
435f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PREPARED:
436f6603c60Sopenharmony_ci            // step 1: initialized -> prepared -> play
437f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
438f6603c60Sopenharmony_ci                console.info('playPauseLoopWithCallBack play state is PREPARED')
439f6603c60Sopenharmony_ci                avPlayer.play()
440f6603c60Sopenharmony_ci                break;
441f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PLAYING:
442f6603c60Sopenharmony_ci                avPlayer.loop = true;
443f6603c60Sopenharmony_ci                console.info('playPauseLoopWithCallBack play state is PLAYING')
444f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
445f6603c60Sopenharmony_ci                playPauseCount++;
446f6603c60Sopenharmony_ci                mediaTestBase.msleepAsync(playTime);
447f6603c60Sopenharmony_ci                if(playPauseCount == 1001){
448f6603c60Sopenharmony_ci                    // step 4: playing -> stop -> release
449f6603c60Sopenharmony_ci                    avPlayer.stop().then(() => {
450f6603c60Sopenharmony_ci                        console.info('playPauseLoopWithCallBack avPlayer from play to stop')
451f6603c60Sopenharmony_ci                        avPlayer.release().then(() => {
452f6603c60Sopenharmony_ci                            console.info('playPauseLoopWithCallBack avPlayer from stop to release')
453f6603c60Sopenharmony_ci                            done();
454f6603c60Sopenharmony_ci                        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
455f6603c60Sopenharmony_ci                    }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
456f6603c60Sopenharmony_ci                }else{
457f6603c60Sopenharmony_ci                    // step 2: playing -> pause loop
458f6603c60Sopenharmony_ci                    avPlayer.pause().then(() => {
459f6603c60Sopenharmony_ci                        console.info('playPauseLoopWithCallBack avPlayer from play to pause,time is :' + playPauseCount)
460f6603c60Sopenharmony_ci                    }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
461f6603c60Sopenharmony_ci                }
462f6603c60Sopenharmony_ci                break;
463f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PAUSED:
464f6603c60Sopenharmony_ci                console.info('playPauseLoopWithCallBack play state is PAUSED')
465f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PAUSED);
466f6603c60Sopenharmony_ci            // step 3: pause -> playing loop
467f6603c60Sopenharmony_ci                avPlayer.play().then(() => {
468f6603c60Sopenharmony_ci                    console.info('playPauseLoopWithCallBack avPlayer from pause to play,time is :' + playPauseCount)
469f6603c60Sopenharmony_ci                }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
470f6603c60Sopenharmony_ci                break;
471f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.ERROR:
472f6603c60Sopenharmony_ci                expect().assertFail();
473f6603c60Sopenharmony_ci                avPlayer.release().then(() => {
474f6603c60Sopenharmony_ci                }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
475f6603c60Sopenharmony_ci                break;
476f6603c60Sopenharmony_ci            default:
477f6603c60Sopenharmony_ci                break;
478f6603c60Sopenharmony_ci        }
479f6603c60Sopenharmony_ci    });
480f6603c60Sopenharmony_ci    avPlayer.on('error', async (err) => {
481f6603c60Sopenharmony_ci        console.error(`case error called, errMessage is ${err.message}`);
482f6603c60Sopenharmony_ci        expect().assertFail();
483f6603c60Sopenharmony_ci        await avPlayer.release().then(() => {
484f6603c60Sopenharmony_ci            avPlayer = null;
485f6603c60Sopenharmony_ci            done();
486f6603c60Sopenharmony_ci        });
487f6603c60Sopenharmony_ci    });
488f6603c60Sopenharmony_ci}
489f6603c60Sopenharmony_ci
490f6603c60Sopenharmony_ciasync function idle(src, avPlayer) {
491f6603c60Sopenharmony_ci    console.info(`case media source: ${src}`)
492f6603c60Sopenharmony_ci    await media.createAVPlayer().then((video) => {
493f6603c60Sopenharmony_ci        if (typeof(video) != 'undefined') {
494f6603c60Sopenharmony_ci            console.info('case createAVPlayer success');
495f6603c60Sopenharmony_ci            avPlayer = video;
496f6603c60Sopenharmony_ci        } else {
497f6603c60Sopenharmony_ci            console.error('case createAVPlayer failed');
498f6603c60Sopenharmony_ci            expect().assertFail();
499f6603c60Sopenharmony_ci        }
500f6603c60Sopenharmony_ci    }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
501f6603c60Sopenharmony_ci    return avPlayer;
502f6603c60Sopenharmony_ci}
503f6603c60Sopenharmony_ci
504f6603c60Sopenharmony_ciexport async function avPlayerWithCallBack(src, avPlayer, playTime, done) {
505f6603c60Sopenharmony_ci    avPlayer = await idle(src, avPlayer)
506f6603c60Sopenharmony_ci    await setAVPlayerPlayAndPauseWithCallBack(src, avPlayer, playTime, done);
507f6603c60Sopenharmony_ci    await setSource(avPlayer, src);
508f6603c60Sopenharmony_ci}
509f6603c60Sopenharmony_ci
510f6603c60Sopenharmony_cilet createToReleaseLoopCount = 0;
511f6603c60Sopenharmony_ciasync function createToReleaseLoop(src, avPlayer, done) {
512f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
513f6603c60Sopenharmony_ci    console.info(`case createToReleaseLoop in, surfaceID is ${surfaceID}`);
514f6603c60Sopenharmony_ci    avPlayer.on('stateChange', async (state, reason) => {
515f6603c60Sopenharmony_ci        console.info(`case stateChange called, state is ${state}, reason is ${reason}`);
516f6603c60Sopenharmony_ci        console.info(`case state is ${state}`);
517f6603c60Sopenharmony_ci        switch (state) {
518f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.IDLE:
519f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.IDLE);
520f6603c60Sopenharmony_ci                setSource(avPlayer, src);
521f6603c60Sopenharmony_ci                break;
522f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.INITIALIZED:
523f6603c60Sopenharmony_ci                avPlayer.surfaceId = surfaceID;
524f6603c60Sopenharmony_ci                console.info('createToReleaseLoop play state is INITIALIZED')
525f6603c60Sopenharmony_ci            // step 1: initialized -> prepared -> play
526f6603c60Sopenharmony_ci                avPlayer.release()
527f6603c60Sopenharmony_ci                break;
528f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.RELEASED:
529f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
530f6603c60Sopenharmony_ci                createToReleaseLoopCount++
531f6603c60Sopenharmony_ci                if(createToReleaseLoopCount==1001){
532f6603c60Sopenharmony_ci                    done();
533f6603c60Sopenharmony_ci                }else{
534f6603c60Sopenharmony_ci                    avPlayer = await idle(src, avPlayer)
535f6603c60Sopenharmony_ci                    await createToReleaseLoop(src, avPlayer, done)
536f6603c60Sopenharmony_ci                    await setSource(avPlayer, src);
537f6603c60Sopenharmony_ci                }
538f6603c60Sopenharmony_ci                break;
539f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.ERROR:
540f6603c60Sopenharmony_ci                expect().assertFail();
541f6603c60Sopenharmony_ci                avPlayer.release().then(() => {
542f6603c60Sopenharmony_ci                }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
543f6603c60Sopenharmony_ci                break;
544f6603c60Sopenharmony_ci            default:
545f6603c60Sopenharmony_ci                break;
546f6603c60Sopenharmony_ci        }
547f6603c60Sopenharmony_ci    });
548f6603c60Sopenharmony_ci    avPlayer.on('error', async (err) => {
549f6603c60Sopenharmony_ci        console.error(`case error called, errMessage is ${err.message}`);
550f6603c60Sopenharmony_ci        expect().assertFail();
551f6603c60Sopenharmony_ci        await avPlayer.release().then(() => {
552f6603c60Sopenharmony_ci            avPlayer = null;
553f6603c60Sopenharmony_ci            done();
554f6603c60Sopenharmony_ci        });
555f6603c60Sopenharmony_ci    });
556f6603c60Sopenharmony_ci}
557f6603c60Sopenharmony_ci
558f6603c60Sopenharmony_ciexport async function createToRelease(src, avPlayer, done) {
559f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
560f6603c60Sopenharmony_ci    avPlayer = await idle(src, avPlayer)
561f6603c60Sopenharmony_ci    await createToReleaseLoop(src, avPlayer, done)
562f6603c60Sopenharmony_ci    await setSource(avPlayer, src);
563f6603c60Sopenharmony_ci    console.info('CreateToRelease setSource');
564f6603c60Sopenharmony_ci}
565f6603c60Sopenharmony_ci
566f6603c60Sopenharmony_ciexport async function playToCompleted(src, avPlayer, done) {
567f6603c60Sopenharmony_ci    avPlayer = await idle(src, avPlayer)
568f6603c60Sopenharmony_ci    await playToCompletedLoop(src, avPlayer, done);
569f6603c60Sopenharmony_ci    await setSource(avPlayer, src);
570f6603c60Sopenharmony_ci}
571f6603c60Sopenharmony_ci
572f6603c60Sopenharmony_ciasync function playToCompletedLoop(src, avPlayer, done) {
573f6603c60Sopenharmony_ci    let playToCompletedCount = 0;
574f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
575f6603c60Sopenharmony_ci    console.info(`case playToCompletedLoop in, surfaceID is ${surfaceID}`);
576f6603c60Sopenharmony_ci    avPlayer.on('stateChange', async (state, reason) => {
577f6603c60Sopenharmony_ci        console.info(`case stateChange called, state is ${state}, reason is ${reason}`);
578f6603c60Sopenharmony_ci        console.info(`case state is ${state}`);
579f6603c60Sopenharmony_ci        switch (state) {
580f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.INITIALIZED:
581f6603c60Sopenharmony_ci                avPlayer.surfaceId = surfaceID;
582f6603c60Sopenharmony_ci                console.info('playToCompletedLoop play state is INITIALIZED')
583f6603c60Sopenharmony_ci            // step 1: initialized -> prepared -> play
584f6603c60Sopenharmony_ci                await preparePromise(avPlayer);
585f6603c60Sopenharmony_ci                await sleep(2000);
586f6603c60Sopenharmony_ci                avPlayer.play()
587f6603c60Sopenharmony_ci                break;
588f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PLAYING:
589f6603c60Sopenharmony_ci                avPlayer.loop = false;
590f6603c60Sopenharmony_ci                console.info('playToCompletedLoop play state is PLAYING')
591f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
592f6603c60Sopenharmony_ci                playToCompletedCount++;
593f6603c60Sopenharmony_ci                if(playToCompletedCount == 1001){
594f6603c60Sopenharmony_ci                    // step 4: playing -> stop -> release
595f6603c60Sopenharmony_ci                    avPlayer.stop().then(() => {
596f6603c60Sopenharmony_ci                        console.info('playToCompletedLoop avPlayer from play to stop')
597f6603c60Sopenharmony_ci                        avPlayer.release().then(() => {
598f6603c60Sopenharmony_ci                            console.info('playToCompletedLoop avPlayer from stop to release')
599f6603c60Sopenharmony_ci                            done();
600f6603c60Sopenharmony_ci                        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
601f6603c60Sopenharmony_ci                    }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
602f6603c60Sopenharmony_ci                }else{
603f6603c60Sopenharmony_ci                    // step 2: playing -> seek loop
604f6603c60Sopenharmony_ci                    avPlayer.seek(10034, media.SeekMode.SEEK_NEXT_SYNC)
605f6603c60Sopenharmony_ci                    console.info('playToCompletedLoop avPlayer from play to seek,time is :' + playToCompletedCount)
606f6603c60Sopenharmony_ci                }
607f6603c60Sopenharmony_ci                break;
608f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.COMPLETED:
609f6603c60Sopenharmony_ci                expect(avPlayer.currentTime).assertEqual(avPlayer.duration);
610f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.COMPLETED);
611f6603c60Sopenharmony_ci                console.info('playToCompletedLoop avPlayer from COMPLETED to play')
612f6603c60Sopenharmony_ci            // step 3: COMPLETED -> play loop
613f6603c60Sopenharmony_ci                avPlayer.play();
614f6603c60Sopenharmony_ci                break;
615f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.ERROR:
616f6603c60Sopenharmony_ci                expect().assertFail();
617f6603c60Sopenharmony_ci                avPlayer.release().then(() => {
618f6603c60Sopenharmony_ci                }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
619f6603c60Sopenharmony_ci                break;
620f6603c60Sopenharmony_ci            default:
621f6603c60Sopenharmony_ci                break;
622f6603c60Sopenharmony_ci        }
623f6603c60Sopenharmony_ci    });
624f6603c60Sopenharmony_ci    avPlayer.on('error', async (err) => {
625f6603c60Sopenharmony_ci        console.error(`case error called, errMessage is ${err.message}`);
626f6603c60Sopenharmony_ci        expect().assertFail();
627f6603c60Sopenharmony_ci        await avPlayer.release().then(() => {
628f6603c60Sopenharmony_ci            avPlayer = null;
629f6603c60Sopenharmony_ci            done();
630f6603c60Sopenharmony_ci        });
631f6603c60Sopenharmony_ci    });
632f6603c60Sopenharmony_ci}
633f6603c60Sopenharmony_ci
634f6603c60Sopenharmony_ciexport async function seekLoop(src, avPlayer, done) {
635f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
636f6603c60Sopenharmony_ci    avPlayer = await idle(src, avPlayer)
637f6603c60Sopenharmony_ci    await setSource(avPlayer, src);
638f6603c60Sopenharmony_ci    console.info('seekLoop setSource');
639f6603c60Sopenharmony_ci    await sleep(20);
640f6603c60Sopenharmony_ci    if(avPlayer.state == AV_PLAYER_STATE.INITIALIZED) {
641f6603c60Sopenharmony_ci        avPlayer.surfaceId = surfaceID;
642f6603c60Sopenharmony_ci        console.info('seekLoop case prepare success');
643f6603c60Sopenharmony_ci        await preparePromise(avPlayer);
644f6603c60Sopenharmony_ci        await sleep(2000);
645f6603c60Sopenharmony_ci    }
646f6603c60Sopenharmony_ci    await avPlayer.play().then(() => {
647f6603c60Sopenharmony_ci        console.info('seekLoop play success');
648f6603c60Sopenharmony_ci        expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
649f6603c60Sopenharmony_ci    }, (err) => {
650f6603c60Sopenharmony_ci        console.error('seekLoop play filed,error message is :' + err.message)
651f6603c60Sopenharmony_ci    })
652f6603c60Sopenharmony_ci    await seekLoopWithCallback(avPlayer)
653f6603c60Sopenharmony_ci    console.info('seekLoop avPlayer from play to seek')
654f6603c60Sopenharmony_ci    // play seek loop 1000 times
655f6603c60Sopenharmony_ci    await avPlayer.stop().then(() => {
656f6603c60Sopenharmony_ci        console.info('seekLoopWithCallback avPlayer from play to stop')
657f6603c60Sopenharmony_ci    }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
658f6603c60Sopenharmony_ci    await avPlayer.release().then(() => {
659f6603c60Sopenharmony_ci        console.info('seekLoopWithCallback avPlayer from stop to release')
660f6603c60Sopenharmony_ci        expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
661f6603c60Sopenharmony_ci        done();
662f6603c60Sopenharmony_ci    }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
663f6603c60Sopenharmony_ci}
664f6603c60Sopenharmony_ci
665f6603c60Sopenharmony_ciasync function seekLoopWithCallback(avPlayer) {
666f6603c60Sopenharmony_ci    for (let loopTime = 0; loopTime < 5000; loopTime += 5) {
667f6603c60Sopenharmony_ci        await new Promise(resolve => {
668f6603c60Sopenharmony_ci            avPlayer.on('seekDone', seekDoneTime => {
669f6603c60Sopenharmony_ci                console.info(`case seekDone called seekDoneTime is ${seekDoneTime}`);
670f6603c60Sopenharmony_ci                resolve();
671f6603c60Sopenharmony_ci            });
672f6603c60Sopenharmony_ci            avPlayer.seek(loopTime);
673f6603c60Sopenharmony_ci            console.info(`case seekLoopWithCallback loopTime is ${loopTime}`);
674f6603c60Sopenharmony_ci        });
675f6603c60Sopenharmony_ci    }
676f6603c60Sopenharmony_ci}
677f6603c60Sopenharmony_ci
678f6603c60Sopenharmony_ciasync function seekLoopWithoutCallbackLoop(src, avPlayer, done) {
679f6603c60Sopenharmony_ci    let seekLoopWithoutCallbackLoop = 0;
680f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
681f6603c60Sopenharmony_ci    console.info(`case seekLoopWithoutCallbackLoop in, surfaceID is ${surfaceID}`);
682f6603c60Sopenharmony_ci    avPlayer.on('stateChange', async (state, reason) => {
683f6603c60Sopenharmony_ci        console.info(`case stateChange called, state is ${state}, reason is ${reason}`);
684f6603c60Sopenharmony_ci        console.info(`case state is ${state}`);
685f6603c60Sopenharmony_ci        switch (state) {
686f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.INITIALIZED:
687f6603c60Sopenharmony_ci                avPlayer.surfaceId = surfaceID;
688f6603c60Sopenharmony_ci                console.info('seekLoopWithoutCallbackLoop play state is INITIALIZED')
689f6603c60Sopenharmony_ci            // step 1: prepare
690f6603c60Sopenharmony_ci                preparePromise(avPlayer);
691f6603c60Sopenharmony_ci                break;
692f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PREPARED:
693f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
694f6603c60Sopenharmony_ci            // step 2: sop
695f6603c60Sopenharmony_ci                avPlayer.play()
696f6603c60Sopenharmony_ci                break;
697f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PLAYING:
698f6603c60Sopenharmony_ci                console.info('seekLoopWithoutCallbackLoop play state is PLAYING')
699f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
700f6603c60Sopenharmony_ci            // step 5: PLAYING-IDLE
701f6603c60Sopenharmony_ci                for(var loopTime = 0;loopTime < 1000; loopTime++){
702f6603c60Sopenharmony_ci                    avPlayer.seek(loopTime)
703f6603c60Sopenharmony_ci                    console.info(`case seekLoopWithoutCallbackLoop loopTime is ${loopTime}`);
704f6603c60Sopenharmony_ci                    if(loopTime==999){
705f6603c60Sopenharmony_ci                        avPlayer.stop().then(() => {
706f6603c60Sopenharmony_ci                            console.info('seekLoopWithoutCallbackLoop avPlayer from play to stop')
707f6603c60Sopenharmony_ci                            avPlayer.release().then(() => {
708f6603c60Sopenharmony_ci                                console.info('seekLoopWithoutCallbackLoop avPlayer from stop to release')
709f6603c60Sopenharmony_ci                                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
710f6603c60Sopenharmony_ci                                done();
711f6603c60Sopenharmony_ci                            }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
712f6603c60Sopenharmony_ci                        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
713f6603c60Sopenharmony_ci                    }
714f6603c60Sopenharmony_ci                }
715f6603c60Sopenharmony_ci                break;
716f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.ERROR:
717f6603c60Sopenharmony_ci                expect().assertFail();
718f6603c60Sopenharmony_ci                avPlayer.release().then(() => {
719f6603c60Sopenharmony_ci                }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
720f6603c60Sopenharmony_ci                break;
721f6603c60Sopenharmony_ci            default:
722f6603c60Sopenharmony_ci                break;
723f6603c60Sopenharmony_ci        }
724f6603c60Sopenharmony_ci    });
725f6603c60Sopenharmony_ci    avPlayer.on('error', async (err) => {
726f6603c60Sopenharmony_ci        console.error(`case error called, errMessage is ${err.message}`);
727f6603c60Sopenharmony_ci        expect().assertFail();
728f6603c60Sopenharmony_ci        await avPlayer.release().then(() => {
729f6603c60Sopenharmony_ci            avPlayer = null;
730f6603c60Sopenharmony_ci            done();
731f6603c60Sopenharmony_ci        });
732f6603c60Sopenharmony_ci    });
733f6603c60Sopenharmony_ci}
734f6603c60Sopenharmony_ci
735f6603c60Sopenharmony_ciexport async function seekLoopWithoutCallback(src, avPlayer, done) {
736f6603c60Sopenharmony_ci    avPlayer = await idle(src, avPlayer)
737f6603c60Sopenharmony_ci    await seekLoopWithoutCallbackLoop(src, avPlayer, done)
738f6603c60Sopenharmony_ci    await setSource(avPlayer, src);
739f6603c60Sopenharmony_ci    console.info('seekLoopWithoutCallback setSource');
740f6603c60Sopenharmony_ci}
741f6603c60Sopenharmony_ci
742f6603c60Sopenharmony_ciasync function prepareToStopLoop(src, avPlayer, done) {
743f6603c60Sopenharmony_ci    let prepareToStopLoopCount = 0;
744f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
745f6603c60Sopenharmony_ci    console.info(`case prepareToStopLoop in, surfaceID is ${surfaceID}`);
746f6603c60Sopenharmony_ci    avPlayer.on('stateChange', async (state, reason) => {
747f6603c60Sopenharmony_ci        console.info(`case stateChange called, state is ${state}, reason is ${reason}`);
748f6603c60Sopenharmony_ci        console.info(`case state is ${state}`);
749f6603c60Sopenharmony_ci        switch (state) {
750f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.INITIALIZED:
751f6603c60Sopenharmony_ci                avPlayer.surfaceId = surfaceID;
752f6603c60Sopenharmony_ci                console.info('prepareToStopLoop play state is INITIALIZED')
753f6603c60Sopenharmony_ci            // step 1: prepare
754f6603c60Sopenharmony_ci                preparePromise(avPlayer);
755f6603c60Sopenharmony_ci                break;
756f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PREPARED:
757f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
758f6603c60Sopenharmony_ci            // step 2: sop
759f6603c60Sopenharmony_ci                avPlayer.stop()
760f6603c60Sopenharmony_ci                break;
761f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.STOPPED:
762f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.STOPPED);
763f6603c60Sopenharmony_ci                prepareToStopLoopCount++
764f6603c60Sopenharmony_ci                if(prepareToStopLoopCount==1001){
765f6603c60Sopenharmony_ci            // end: release
766f6603c60Sopenharmony_ci                    avPlayer.release().then(() => {
767f6603c60Sopenharmony_ci                        console.info('prepareToStopLoop avPlayer from stop to release')
768f6603c60Sopenharmony_ci                        expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
769f6603c60Sopenharmony_ci                        done();
770f6603c60Sopenharmony_ci                    }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
771f6603c60Sopenharmony_ci                }else {
772f6603c60Sopenharmony_ci                    preparePromise(avPlayer);
773f6603c60Sopenharmony_ci                }
774f6603c60Sopenharmony_ci                break;
775f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.ERROR:
776f6603c60Sopenharmony_ci                expect().assertFail();
777f6603c60Sopenharmony_ci                avPlayer.release().then(() => {
778f6603c60Sopenharmony_ci                }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
779f6603c60Sopenharmony_ci                break;
780f6603c60Sopenharmony_ci            default:
781f6603c60Sopenharmony_ci                break;
782f6603c60Sopenharmony_ci        }
783f6603c60Sopenharmony_ci    });
784f6603c60Sopenharmony_ci    avPlayer.on('error', async (err) => {
785f6603c60Sopenharmony_ci        console.error(`case error called, errMessage is ${err.message}`);
786f6603c60Sopenharmony_ci        expect().assertFail();
787f6603c60Sopenharmony_ci        await avPlayer.release().then(() => {
788f6603c60Sopenharmony_ci            avPlayer = null;
789f6603c60Sopenharmony_ci            done();
790f6603c60Sopenharmony_ci        });
791f6603c60Sopenharmony_ci    });
792f6603c60Sopenharmony_ci}
793f6603c60Sopenharmony_ci
794f6603c60Sopenharmony_ciexport async function prepareToStop(src, avPlayer, done) {
795f6603c60Sopenharmony_ci    avPlayer = await idle(src, avPlayer)
796f6603c60Sopenharmony_ci    await prepareToStopLoop(src, avPlayer, done)
797f6603c60Sopenharmony_ci    setSource(avPlayer, src);
798f6603c60Sopenharmony_ci    console.info('prepareToStopLoop setSource');
799f6603c60Sopenharmony_ci}
800f6603c60Sopenharmony_ci
801f6603c60Sopenharmony_ciasync function prepareToResetLoop(src, avPlayer, done) {
802f6603c60Sopenharmony_ci    let prepareToResetLoopCount = 0;
803f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
804f6603c60Sopenharmony_ci    console.info(`case prepareToResetLoop in, surfaceID is ${surfaceID}`);
805f6603c60Sopenharmony_ci    avPlayer.on('stateChange', async (state, reason) => {
806f6603c60Sopenharmony_ci        console.info(`case stateChange called, state is ${state}, reason is ${reason}`);
807f6603c60Sopenharmony_ci        console.info(`case state is ${state}`);
808f6603c60Sopenharmony_ci        switch (state) {
809f6603c60Sopenharmony_ci            // step 1: create-Idle
810f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.IDLE:
811f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.IDLE);
812f6603c60Sopenharmony_ci                prepareToResetLoopCount++;
813f6603c60Sopenharmony_ci                if(prepareToResetLoopCount == 1001){
814f6603c60Sopenharmony_ci                    // end: release
815f6603c60Sopenharmony_ci                    avPlayer.release().then(() => {
816f6603c60Sopenharmony_ci                        console.info('prepareToResetLoop avPlayer from stop to release')
817f6603c60Sopenharmony_ci                        expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
818f6603c60Sopenharmony_ci                        done();
819f6603c60Sopenharmony_ci                    }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
820f6603c60Sopenharmony_ci                }else{
821f6603c60Sopenharmony_ci            // step 2: idle-INITIALIZED
822f6603c60Sopenharmony_ci                    setSource(avPlayer, src);
823f6603c60Sopenharmony_ci                    console.info('prepareToResetLoop avPlayer from play to seek,time is :' + prepareToResetLoopCount)
824f6603c60Sopenharmony_ci                }
825f6603c60Sopenharmony_ci                break;
826f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.INITIALIZED:
827f6603c60Sopenharmony_ci                avPlayer.surfaceId = surfaceID;
828f6603c60Sopenharmony_ci                console.info('prepareToResetLoop play state is INITIALIZED')
829f6603c60Sopenharmony_ci            // step 3: INITIALIZED-PREPARED
830f6603c60Sopenharmony_ci                preparePromise(avPlayer);
831f6603c60Sopenharmony_ci                break;
832f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PREPARED:
833f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
834f6603c60Sopenharmony_ci            // step 4: PREPARED-PLAYING
835f6603c60Sopenharmony_ci                avPlayer.play()
836f6603c60Sopenharmony_ci                break;
837f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PLAYING:
838f6603c60Sopenharmony_ci                console.info('prepareToResetLoop play state is PLAYING')
839f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
840f6603c60Sopenharmony_ci            // step 5: PLAYING-IDLE
841f6603c60Sopenharmony_ci                avPlayer.reset()
842f6603c60Sopenharmony_ci                break;
843f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.ERROR:
844f6603c60Sopenharmony_ci                expect().assertFail();
845f6603c60Sopenharmony_ci                avPlayer.release().then(() => {
846f6603c60Sopenharmony_ci                }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
847f6603c60Sopenharmony_ci                break;
848f6603c60Sopenharmony_ci            default:
849f6603c60Sopenharmony_ci                break;
850f6603c60Sopenharmony_ci        }
851f6603c60Sopenharmony_ci    });
852f6603c60Sopenharmony_ci    avPlayer.on('error', async (err) => {
853f6603c60Sopenharmony_ci        console.error(`case error called, errMessage is ${err.message}`);
854f6603c60Sopenharmony_ci        expect().assertFail();
855f6603c60Sopenharmony_ci        await avPlayer.release().then(() => {
856f6603c60Sopenharmony_ci            avPlayer = null;
857f6603c60Sopenharmony_ci            done();
858f6603c60Sopenharmony_ci        });
859f6603c60Sopenharmony_ci    });
860f6603c60Sopenharmony_ci}
861f6603c60Sopenharmony_ci
862f6603c60Sopenharmony_ciexport async function prepareToReset(src, avPlayer, done) {
863f6603c60Sopenharmony_ci    avPlayer = await idle(src, avPlayer)
864f6603c60Sopenharmony_ci    // url -> prepare -> play -> reset loop 1000 times
865f6603c60Sopenharmony_ci    await prepareToResetLoop(src, avPlayer, done)
866f6603c60Sopenharmony_ci    await setSource(avPlayer, src);
867f6603c60Sopenharmony_ci}
868f6603c60Sopenharmony_ci
869f6603c60Sopenharmony_cilet createToReleaseLoopCount2 = 0;
870f6603c60Sopenharmony_ciasync function createToReleaseLoop2(src, avPlayer, done) {
871f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
872f6603c60Sopenharmony_ci    console.info(`case createToReleaseLoop2 in, surfaceID is ${surfaceID}`);
873f6603c60Sopenharmony_ci    avPlayer.on('stateChange', async (state, reason) => {
874f6603c60Sopenharmony_ci        console.info(`case stateChange called, state is ${state}, reason is ${reason}`);
875f6603c60Sopenharmony_ci        console.info(`case state is ${state}`);
876f6603c60Sopenharmony_ci        switch (state) {
877f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.IDLE:
878f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.IDLE);
879f6603c60Sopenharmony_ci                setSource(avPlayer, src);
880f6603c60Sopenharmony_ci                break;
881f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.INITIALIZED:
882f6603c60Sopenharmony_ci                avPlayer.surfaceId = surfaceID;
883f6603c60Sopenharmony_ci                console.info('createToReleaseLoop2 play state is INITIALIZED')
884f6603c60Sopenharmony_ci                preparePromise(avPlayer);
885f6603c60Sopenharmony_ci                break;
886f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PREPARED:
887f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
888f6603c60Sopenharmony_ci            // step 4: PREPARED-PLAYING
889f6603c60Sopenharmony_ci                avPlayer.play()
890f6603c60Sopenharmony_ci                break;
891f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PLAYING:
892f6603c60Sopenharmony_ci                console.info('createToReleaseLoop2 play state is PLAYING')
893f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
894f6603c60Sopenharmony_ci                avPlayer.release()
895f6603c60Sopenharmony_ci                break;
896f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.RELEASED:
897f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
898f6603c60Sopenharmony_ci                createToReleaseLoopCount2++
899f6603c60Sopenharmony_ci                if(createToReleaseLoopCount2==1001){
900f6603c60Sopenharmony_ci                    done();
901f6603c60Sopenharmony_ci                }else{
902f6603c60Sopenharmony_ci                    avPlayer = await idle(src, avPlayer)
903f6603c60Sopenharmony_ci                    await createToReleaseLoop2(src, avPlayer, done)
904f6603c60Sopenharmony_ci                    await setSource(avPlayer, src);
905f6603c60Sopenharmony_ci                }
906f6603c60Sopenharmony_ci                break;
907f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.ERROR:
908f6603c60Sopenharmony_ci                expect().assertFail();
909f6603c60Sopenharmony_ci                avPlayer.release().then(() => {
910f6603c60Sopenharmony_ci                }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
911f6603c60Sopenharmony_ci                break;
912f6603c60Sopenharmony_ci            default:
913f6603c60Sopenharmony_ci                break;
914f6603c60Sopenharmony_ci        }
915f6603c60Sopenharmony_ci    });
916f6603c60Sopenharmony_ci    avPlayer.on('error', async (err) => {
917f6603c60Sopenharmony_ci        console.error(`case error called, errMessage is ${err.message}`);
918f6603c60Sopenharmony_ci        expect().assertFail();
919f6603c60Sopenharmony_ci        await avPlayer.release().then(() => {
920f6603c60Sopenharmony_ci            avPlayer = null;
921f6603c60Sopenharmony_ci            done();
922f6603c60Sopenharmony_ci        });
923f6603c60Sopenharmony_ci    });
924f6603c60Sopenharmony_ci}
925f6603c60Sopenharmony_ci
926f6603c60Sopenharmony_ciexport async function createToRelease2(src, avPlayer, done) {
927f6603c60Sopenharmony_ci    avPlayer = await idle(src, avPlayer)
928f6603c60Sopenharmony_ci    await createToReleaseLoop2(src, avPlayer, done)
929f6603c60Sopenharmony_ci    await setSource(avPlayer, src);
930f6603c60Sopenharmony_ci    console.info('createToRelease2 setSource');
931f6603c60Sopenharmony_ci}
932f6603c60Sopenharmony_ci
933f6603c60Sopenharmony_cilet createLoopTime = 0;
934f6603c60Sopenharmony_cilet createTotalTime = 0;
935f6603c60Sopenharmony_cilet createStart;
936f6603c60Sopenharmony_ciexport async function createTimeWithCallback(src, avPlayer, done) {
937f6603c60Sopenharmony_ci    avPlayer = await idle(src, avPlayer)
938f6603c60Sopenharmony_ci    createStart = Date.now();
939f6603c60Sopenharmony_ci    console.info(`createTimeWithCallback createStart time is : ${createStart}`)
940f6603c60Sopenharmony_ci    createTimeCallback(src, avPlayer, done)
941f6603c60Sopenharmony_ci}
942f6603c60Sopenharmony_ci
943f6603c60Sopenharmony_cifunction createTimeCallback(src, avPlayer, done){
944f6603c60Sopenharmony_ci    let end;
945f6603c60Sopenharmony_ci    let execution;
946f6603c60Sopenharmony_ci    avPlayer.on('stateChange', async (state, reason) => {
947f6603c60Sopenharmony_ci        console.info(`createTimeCallback stateChange called, state is ${state}, reason is ${reason}`);
948f6603c60Sopenharmony_ci        console.info(`createTimeCallback state is ${state}`);
949f6603c60Sopenharmony_ci        switch (state) {
950f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.IDLE:
951f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.IDLE);
952f6603c60Sopenharmony_ci                end = Date.now();
953f6603c60Sopenharmony_ci                console.info(`createTimeCallback end time is : ${end}`)
954f6603c60Sopenharmony_ci                execution = parseInt(end - createStart)
955f6603c60Sopenharmony_ci                createTotalTime = createTotalTime + execution;
956f6603c60Sopenharmony_ci                console.info("createTimeCallback execution time  is :" + execution)
957f6603c60Sopenharmony_ci                createLoopTime++;
958f6603c60Sopenharmony_ci                avPlayer.release()
959f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.RELEASED:
960f6603c60Sopenharmony_ci                console.info('createTimeCallback play state is release')
961f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
962f6603c60Sopenharmony_ci                if(createLoopTime == 10){
963f6603c60Sopenharmony_ci                    let avg = createTotalTime/10;
964f6603c60Sopenharmony_ci                    console.info("createTimeCallback avg time  is :" + avg)
965f6603c60Sopenharmony_ci                    createLoopTime = 0;
966f6603c60Sopenharmony_ci                    createTotalTime = 0;
967f6603c60Sopenharmony_ci                    done();
968f6603c60Sopenharmony_ci                }else{
969f6603c60Sopenharmony_ci                    avPlayer = null;
970f6603c60Sopenharmony_ci                    createTimeWithCallback(src, avPlayer, done)
971f6603c60Sopenharmony_ci                }
972f6603c60Sopenharmony_ci                break;
973f6603c60Sopenharmony_ci            default:
974f6603c60Sopenharmony_ci                break;
975f6603c60Sopenharmony_ci        }
976f6603c60Sopenharmony_ci    });
977f6603c60Sopenharmony_ci}
978f6603c60Sopenharmony_ci
979f6603c60Sopenharmony_ciexport async function createTimeWithoutCallback(src, avPlayer, done) {
980f6603c60Sopenharmony_ci    let totalTime = 0;
981f6603c60Sopenharmony_ci    for(var i = 0;i < 10;i++){
982f6603c60Sopenharmony_ci        let start = Date.now();
983f6603c60Sopenharmony_ci        console.info(`createTimeWithoutCallback start time is : ${start}`)
984f6603c60Sopenharmony_ci        avPlayer = await idle(src, avPlayer)
985f6603c60Sopenharmony_ci        let end = Date.now()
986f6603c60Sopenharmony_ci        let execution = parseInt(end - start)
987f6603c60Sopenharmony_ci        console.info("createTimeWithoutCallback execution time  is :" + execution)
988f6603c60Sopenharmony_ci        totalTime = totalTime + execution;
989f6603c60Sopenharmony_ci        await avPlayer.release().then(() => {
990f6603c60Sopenharmony_ci            console.info('createTimeWithoutCallback avPlayer is release')
991f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
992f6603c60Sopenharmony_ci        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
993f6603c60Sopenharmony_ci    }
994f6603c60Sopenharmony_ci    let avg = totalTime/10;
995f6603c60Sopenharmony_ci    console.info("createTimeWithoutCallback avg time  is :" + avg)
996f6603c60Sopenharmony_ci    done();
997f6603c60Sopenharmony_ci}
998f6603c60Sopenharmony_ci
999f6603c60Sopenharmony_ciexport async function prepareTimeWithoutCallback(src, avPlayer, done) {
1000f6603c60Sopenharmony_ci    let totalTime = 0;
1001f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
1002f6603c60Sopenharmony_ci    for(var i = 0;i < 10;i++){
1003f6603c60Sopenharmony_ci        avPlayer = await idle(src, avPlayer)
1004f6603c60Sopenharmony_ci        await setSource(avPlayer, src);
1005f6603c60Sopenharmony_ci        console.info('prepareTimeWithoutCallback setSource');
1006f6603c60Sopenharmony_ci        await sleep(20)
1007f6603c60Sopenharmony_ci        avPlayer.surfaceId = surfaceID;
1008f6603c60Sopenharmony_ci        let start = Date.now();
1009f6603c60Sopenharmony_ci        console.info(`prepareTimeWithoutCallback start time is : ${start}`)
1010f6603c60Sopenharmony_ci        let end;
1011f6603c60Sopenharmony_ci        await avPlayer.prepare().then(() => {
1012f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
1013f6603c60Sopenharmony_ci            console.info('prepareTimeWithoutCallback avPlayer state is prepared')
1014f6603c60Sopenharmony_ci            end = Date.now()
1015f6603c60Sopenharmony_ci            console.info(`prepareTimeWithoutCallback end time is : ${end}`)
1016f6603c60Sopenharmony_ci        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1017f6603c60Sopenharmony_ci        let execution = parseInt(end - start)
1018f6603c60Sopenharmony_ci        console.info("prepareTimeWithoutCallback execution time  is :" + execution)
1019f6603c60Sopenharmony_ci        totalTime = totalTime + execution;
1020f6603c60Sopenharmony_ci        await avPlayer.release().then(() => {
1021f6603c60Sopenharmony_ci            console.info('prepareTimeWithoutCallback avPlayer is release')
1022f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
1023f6603c60Sopenharmony_ci        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1024f6603c60Sopenharmony_ci    }
1025f6603c60Sopenharmony_ci    let avg = totalTime/10;
1026f6603c60Sopenharmony_ci    console.info("prepareTimeWithoutCallback avg time  is :" + avg)
1027f6603c60Sopenharmony_ci    done();
1028f6603c60Sopenharmony_ci}
1029f6603c60Sopenharmony_ci
1030f6603c60Sopenharmony_ciexport async function prepareTimeWithCallback(src, avPlayer, done) {
1031f6603c60Sopenharmony_ci    avPlayer = await idle(src, avPlayer)
1032f6603c60Sopenharmony_ci    await prepareTimeCallback(src, avPlayer, done)
1033f6603c60Sopenharmony_ci    await setSource(avPlayer, src);
1034f6603c60Sopenharmony_ci}
1035f6603c60Sopenharmony_ci
1036f6603c60Sopenharmony_ciasync function prepareTimeCallback(src, avPlayer, done) {
1037f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
1038f6603c60Sopenharmony_ci    let start;
1039f6603c60Sopenharmony_ci    let end;
1040f6603c60Sopenharmony_ci    let execution;
1041f6603c60Sopenharmony_ci    let loopTime = 0;
1042f6603c60Sopenharmony_ci    let totalTime = 0;
1043f6603c60Sopenharmony_ci    console.info(`case setCallback in, surfaceID is ${surfaceID}`);
1044f6603c60Sopenharmony_ci    avPlayer.on('stateChange', async (state, reason) => {
1045f6603c60Sopenharmony_ci        console.info(`case stateChange called, state is ${state}, reason is ${reason}`);
1046f6603c60Sopenharmony_ci        console.info(`case state is ${state}`);
1047f6603c60Sopenharmony_ci        switch (state) {
1048f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.IDLE:
1049f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.IDLE);
1050f6603c60Sopenharmony_ci                if(loopTime == 10){
1051f6603c60Sopenharmony_ci                    avPlayer.release().then(() => {
1052f6603c60Sopenharmony_ci                        console.info('prepareTimeWithCallback avPlayer is release')
1053f6603c60Sopenharmony_ci                        expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
1054f6603c60Sopenharmony_ci                        avPlayer = null;
1055f6603c60Sopenharmony_ci                        let avg = totalTime/10;
1056f6603c60Sopenharmony_ci                        console.info("prepareTimeWithCallback avg time is :" + avg)
1057f6603c60Sopenharmony_ci                        done();
1058f6603c60Sopenharmony_ci                    }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1059f6603c60Sopenharmony_ci                }else{
1060f6603c60Sopenharmony_ci                    setSource(avPlayer, src)
1061f6603c60Sopenharmony_ci                }
1062f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.INITIALIZED:
1063f6603c60Sopenharmony_ci                avPlayer.surfaceId = surfaceID;
1064f6603c60Sopenharmony_ci                console.info('prepareTimeWithCallback play state is INITIALIZED')
1065f6603c60Sopenharmony_ci            // step 1: initialized -> prepared
1066f6603c60Sopenharmony_ci                start = Date.now();
1067f6603c60Sopenharmony_ci                console.info(`prepareTimeWithCallback start time is : ${start}`)
1068f6603c60Sopenharmony_ci                avPlayer.prepare()
1069f6603c60Sopenharmony_ci                break;
1070f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PREPARED:
1071f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
1072f6603c60Sopenharmony_ci                console.info('prepareTimeWithCallback avPlayer state is prepared')
1073f6603c60Sopenharmony_ci                end = Date.now();
1074f6603c60Sopenharmony_ci                console.info(`prepareTimeWithCallback end time is : ${end}`)
1075f6603c60Sopenharmony_ci                execution = parseInt(end - start)
1076f6603c60Sopenharmony_ci                console.info("prepareTimeWithCallback execution time  is :" + execution)
1077f6603c60Sopenharmony_ci                totalTime = totalTime + execution;
1078f6603c60Sopenharmony_ci                loopTime++;
1079f6603c60Sopenharmony_ci                avPlayer.reset()
1080f6603c60Sopenharmony_ci                break;
1081f6603c60Sopenharmony_ci            default:
1082f6603c60Sopenharmony_ci                break;
1083f6603c60Sopenharmony_ci        }
1084f6603c60Sopenharmony_ci    });
1085f6603c60Sopenharmony_ci}
1086f6603c60Sopenharmony_ci
1087f6603c60Sopenharmony_ciexport async function playTimeWithoutCallback(src, avPlayer, done) {
1088f6603c60Sopenharmony_ci    let totalTime = 0;
1089f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
1090f6603c60Sopenharmony_ci    for(var i = 0;i < 10;i++){
1091f6603c60Sopenharmony_ci        avPlayer = await idle(src, avPlayer)
1092f6603c60Sopenharmony_ci        await setSource(avPlayer, src);
1093f6603c60Sopenharmony_ci        console.info('playTimeWithoutCallback setSource');
1094f6603c60Sopenharmony_ci        await sleep(20)
1095f6603c60Sopenharmony_ci        avPlayer.surfaceId = surfaceID;
1096f6603c60Sopenharmony_ci        await avPlayer.prepare().then(() => {
1097f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
1098f6603c60Sopenharmony_ci            console.info('playTimeWithoutCallback avPlayer state is prepared')
1099f6603c60Sopenharmony_ci        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1100f6603c60Sopenharmony_ci        let start = Date.now();
1101f6603c60Sopenharmony_ci        let end;
1102f6603c60Sopenharmony_ci        console.info(`playTimeWithoutCallback start time is : ${start}`)
1103f6603c60Sopenharmony_ci        await avPlayer.play().then(() => {
1104f6603c60Sopenharmony_ci            end = Date.now();
1105f6603c60Sopenharmony_ci            console.info(`playTimeWithoutCallback end time is : ${end}`)
1106f6603c60Sopenharmony_ci            console.info('playTimeWithoutCallback play success');
1107f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
1108f6603c60Sopenharmony_ci        }, (err) => {
1109f6603c60Sopenharmony_ci            console.error('playTimeWithoutCallback play filed,error message is :' + err.message)
1110f6603c60Sopenharmony_ci        })
1111f6603c60Sopenharmony_ci        let execution = parseInt(end - start)
1112f6603c60Sopenharmony_ci        console.info("playTimeWithoutCallback execution time  is :" + execution)
1113f6603c60Sopenharmony_ci        totalTime = totalTime + execution;
1114f6603c60Sopenharmony_ci        await avPlayer.release().then(() => {
1115f6603c60Sopenharmony_ci            console.info('playTimeWithoutCallback avPlayer is release')
1116f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
1117f6603c60Sopenharmony_ci            avPlayer = null;
1118f6603c60Sopenharmony_ci        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1119f6603c60Sopenharmony_ci    }
1120f6603c60Sopenharmony_ci    let avg = totalTime/10;
1121f6603c60Sopenharmony_ci    console.info("playTimeWithoutCallback avg time  is :" + avg)
1122f6603c60Sopenharmony_ci    done();
1123f6603c60Sopenharmony_ci}
1124f6603c60Sopenharmony_ci
1125f6603c60Sopenharmony_ciexport async function playTimeWithCallback(src, avPlayer, done) {
1126f6603c60Sopenharmony_ci    avPlayer = await idle(src, avPlayer)
1127f6603c60Sopenharmony_ci    await playTimeCallback(avPlayer, done)
1128f6603c60Sopenharmony_ci    await setSource(avPlayer, src);
1129f6603c60Sopenharmony_ci}
1130f6603c60Sopenharmony_ci
1131f6603c60Sopenharmony_ciexport function playTimeCallback(avPlayer, done) {
1132f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
1133f6603c60Sopenharmony_ci    let start;
1134f6603c60Sopenharmony_ci    let end;
1135f6603c60Sopenharmony_ci    let execution;
1136f6603c60Sopenharmony_ci    let loopTime = 0;
1137f6603c60Sopenharmony_ci    let totalTime = 0;
1138f6603c60Sopenharmony_ci    console.info(`case setCallback in, surfaceID is ${surfaceID}`);
1139f6603c60Sopenharmony_ci    avPlayer.on('stateChange', async (state, reason) => {
1140f6603c60Sopenharmony_ci        console.info(`case stateChange called, state is ${state}, reason is ${reason}`);
1141f6603c60Sopenharmony_ci        console.info(`case state is ${state}`);
1142f6603c60Sopenharmony_ci        switch (state) {
1143f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.INITIALIZED:
1144f6603c60Sopenharmony_ci                avPlayer.surfaceId = surfaceID;
1145f6603c60Sopenharmony_ci                console.info('playTimeCallback play state is INITIALIZED')
1146f6603c60Sopenharmony_ci            // step 1: initialized -> prepared
1147f6603c60Sopenharmony_ci                avPlayer.prepare((err) => {
1148f6603c60Sopenharmony_ci                    if (err != null) {
1149f6603c60Sopenharmony_ci                        console.error(`case prepare error, errMessage is ${err.message}`);
1150f6603c60Sopenharmony_ci                        expect().assertFail();
1151f6603c60Sopenharmony_ci                        done();
1152f6603c60Sopenharmony_ci                    } else {
1153f6603c60Sopenharmony_ci                        console.info('playTimeCallback play state is prepared')
1154f6603c60Sopenharmony_ci                    }
1155f6603c60Sopenharmony_ci                });
1156f6603c60Sopenharmony_ci                break;
1157f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PREPARED:
1158f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
1159f6603c60Sopenharmony_ci                console.info('playTimeCallback avPlayer state is prepared')
1160f6603c60Sopenharmony_ci                start = Date.now();
1161f6603c60Sopenharmony_ci                console.info(`playTimeCallback start time is : ${start}`)
1162f6603c60Sopenharmony_ci            // step 2: prapared -> play
1163f6603c60Sopenharmony_ci                avPlayer.play()
1164f6603c60Sopenharmony_ci                break;
1165f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PLAYING:
1166f6603c60Sopenharmony_ci                console.info('playTimeCallback play state is PLAYING')
1167f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
1168f6603c60Sopenharmony_ci                end = Date.now();
1169f6603c60Sopenharmony_ci                console.info(`playTimeCallback end time is : ${end}`)
1170f6603c60Sopenharmony_ci                execution = parseInt(end - start)
1171f6603c60Sopenharmony_ci                console.info("playTimeCallback execution time  is :" + execution)
1172f6603c60Sopenharmony_ci                totalTime = totalTime + execution;
1173f6603c60Sopenharmony_ci                loopTime++;
1174f6603c60Sopenharmony_ci                if(loopTime == 10){
1175f6603c60Sopenharmony_ci                    avPlayer.release().then(() => {
1176f6603c60Sopenharmony_ci                        console.info('playTimeCallback avPlayer is release')
1177f6603c60Sopenharmony_ci                        expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
1178f6603c60Sopenharmony_ci                        avPlayer = null;
1179f6603c60Sopenharmony_ci                        let avg = totalTime/10;
1180f6603c60Sopenharmony_ci                        console.info("playTimeWithCallback avg time is :" + avg)
1181f6603c60Sopenharmony_ci                        done();
1182f6603c60Sopenharmony_ci                    }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1183f6603c60Sopenharmony_ci                }else{
1184f6603c60Sopenharmony_ci            // step 3: playing -> pause loop
1185f6603c60Sopenharmony_ci                    setTimeout( () => {
1186f6603c60Sopenharmony_ci                        avPlayer.pause()
1187f6603c60Sopenharmony_ci                    }, 200);
1188f6603c60Sopenharmony_ci                }
1189f6603c60Sopenharmony_ci                break;
1190f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PAUSED:
1191f6603c60Sopenharmony_ci                console.info('playTimeWithCallback play state is PAUSED')
1192f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual('paused');
1193f6603c60Sopenharmony_ci                start = Date.now();
1194f6603c60Sopenharmony_ci                console.info(`playTimeCallback start time is : ${start}`)
1195f6603c60Sopenharmony_ci                avPlayer.play()
1196f6603c60Sopenharmony_ci                break;
1197f6603c60Sopenharmony_ci            default:
1198f6603c60Sopenharmony_ci                break;
1199f6603c60Sopenharmony_ci        }
1200f6603c60Sopenharmony_ci    });
1201f6603c60Sopenharmony_ci}
1202f6603c60Sopenharmony_ci
1203f6603c60Sopenharmony_ciexport async function pauseTimeWithoutCallback(src, avPlayer, done) {
1204f6603c60Sopenharmony_ci    let totalTime = 0;
1205f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
1206f6603c60Sopenharmony_ci    for(var i = 0;i < 10;i++){
1207f6603c60Sopenharmony_ci        let execution;
1208f6603c60Sopenharmony_ci        let end;
1209f6603c60Sopenharmony_ci        avPlayer = await idle(src, avPlayer)
1210f6603c60Sopenharmony_ci        await setSource(avPlayer, src);
1211f6603c60Sopenharmony_ci        console.info('pauseTimeWithoutCallback setSource');
1212f6603c60Sopenharmony_ci        await sleep(20)
1213f6603c60Sopenharmony_ci        avPlayer.surfaceId = surfaceID;
1214f6603c60Sopenharmony_ci        await avPlayer.prepare().then(() => {
1215f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
1216f6603c60Sopenharmony_ci            console.info('pauseTimeWithoutCallback avPlayer state is prepared')
1217f6603c60Sopenharmony_ci        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1218f6603c60Sopenharmony_ci        await avPlayer.play().then(() => {
1219f6603c60Sopenharmony_ci            console.info('pauseTimeWithoutCallback play success');
1220f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
1221f6603c60Sopenharmony_ci        }, (err) => {
1222f6603c60Sopenharmony_ci            console.error('pauseTimeWithoutCallback play filed,error message is :' + err.message)
1223f6603c60Sopenharmony_ci        })
1224f6603c60Sopenharmony_ci        let start = Date.now();
1225f6603c60Sopenharmony_ci
1226f6603c60Sopenharmony_ci        console.info(`pauseTimeWithoutCallback start time is : ${start}`)
1227f6603c60Sopenharmony_ci        await avPlayer.pause().then(() => {
1228f6603c60Sopenharmony_ci            console.info('pauseTimeWithoutCallback pause success');
1229f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PAUSED);
1230f6603c60Sopenharmony_ci            end = Date.now();
1231f6603c60Sopenharmony_ci            console.info(`pauseTimeWithoutCallback end time is : ${end}`)
1232f6603c60Sopenharmony_ci            execution = parseInt(end - start)
1233f6603c60Sopenharmony_ci            console.info("pauseTimeWithoutCallback execution time  is :" + execution)
1234f6603c60Sopenharmony_ci        }, (err) => {
1235f6603c60Sopenharmony_ci            console.error('pauseTimeWithoutCallback pause filed,error message is :' + err.message)
1236f6603c60Sopenharmony_ci        })
1237f6603c60Sopenharmony_ci        totalTime = totalTime + execution;
1238f6603c60Sopenharmony_ci        await avPlayer.release().then(() => {
1239f6603c60Sopenharmony_ci            console.info('pauseTimeWithoutCallback avPlayer is release')
1240f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
1241f6603c60Sopenharmony_ci        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1242f6603c60Sopenharmony_ci    }
1243f6603c60Sopenharmony_ci    let avg = totalTime/10;
1244f6603c60Sopenharmony_ci    console.info("pauseTimeWithoutCallback avg time  is :" + avg)
1245f6603c60Sopenharmony_ci    done();
1246f6603c60Sopenharmony_ci}
1247f6603c60Sopenharmony_ci
1248f6603c60Sopenharmony_ciexport async function pauseTimeWithCallback(src, avPlayer, done) {
1249f6603c60Sopenharmony_ci    avPlayer = await idle(src, avPlayer)
1250f6603c60Sopenharmony_ci    await pauseTimeCallback(avPlayer, done)
1251f6603c60Sopenharmony_ci    await setSource(avPlayer, src);
1252f6603c60Sopenharmony_ci}
1253f6603c60Sopenharmony_ci
1254f6603c60Sopenharmony_cifunction pauseTimeCallback(avPlayer, done) {
1255f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
1256f6603c60Sopenharmony_ci    let start;
1257f6603c60Sopenharmony_ci    let end;
1258f6603c60Sopenharmony_ci    let execution;
1259f6603c60Sopenharmony_ci    let loopTime = 0;
1260f6603c60Sopenharmony_ci    let totalTime = 0;
1261f6603c60Sopenharmony_ci    console.info(`case setCallback in, surfaceID is ${surfaceID}`);
1262f6603c60Sopenharmony_ci    avPlayer.on('stateChange', async (state, reason) => {
1263f6603c60Sopenharmony_ci        console.info(`case stateChange called, state is ${state}, reason is ${reason}`);
1264f6603c60Sopenharmony_ci        console.info(`case state is ${state}`);
1265f6603c60Sopenharmony_ci        switch (state) {
1266f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.INITIALIZED:
1267f6603c60Sopenharmony_ci                avPlayer.surfaceId = surfaceID;
1268f6603c60Sopenharmony_ci                console.info('pauseTimeCallback play state is INITIALIZED')
1269f6603c60Sopenharmony_ci            // step 1: initialized -> prepared
1270f6603c60Sopenharmony_ci                avPlayer.prepare((err) => {
1271f6603c60Sopenharmony_ci                    if (err != null) {
1272f6603c60Sopenharmony_ci                        console.error(`case prepare error, errMessage is ${err.message}`);
1273f6603c60Sopenharmony_ci                        expect().assertFail();
1274f6603c60Sopenharmony_ci                        done();
1275f6603c60Sopenharmony_ci                    } else {
1276f6603c60Sopenharmony_ci                        console.info('pauseTimeCallback play state is prepared')
1277f6603c60Sopenharmony_ci                    }
1278f6603c60Sopenharmony_ci                });
1279f6603c60Sopenharmony_ci                break;
1280f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PREPARED:
1281f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
1282f6603c60Sopenharmony_ci                console.info('pauseTimeCallback avPlayer state is prepared')
1283f6603c60Sopenharmony_ci                avPlayer.play()
1284f6603c60Sopenharmony_ci                break;
1285f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PLAYING:
1286f6603c60Sopenharmony_ci                console.info('pauseTimeCallback play state is PLAYING')
1287f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
1288f6603c60Sopenharmony_ci                setTimeout( () => {
1289f6603c60Sopenharmony_ci                    start = Date.now();
1290f6603c60Sopenharmony_ci                    console.info(`pauseTimeCallback start time is : ${start}`)
1291f6603c60Sopenharmony_ci                    avPlayer.pause()
1292f6603c60Sopenharmony_ci                }, 200);
1293f6603c60Sopenharmony_ci                break;
1294f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PAUSED:
1295f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PAUSED);
1296f6603c60Sopenharmony_ci                end = Date.now();
1297f6603c60Sopenharmony_ci                console.info(`pauseTimeCallback end time is : ${end}`)
1298f6603c60Sopenharmony_ci                execution = parseInt(end - start)
1299f6603c60Sopenharmony_ci                console.info("pauseTimeCallback execution time  is :" + execution)
1300f6603c60Sopenharmony_ci                totalTime = totalTime + execution;
1301f6603c60Sopenharmony_ci                loopTime++;
1302f6603c60Sopenharmony_ci                if(loopTime == 10){
1303f6603c60Sopenharmony_ci                    avPlayer.release().then(() => {
1304f6603c60Sopenharmony_ci                        console.info('pauseTimeCallback avPlayer is release')
1305f6603c60Sopenharmony_ci                        expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
1306f6603c60Sopenharmony_ci                        avPlayer = null;
1307f6603c60Sopenharmony_ci                        let avg = totalTime/10;
1308f6603c60Sopenharmony_ci                        console.info("pauseTimeCallback avg time is :" + avg)
1309f6603c60Sopenharmony_ci                        done();
1310f6603c60Sopenharmony_ci                    }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1311f6603c60Sopenharmony_ci                }else{
1312f6603c60Sopenharmony_ci                    avPlayer.play()
1313f6603c60Sopenharmony_ci                }
1314f6603c60Sopenharmony_ci                break;
1315f6603c60Sopenharmony_ci            default:
1316f6603c60Sopenharmony_ci                break;
1317f6603c60Sopenharmony_ci        }
1318f6603c60Sopenharmony_ci    });
1319f6603c60Sopenharmony_ci}
1320f6603c60Sopenharmony_ci
1321f6603c60Sopenharmony_ciexport async function stopTimeWithoutCallback(src, avPlayer, done) {
1322f6603c60Sopenharmony_ci    let totalTime = 0;
1323f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
1324f6603c60Sopenharmony_ci    for(var i = 0;i < 10;i++){
1325f6603c60Sopenharmony_ci        avPlayer = await idle(src, avPlayer)
1326f6603c60Sopenharmony_ci        await setSource(avPlayer, src);
1327f6603c60Sopenharmony_ci        console.info('stopTimeWithoutCallback setSource');
1328f6603c60Sopenharmony_ci        await sleep(20)
1329f6603c60Sopenharmony_ci        avPlayer.surfaceId = surfaceID;
1330f6603c60Sopenharmony_ci        await avPlayer.prepare().then(() => {
1331f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
1332f6603c60Sopenharmony_ci            console.info('stopTimeWithoutCallback avPlayer state is prepared')
1333f6603c60Sopenharmony_ci        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1334f6603c60Sopenharmony_ci        await avPlayer.play().then(() => {
1335f6603c60Sopenharmony_ci            console.info('stopTimeWithoutCallback play success');
1336f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
1337f6603c60Sopenharmony_ci        }, (err) => {
1338f6603c60Sopenharmony_ci            console.error('stopTimeWithoutCallback play filed,error message is :' + err.message)
1339f6603c60Sopenharmony_ci        })
1340f6603c60Sopenharmony_ci        let start = Date.now();
1341f6603c60Sopenharmony_ci        console.info(`stopTimeWithoutCallback start time is : ${start}`)
1342f6603c60Sopenharmony_ci        let end;
1343f6603c60Sopenharmony_ci        await avPlayer.stop().then(() => {
1344f6603c60Sopenharmony_ci            end = Date.now();
1345f6603c60Sopenharmony_ci            console.info(`stopTimeWithoutCallback end time is : ${end}`)
1346f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.STOPPED);
1347f6603c60Sopenharmony_ci            console.info('stopTimeWithoutCallback avPlayer state is stop')
1348f6603c60Sopenharmony_ci        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1349f6603c60Sopenharmony_ci        let execution = parseInt(end - start)
1350f6603c60Sopenharmony_ci        console.info("stopTimeWithoutCallback execution time  is :" + execution)
1351f6603c60Sopenharmony_ci        totalTime = totalTime + execution;
1352f6603c60Sopenharmony_ci        await avPlayer.release().then(() => {
1353f6603c60Sopenharmony_ci            console.info('stopTimeWithoutCallback avPlayer is release')
1354f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
1355f6603c60Sopenharmony_ci        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1356f6603c60Sopenharmony_ci    }
1357f6603c60Sopenharmony_ci    let avg = totalTime/10;
1358f6603c60Sopenharmony_ci    console.info("stopTimeWithoutCallback avg time  is :" + avg)
1359f6603c60Sopenharmony_ci    done();
1360f6603c60Sopenharmony_ci}
1361f6603c60Sopenharmony_ci
1362f6603c60Sopenharmony_ciexport async function stopTimeWithCallback(src, avPlayer, done) {
1363f6603c60Sopenharmony_ci    avPlayer = await idle(src, avPlayer)
1364f6603c60Sopenharmony_ci    await stopTimeCallback(src, avPlayer, done)
1365f6603c60Sopenharmony_ci    await setSource(avPlayer, src);
1366f6603c60Sopenharmony_ci}
1367f6603c60Sopenharmony_ci
1368f6603c60Sopenharmony_cifunction stopTimeCallback(src, avPlayer, done) {
1369f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
1370f6603c60Sopenharmony_ci    let start;
1371f6603c60Sopenharmony_ci    let end;
1372f6603c60Sopenharmony_ci    let execution;
1373f6603c60Sopenharmony_ci    let loopTime = 0;
1374f6603c60Sopenharmony_ci    let totalTime = 0;
1375f6603c60Sopenharmony_ci    console.info(`case setCallback in, surfaceID is ${surfaceID}`);
1376f6603c60Sopenharmony_ci    avPlayer.on('stateChange', async (state, reason) => {
1377f6603c60Sopenharmony_ci        console.info(`case stateChange called, state is ${state}, reason is ${reason}`);
1378f6603c60Sopenharmony_ci        console.info(`case state is ${state}`);
1379f6603c60Sopenharmony_ci        switch (state) {
1380f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.IDLE:
1381f6603c60Sopenharmony_ci                setSource(avPlayer, src);
1382f6603c60Sopenharmony_ci                break;
1383f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.INITIALIZED:
1384f6603c60Sopenharmony_ci                avPlayer.surfaceId = surfaceID;
1385f6603c60Sopenharmony_ci                console.info('stopTimeCallback play state is INITIALIZED')
1386f6603c60Sopenharmony_ci            // step 1: initialized -> prepared
1387f6603c60Sopenharmony_ci                avPlayer.prepare((err) => {
1388f6603c60Sopenharmony_ci                    if (err != null) {
1389f6603c60Sopenharmony_ci                        console.error(`case prepare error, errMessage is ${err.message}`);
1390f6603c60Sopenharmony_ci                        expect().assertFail();
1391f6603c60Sopenharmony_ci                        done();
1392f6603c60Sopenharmony_ci                    } else {
1393f6603c60Sopenharmony_ci                        console.info('stopTimeCallback play state is prepared')
1394f6603c60Sopenharmony_ci                    }
1395f6603c60Sopenharmony_ci                });
1396f6603c60Sopenharmony_ci                break;
1397f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PREPARED:
1398f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
1399f6603c60Sopenharmony_ci                console.info('stopTimeCallback avPlayer state is prepared')
1400f6603c60Sopenharmony_ci                start = Date.now();
1401f6603c60Sopenharmony_ci                console.info(`stopTimeCallback start time is : ${start}`)
1402f6603c60Sopenharmony_ci                loopTime++;
1403f6603c60Sopenharmony_ci                avPlayer.stop()
1404f6603c60Sopenharmony_ci                break;
1405f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.STOPPED:
1406f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.STOPPED);
1407f6603c60Sopenharmony_ci                end = Date.now();
1408f6603c60Sopenharmony_ci                console.info(`stopTimeCallback end time is : ${end}`)
1409f6603c60Sopenharmony_ci                execution = parseInt(end - start)
1410f6603c60Sopenharmony_ci                console.info("stopTimeCallback execution time  is :" + execution)
1411f6603c60Sopenharmony_ci                totalTime = totalTime + execution;
1412f6603c60Sopenharmony_ci                if(loopTime == 10){
1413f6603c60Sopenharmony_ci                    avPlayer.release().then(() => {
1414f6603c60Sopenharmony_ci                        console.info('stopTimeCallback avPlayer is release')
1415f6603c60Sopenharmony_ci                        expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
1416f6603c60Sopenharmony_ci                        avPlayer = null;
1417f6603c60Sopenharmony_ci                        let avg = totalTime/10;
1418f6603c60Sopenharmony_ci                        console.info("stopTimeCallback avg time is :" + avg)
1419f6603c60Sopenharmony_ci                        done();
1420f6603c60Sopenharmony_ci                    }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1421f6603c60Sopenharmony_ci                }else{
1422f6603c60Sopenharmony_ci                    avPlayer.reset()
1423f6603c60Sopenharmony_ci                }
1424f6603c60Sopenharmony_ci                break;
1425f6603c60Sopenharmony_ci            default:
1426f6603c60Sopenharmony_ci                break;
1427f6603c60Sopenharmony_ci        }
1428f6603c60Sopenharmony_ci    });
1429f6603c60Sopenharmony_ci}
1430f6603c60Sopenharmony_ci
1431f6603c60Sopenharmony_ciexport async function resetTimeWithoutCallback(src, avPlayer, done) {
1432f6603c60Sopenharmony_ci    let totalTime = 0;
1433f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
1434f6603c60Sopenharmony_ci    for(var i = 0;i < 10;i++){
1435f6603c60Sopenharmony_ci        avPlayer = await idle(src, avPlayer)
1436f6603c60Sopenharmony_ci        await setSource(avPlayer, src);
1437f6603c60Sopenharmony_ci        console.info('resetTimeWithoutCallback setSource');
1438f6603c60Sopenharmony_ci        await sleep(20)
1439f6603c60Sopenharmony_ci        avPlayer.surfaceId = surfaceID;
1440f6603c60Sopenharmony_ci        await avPlayer.prepare().then(() => {
1441f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
1442f6603c60Sopenharmony_ci            console.info('resetTimeWithoutCallback avPlayer state is prepared')
1443f6603c60Sopenharmony_ci        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1444f6603c60Sopenharmony_ci        let end;
1445f6603c60Sopenharmony_ci        await avPlayer.play().then(() => {
1446f6603c60Sopenharmony_ci            console.info('resetTimeWithoutCallback play success');
1447f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
1448f6603c60Sopenharmony_ci        }, (err) => {
1449f6603c60Sopenharmony_ci            console.error('resetTimeWithoutCallback play filed,error message is :' + err.message)
1450f6603c60Sopenharmony_ci        })
1451f6603c60Sopenharmony_ci        let start = Date.now();
1452f6603c60Sopenharmony_ci        console.info(`resetTimeWithoutCallback start time is : ${start}`)
1453f6603c60Sopenharmony_ci        await avPlayer.reset().then(() => {
1454f6603c60Sopenharmony_ci            end = Date.now();
1455f6603c60Sopenharmony_ci            console.info(`resetTimeWithoutCallback end time is : ${end}`)
1456f6603c60Sopenharmony_ci            console.info('reset success');
1457f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.IDLE);
1458f6603c60Sopenharmony_ci        }, (err) => {
1459f6603c60Sopenharmony_ci            console.error('reset filed,error message is :' + err.message)
1460f6603c60Sopenharmony_ci        })
1461f6603c60Sopenharmony_ci        let execution = parseInt(end - start)
1462f6603c60Sopenharmony_ci        console.info("resetTimeWithoutCallback execution time  is :" + execution)
1463f6603c60Sopenharmony_ci        totalTime = totalTime + execution;
1464f6603c60Sopenharmony_ci        await avPlayer.release().then(() => {
1465f6603c60Sopenharmony_ci            console.info('resetTimeWithoutCallback avPlayer is release')
1466f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
1467f6603c60Sopenharmony_ci        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1468f6603c60Sopenharmony_ci    }
1469f6603c60Sopenharmony_ci    let avg = totalTime/10;
1470f6603c60Sopenharmony_ci    console.info("resetTimeWithoutCallback avg time  is :" + avg)
1471f6603c60Sopenharmony_ci    done();
1472f6603c60Sopenharmony_ci}
1473f6603c60Sopenharmony_ci
1474f6603c60Sopenharmony_ciexport async function resetTimeWithCallback(src, avPlayer, done) {
1475f6603c60Sopenharmony_ci    avPlayer = await idle(src, avPlayer)
1476f6603c60Sopenharmony_ci    await resetTimeCallback(src, avPlayer, done)
1477f6603c60Sopenharmony_ci    await setSource(avPlayer, src);
1478f6603c60Sopenharmony_ci}
1479f6603c60Sopenharmony_ci
1480f6603c60Sopenharmony_cifunction resetTimeCallback(src, avPlayer, done) {
1481f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
1482f6603c60Sopenharmony_ci    let start;
1483f6603c60Sopenharmony_ci    let end;
1484f6603c60Sopenharmony_ci    let execution;
1485f6603c60Sopenharmony_ci    let loopTime = 0;
1486f6603c60Sopenharmony_ci    let totalTime = 0;
1487f6603c60Sopenharmony_ci    console.info(`case setCallback in, surfaceID is ${surfaceID}`);
1488f6603c60Sopenharmony_ci    avPlayer.on('stateChange', async (state, reason) => {
1489f6603c60Sopenharmony_ci        console.info(`case stateChange called, state is ${state}, reason is ${reason}`);
1490f6603c60Sopenharmony_ci        console.info(`case state is ${state}`);
1491f6603c60Sopenharmony_ci        switch (state) {
1492f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.IDLE:
1493f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.IDLE);
1494f6603c60Sopenharmony_ci                end = Date.now();
1495f6603c60Sopenharmony_ci                console.info(`resetTimeCallback end time is : ${end}`)
1496f6603c60Sopenharmony_ci                execution = parseInt(end - start)
1497f6603c60Sopenharmony_ci                console.info("resetTimeCallback execution time  is :" + execution)
1498f6603c60Sopenharmony_ci                totalTime = totalTime + execution;
1499f6603c60Sopenharmony_ci                loopTime++;
1500f6603c60Sopenharmony_ci                if(loopTime == 10){
1501f6603c60Sopenharmony_ci                    avPlayer.release().then(() => {
1502f6603c60Sopenharmony_ci                        console.info('resetTimeCallback avPlayer is release')
1503f6603c60Sopenharmony_ci                        expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
1504f6603c60Sopenharmony_ci                        avPlayer = null;
1505f6603c60Sopenharmony_ci                        let avg = totalTime/10;
1506f6603c60Sopenharmony_ci                        console.info("resetTimeCallback avg time is :" + avg)
1507f6603c60Sopenharmony_ci                        done();
1508f6603c60Sopenharmony_ci                    }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1509f6603c60Sopenharmony_ci                }else{
1510f6603c60Sopenharmony_ci                    setSource(avPlayer, src)
1511f6603c60Sopenharmony_ci                }
1512f6603c60Sopenharmony_ci                break;
1513f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.INITIALIZED:
1514f6603c60Sopenharmony_ci                avPlayer.surfaceId = surfaceID;
1515f6603c60Sopenharmony_ci                console.info('resetTimeCallback play state is INITIALIZED')
1516f6603c60Sopenharmony_ci                start = Date.now();
1517f6603c60Sopenharmony_ci                console.info(`resetTimeCallback start time is : ${start}`)
1518f6603c60Sopenharmony_ci                avPlayer.reset().then(() => {
1519f6603c60Sopenharmony_ci                    console.info('reset success');
1520f6603c60Sopenharmony_ci                }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1521f6603c60Sopenharmony_ci                break;
1522f6603c60Sopenharmony_ci            default:
1523f6603c60Sopenharmony_ci                break;
1524f6603c60Sopenharmony_ci        }
1525f6603c60Sopenharmony_ci    });
1526f6603c60Sopenharmony_ci}
1527f6603c60Sopenharmony_ci
1528f6603c60Sopenharmony_ciexport async function releaseTimeWithoutCallback(src, avPlayer, done) {
1529f6603c60Sopenharmony_ci    let totalTime = 0;
1530f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
1531f6603c60Sopenharmony_ci    for(var i = 0;i < 10;i++){
1532f6603c60Sopenharmony_ci        avPlayer = await idle(src, avPlayer)
1533f6603c60Sopenharmony_ci        await setSource(avPlayer, src);
1534f6603c60Sopenharmony_ci        console.info('releaseTimeWithoutCallback setSource');
1535f6603c60Sopenharmony_ci        await sleep(20)
1536f6603c60Sopenharmony_ci        avPlayer.surfaceId = surfaceID;
1537f6603c60Sopenharmony_ci        let start = Date.now();
1538f6603c60Sopenharmony_ci        console.info(`releaseTimeWithoutCallback start time is : ${start}`)
1539f6603c60Sopenharmony_ci        let end;
1540f6603c60Sopenharmony_ci        await avPlayer.release().then(() => {
1541f6603c60Sopenharmony_ci            console.info('releaseTimeWithoutCallback avPlayer is release')
1542f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
1543f6603c60Sopenharmony_ci        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1544f6603c60Sopenharmony_ci        end = Date.now();
1545f6603c60Sopenharmony_ci        console.info(`releaseTimeWithoutCallback end time is : ${end}`)
1546f6603c60Sopenharmony_ci        let execution = parseInt(end - start)
1547f6603c60Sopenharmony_ci        console.info("releaseTimeWithoutCallback execution time  is :" + execution)
1548f6603c60Sopenharmony_ci        totalTime = totalTime + execution;
1549f6603c60Sopenharmony_ci    }
1550f6603c60Sopenharmony_ci    let avg = totalTime/10;
1551f6603c60Sopenharmony_ci    console.info("releaseTimeWithoutCallback avg time  is :" + avg)
1552f6603c60Sopenharmony_ci    done();
1553f6603c60Sopenharmony_ci}
1554f6603c60Sopenharmony_ci
1555f6603c60Sopenharmony_cilet releaseTotalTime = 0;
1556f6603c60Sopenharmony_cilet releaseLoop = 0;
1557f6603c60Sopenharmony_ciexport async function releaseTimeWithCallback(src, avPlayer, done) {
1558f6603c60Sopenharmony_ci    avPlayer = await idle(src, avPlayer)
1559f6603c60Sopenharmony_ci    await releaseTimeCallback(src, avPlayer, done)
1560f6603c60Sopenharmony_ci    await setSource(avPlayer, src);
1561f6603c60Sopenharmony_ci}
1562f6603c60Sopenharmony_ci
1563f6603c60Sopenharmony_cifunction releaseTimeCallback(src, avPlayer, done) {
1564f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
1565f6603c60Sopenharmony_ci    let start;
1566f6603c60Sopenharmony_ci    let end;
1567f6603c60Sopenharmony_ci    let execution;
1568f6603c60Sopenharmony_ci    console.info(`case setCallback in, surfaceID is ${surfaceID}`);
1569f6603c60Sopenharmony_ci    avPlayer.on('stateChange', async (state, reason) => {
1570f6603c60Sopenharmony_ci        console.info(`case stateChange called, state is ${state}, reason is ${reason}`);
1571f6603c60Sopenharmony_ci        console.info(`case state is ${state}`);
1572f6603c60Sopenharmony_ci        switch (state) {
1573f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.INITIALIZED:
1574f6603c60Sopenharmony_ci                avPlayer.surfaceId = surfaceID;
1575f6603c60Sopenharmony_ci                console.info('releaseTimeCallback play state is INITIALIZED')
1576f6603c60Sopenharmony_ci                start = Date.now();
1577f6603c60Sopenharmony_ci                console.info(`releaseTimeCallback start time is : ${start}`)
1578f6603c60Sopenharmony_ci                avPlayer.release()
1579f6603c60Sopenharmony_ci                break;
1580f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.RELEASED:
1581f6603c60Sopenharmony_ci                console.info('releaseTimeCallback play state is release')
1582f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
1583f6603c60Sopenharmony_ci                end = Date.now();
1584f6603c60Sopenharmony_ci                console.info(`releaseTimeCallback end time is : ${end}`)
1585f6603c60Sopenharmony_ci                execution = parseInt(end - start)
1586f6603c60Sopenharmony_ci                console.info("releaseTimeCallback execution time  is :" + execution)
1587f6603c60Sopenharmony_ci                releaseTotalTime = releaseTotalTime + execution;
1588f6603c60Sopenharmony_ci                releaseLoop++;
1589f6603c60Sopenharmony_ci                if(releaseLoop == 10){
1590f6603c60Sopenharmony_ci                    let avg = releaseTotalTime/10;
1591f6603c60Sopenharmony_ci                    console.info("releaseTimeCallback avg time  is :" + avg)
1592f6603c60Sopenharmony_ci                    releaseTotalTime = 0;
1593f6603c60Sopenharmony_ci                    releaseLoop = 0;
1594f6603c60Sopenharmony_ci                    done();
1595f6603c60Sopenharmony_ci                }else{
1596f6603c60Sopenharmony_ci                    avPlayer = null;
1597f6603c60Sopenharmony_ci                    releaseTimeWithCallback(src, avPlayer, done)
1598f6603c60Sopenharmony_ci                }
1599f6603c60Sopenharmony_ci                break;
1600f6603c60Sopenharmony_ci            default:
1601f6603c60Sopenharmony_ci                break;
1602f6603c60Sopenharmony_ci        }
1603f6603c60Sopenharmony_ci    });
1604f6603c60Sopenharmony_ci}
1605f6603c60Sopenharmony_ci
1606f6603c60Sopenharmony_ciexport function getTotalTime(releaseTotalTime){
1607f6603c60Sopenharmony_ci    return releaseTotalTime;
1608f6603c60Sopenharmony_ci}
1609f6603c60Sopenharmony_ci
1610f6603c60Sopenharmony_ciexport async function seekTimeWithoutCallback(src, avPlayer, done) {
1611f6603c60Sopenharmony_ci    let totalTime = 0;
1612f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
1613f6603c60Sopenharmony_ci    for(var i = 0;i < 10;i++){
1614f6603c60Sopenharmony_ci        avPlayer = await idle(src, avPlayer)
1615f6603c60Sopenharmony_ci        await setSource(avPlayer, src);
1616f6603c60Sopenharmony_ci        console.info('seekTimeWithoutCallback setSource');
1617f6603c60Sopenharmony_ci        await sleep(20)
1618f6603c60Sopenharmony_ci        avPlayer.surfaceId = surfaceID;
1619f6603c60Sopenharmony_ci        await avPlayer.prepare().then(() => {
1620f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
1621f6603c60Sopenharmony_ci            console.info('seekTimeWithoutCallback avPlayer state is prepared')
1622f6603c60Sopenharmony_ci        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1623f6603c60Sopenharmony_ci        let end;
1624f6603c60Sopenharmony_ci        await avPlayer.play().then(() => {
1625f6603c60Sopenharmony_ci            console.info('seekTimeWithoutCallback play success');
1626f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
1627f6603c60Sopenharmony_ci        }, (err) => {
1628f6603c60Sopenharmony_ci            console.error('seekTimeWithoutCallback play filed,error message is :' + err.message)
1629f6603c60Sopenharmony_ci        })
1630f6603c60Sopenharmony_ci        let start = Date.now();
1631f6603c60Sopenharmony_ci        console.info(`seekTimeWithoutCallback start time is : ${start}`)
1632f6603c60Sopenharmony_ci        await avPlayer.seek(100)
1633f6603c60Sopenharmony_ci        end = Date.now();
1634f6603c60Sopenharmony_ci        console.info(`seekTimeWithoutCallback end time is : ${end}`)
1635f6603c60Sopenharmony_ci        let execution = parseInt(end - start)
1636f6603c60Sopenharmony_ci        console.info("seekTimeWithoutCallback execution time  is :" + execution)
1637f6603c60Sopenharmony_ci        totalTime = totalTime + execution;
1638f6603c60Sopenharmony_ci        await avPlayer.release().then(() => {
1639f6603c60Sopenharmony_ci            console.info('seekTimeWithoutCallback avPlayer is release')
1640f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
1641f6603c60Sopenharmony_ci        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1642f6603c60Sopenharmony_ci    }
1643f6603c60Sopenharmony_ci    let avg = totalTime/10;
1644f6603c60Sopenharmony_ci    console.info("seekTimeWithoutCallback avg time  is :" + avg)
1645f6603c60Sopenharmony_ci    done();
1646f6603c60Sopenharmony_ci}
1647f6603c60Sopenharmony_ci
1648f6603c60Sopenharmony_ciexport async function seekTimeWithCallback(src, avPlayer, done) {
1649f6603c60Sopenharmony_ci    avPlayer = await idle(src, avPlayer)
1650f6603c60Sopenharmony_ci    await seekTimeCallback(avPlayer, done)
1651f6603c60Sopenharmony_ci    await setSource(avPlayer, src);
1652f6603c60Sopenharmony_ci}
1653f6603c60Sopenharmony_ci
1654f6603c60Sopenharmony_cifunction seekTimeCallback(avPlayer, done) {
1655f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
1656f6603c60Sopenharmony_ci    let start;
1657f6603c60Sopenharmony_ci    let end;
1658f6603c60Sopenharmony_ci    let execution;
1659f6603c60Sopenharmony_ci    let loopTime = 0;
1660f6603c60Sopenharmony_ci    let totalTime = 0;
1661f6603c60Sopenharmony_ci    console.info(`case setCallback in, surfaceID is ${surfaceID}`);
1662f6603c60Sopenharmony_ci    avPlayer.on('stateChange', async (state, reason) => {
1663f6603c60Sopenharmony_ci        console.info(`case stateChange called, state is ${state}, reason is ${reason}`);
1664f6603c60Sopenharmony_ci        console.info(`case state is ${state}`);
1665f6603c60Sopenharmony_ci        switch (state) {
1666f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.INITIALIZED:
1667f6603c60Sopenharmony_ci                avPlayer.surfaceId = surfaceID;
1668f6603c60Sopenharmony_ci                console.info('seekTimeCallback play state is INITIALIZED')
1669f6603c60Sopenharmony_ci                avPlayer.prepare((err) => {
1670f6603c60Sopenharmony_ci                    if (err != null) {
1671f6603c60Sopenharmony_ci                        console.error(`case prepare error, errMessage is ${err.message}`);
1672f6603c60Sopenharmony_ci                        expect().assertFail();
1673f6603c60Sopenharmony_ci                        done();
1674f6603c60Sopenharmony_ci                    } else {
1675f6603c60Sopenharmony_ci                        console.info('seekTimeCallback play state is prepared')
1676f6603c60Sopenharmony_ci                    }
1677f6603c60Sopenharmony_ci                });
1678f6603c60Sopenharmony_ci                break;
1679f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PREPARED:
1680f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
1681f6603c60Sopenharmony_ci                console.info('seekTimeCallback avPlayer state is prepared')
1682f6603c60Sopenharmony_ci                avPlayer.play()
1683f6603c60Sopenharmony_ci                break;
1684f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PLAYING:
1685f6603c60Sopenharmony_ci                console.info('seekTimeCallback play state is PLAYING')
1686f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
1687f6603c60Sopenharmony_ci                start = Date.now();
1688f6603c60Sopenharmony_ci                console.info(`seekTimeCallback start time is : ${start}`)
1689f6603c60Sopenharmony_ci                loopTime+=20;
1690f6603c60Sopenharmony_ci                if(loopTime == 220){
1691f6603c60Sopenharmony_ci                    avPlayer.release().then(() => {
1692f6603c60Sopenharmony_ci                        console.info('seekTimeCallback avPlayer is release')
1693f6603c60Sopenharmony_ci                        expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
1694f6603c60Sopenharmony_ci                        avPlayer = null;
1695f6603c60Sopenharmony_ci                        let avg = totalTime/10;
1696f6603c60Sopenharmony_ci                        console.info("seekTimeCallback avg time is :" + avg)
1697f6603c60Sopenharmony_ci                        done();
1698f6603c60Sopenharmony_ci                    }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1699f6603c60Sopenharmony_ci                }else{
1700f6603c60Sopenharmony_ci                    avPlayer.seek(loopTime)
1701f6603c60Sopenharmony_ci                }
1702f6603c60Sopenharmony_ci                break;
1703f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PAUSED:
1704f6603c60Sopenharmony_ci                console.info('seekTimeCallback play state is PAUSED')
1705f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PAUSED);
1706f6603c60Sopenharmony_ci                avPlayer.play().then(() => {
1707f6603c60Sopenharmony_ci                    console.info('seekTimeCallback avPlayer from pause to play')
1708f6603c60Sopenharmony_ci                }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1709f6603c60Sopenharmony_ci                break;
1710f6603c60Sopenharmony_ci            default:
1711f6603c60Sopenharmony_ci                break;
1712f6603c60Sopenharmony_ci        }
1713f6603c60Sopenharmony_ci    });
1714f6603c60Sopenharmony_ci    avPlayer.on('seekDone', async (seekDoneTime) => {
1715f6603c60Sopenharmony_ci        end = Date.now();
1716f6603c60Sopenharmony_ci        console.info(`seekTimeCallback end time is : ${end}`)
1717f6603c60Sopenharmony_ci        execution = parseInt(end - start)
1718f6603c60Sopenharmony_ci        console.info("seekTimeCallback execution time  is :" + execution)
1719f6603c60Sopenharmony_ci        totalTime = totalTime + execution;
1720f6603c60Sopenharmony_ci        console.info(`case seekDone called seekDoneTime is ${seekDoneTime}`);
1721f6603c60Sopenharmony_ci        avPlayer.pause()
1722f6603c60Sopenharmony_ci    });
1723f6603c60Sopenharmony_ci}
1724f6603c60Sopenharmony_ci
1725f6603c60Sopenharmony_ciexport async function getTrackDescriptionTimeWithoutCallback(src, avPlayer, done) {
1726f6603c60Sopenharmony_ci    let totalTime = 0;
1727f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
1728f6603c60Sopenharmony_ci    for(var i = 0;i < 10;i++){
1729f6603c60Sopenharmony_ci        avPlayer = await idle(src, avPlayer)
1730f6603c60Sopenharmony_ci        await setSource(avPlayer, src);
1731f6603c60Sopenharmony_ci        console.info('getTrackDescriptionTimeWithoutCallback setSource');
1732f6603c60Sopenharmony_ci        await sleep(20)
1733f6603c60Sopenharmony_ci        avPlayer.surfaceId = surfaceID;
1734f6603c60Sopenharmony_ci        await avPlayer.prepare().then(() => {
1735f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
1736f6603c60Sopenharmony_ci            console.info('getTrackDescriptionTimeWithoutCallback avPlayer state is prepared')
1737f6603c60Sopenharmony_ci        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1738f6603c60Sopenharmony_ci        await avPlayer.play().then(() => {
1739f6603c60Sopenharmony_ci            console.info('getTrackDescriptionTimeWithoutCallback play success');
1740f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
1741f6603c60Sopenharmony_ci        }, (err) => {
1742f6603c60Sopenharmony_ci            console.error('getTrackDescriptionTimeWithoutCallback play filed,error message is :' + err.message)
1743f6603c60Sopenharmony_ci        })
1744f6603c60Sopenharmony_ci        let arrayDescription;
1745f6603c60Sopenharmony_ci        let start = Date.now();
1746f6603c60Sopenharmony_ci        console.info(`getTrackDescriptionTimeWithoutCallback start time is : ${start}`)
1747f6603c60Sopenharmony_ci        let end;
1748f6603c60Sopenharmony_ci        await avPlayer.getTrackDescription().then((arrList) => {
1749f6603c60Sopenharmony_ci            if (arrList != null) {
1750f6603c60Sopenharmony_ci                arrayDescription = arrList;
1751f6603c60Sopenharmony_ci            } else {
1752f6603c60Sopenharmony_ci                console.log('video getTrackDescription fail');
1753f6603c60Sopenharmony_ci            }
1754f6603c60Sopenharmony_ci        }).catch((error) => {
1755f6603c60Sopenharmony_ci            console.info(`video catchCallback, error:${error}`);
1756f6603c60Sopenharmony_ci        });
1757f6603c60Sopenharmony_ci        end = Date.now();
1758f6603c60Sopenharmony_ci        console.info(`getTrackDescriptionTimeWithoutCallback end time is : ${end}`)
1759f6603c60Sopenharmony_ci        let execution = parseInt(end - start)
1760f6603c60Sopenharmony_ci        console.info("getTrackDescriptionTimeWithoutCallback execution time  is :" + execution)
1761f6603c60Sopenharmony_ci        totalTime = totalTime + execution;
1762f6603c60Sopenharmony_ci        await avPlayer.release().then(() => {
1763f6603c60Sopenharmony_ci            console.info('getTrackDescriptionTimeWithoutCallback avPlayer is release')
1764f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
1765f6603c60Sopenharmony_ci        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1766f6603c60Sopenharmony_ci    }
1767f6603c60Sopenharmony_ci    let avg = totalTime/10;
1768f6603c60Sopenharmony_ci    console.info("getTrackDescriptionTimeWithoutCallback avg time  is :" + avg)
1769f6603c60Sopenharmony_ci    done();
1770f6603c60Sopenharmony_ci}
1771f6603c60Sopenharmony_ci
1772f6603c60Sopenharmony_ciexport async function getTrackDescriptionTimeWithCallback(src, avPlayer, done) {
1773f6603c60Sopenharmony_ci    avPlayer = await idle(src, avPlayer)
1774f6603c60Sopenharmony_ci    await getTrackDescriptionTimeCallback(avPlayer, done)
1775f6603c60Sopenharmony_ci    await setSource(avPlayer, src);
1776f6603c60Sopenharmony_ci}
1777f6603c60Sopenharmony_ci
1778f6603c60Sopenharmony_cifunction getTrackDescriptionTimeCallback(avPlayer, done) {
1779f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
1780f6603c60Sopenharmony_ci    let start;
1781f6603c60Sopenharmony_ci    let end;
1782f6603c60Sopenharmony_ci    let execution;
1783f6603c60Sopenharmony_ci    let loopTime = 0;
1784f6603c60Sopenharmony_ci    let totalTime = 0;
1785f6603c60Sopenharmony_ci    let arrayDescription;
1786f6603c60Sopenharmony_ci    console.info(`case setCallback in, surfaceID is ${surfaceID}`);
1787f6603c60Sopenharmony_ci    avPlayer.on('stateChange', async (state, reason) => {
1788f6603c60Sopenharmony_ci        console.info(`case stateChange called, state is ${state}, reason is ${reason}`);
1789f6603c60Sopenharmony_ci        console.info(`case state is ${state}`);
1790f6603c60Sopenharmony_ci        switch (state) {
1791f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.INITIALIZED:
1792f6603c60Sopenharmony_ci                avPlayer.surfaceId = surfaceID;
1793f6603c60Sopenharmony_ci                console.info('getTrackDescriptionTimeCallback play state is INITIALIZED')
1794f6603c60Sopenharmony_ci                avPlayer.prepare((err) => {
1795f6603c60Sopenharmony_ci                    if (err != null) {
1796f6603c60Sopenharmony_ci                        console.error(`case prepare error, errMessage is ${err.message}`);
1797f6603c60Sopenharmony_ci                        expect().assertFail();
1798f6603c60Sopenharmony_ci                        done();
1799f6603c60Sopenharmony_ci                    } else {
1800f6603c60Sopenharmony_ci                        console.info('getTrackDescriptionTimeCallback play state is prepared')
1801f6603c60Sopenharmony_ci                    }
1802f6603c60Sopenharmony_ci                });
1803f6603c60Sopenharmony_ci                break;
1804f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PREPARED:
1805f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
1806f6603c60Sopenharmony_ci                console.info('getTrackDescriptionTimeCallback avPlayer state is prepared')
1807f6603c60Sopenharmony_ci                avPlayer.play()
1808f6603c60Sopenharmony_ci                break;
1809f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PLAYING:
1810f6603c60Sopenharmony_ci                console.info('getTrackDescriptionTimeCallback play state is PLAYING')
1811f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
1812f6603c60Sopenharmony_ci                start = Date.now();
1813f6603c60Sopenharmony_ci                console.info(`getTrackDescriptionTimeCallback start time is : ${start}`)
1814f6603c60Sopenharmony_ci                if(loopTime == 10){
1815f6603c60Sopenharmony_ci                    avPlayer.release().then(() => {
1816f6603c60Sopenharmony_ci                        console.info('getTrackDescriptionTimeCallback avPlayer is release')
1817f6603c60Sopenharmony_ci                        expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
1818f6603c60Sopenharmony_ci                        avPlayer = null;
1819f6603c60Sopenharmony_ci                        let avg = totalTime/10;
1820f6603c60Sopenharmony_ci                        console.info("getTrackDescriptionTimeCallback avg time is :" + avg)
1821f6603c60Sopenharmony_ci                        done();
1822f6603c60Sopenharmony_ci                    }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1823f6603c60Sopenharmony_ci                }else{
1824f6603c60Sopenharmony_ci                    loopTime++;
1825f6603c60Sopenharmony_ci                    avPlayer.getTrackDescription().then((arrList) => {
1826f6603c60Sopenharmony_ci                        if (arrList != null) {
1827f6603c60Sopenharmony_ci                            arrayDescription = arrList;
1828f6603c60Sopenharmony_ci                            end = Date.now();
1829f6603c60Sopenharmony_ci                            console.info(`getTrackDescriptionTimeCallback end time is : ${end}`)
1830f6603c60Sopenharmony_ci                            execution = parseInt(end - start)
1831f6603c60Sopenharmony_ci                            console.info("getTrackDescriptionTimeCallback execution time  is :" + execution)
1832f6603c60Sopenharmony_ci                            totalTime = totalTime + execution;
1833f6603c60Sopenharmony_ci
1834f6603c60Sopenharmony_ci                        } else {
1835f6603c60Sopenharmony_ci                            console.log('video getTrackDescription fail');
1836f6603c60Sopenharmony_ci                        }
1837f6603c60Sopenharmony_ci                    }).catch((error) => {
1838f6603c60Sopenharmony_ci                        console.info(`video catchCallback, error:${error}`);
1839f6603c60Sopenharmony_ci                    });
1840f6603c60Sopenharmony_ci                    setTimeout( () => {
1841f6603c60Sopenharmony_ci                        avPlayer.pause()
1842f6603c60Sopenharmony_ci                    }, 200);
1843f6603c60Sopenharmony_ci                }
1844f6603c60Sopenharmony_ci                break;
1845f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PAUSED:
1846f6603c60Sopenharmony_ci                console.info('getTrackDescriptionTimeCallback play state is PAUSED')
1847f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PAUSED);
1848f6603c60Sopenharmony_ci                avPlayer.play().then(() => {
1849f6603c60Sopenharmony_ci                    console.info('getTrackDescriptionTimeCallback avPlayer from pause to play')
1850f6603c60Sopenharmony_ci                }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1851f6603c60Sopenharmony_ci                break;
1852f6603c60Sopenharmony_ci            default:
1853f6603c60Sopenharmony_ci                break;
1854f6603c60Sopenharmony_ci        }
1855f6603c60Sopenharmony_ci    });
1856f6603c60Sopenharmony_ci}
1857f6603c60Sopenharmony_ci
1858f6603c60Sopenharmony_ciexport async function setSpeedTimeWithoutCallback(src, avPlayer, done) {
1859f6603c60Sopenharmony_ci    let totalTime = 0;
1860f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
1861f6603c60Sopenharmony_ci    for(var i = 0;i < 10;i++){
1862f6603c60Sopenharmony_ci        avPlayer = await idle(src, avPlayer)
1863f6603c60Sopenharmony_ci        await setSource(avPlayer, src);
1864f6603c60Sopenharmony_ci        console.info('setSpeedTimeWithoutCallback setSource');
1865f6603c60Sopenharmony_ci        await sleep(20)
1866f6603c60Sopenharmony_ci        avPlayer.surfaceId = surfaceID;
1867f6603c60Sopenharmony_ci        await avPlayer.prepare().then(() => {
1868f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
1869f6603c60Sopenharmony_ci            console.info('setSpeedTimeWithoutCallback avPlayer state is prepared')
1870f6603c60Sopenharmony_ci        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1871f6603c60Sopenharmony_ci        let start = Date.now();
1872f6603c60Sopenharmony_ci        console.info(`setSpeedTimeWithoutCallback start time is : ${start}`)
1873f6603c60Sopenharmony_ci        await avPlayer.setSpeed(media.PlaybackSpeed.SPEED_FORWARD_1_00_X);
1874f6603c60Sopenharmony_ci        let end = Date.now();
1875f6603c60Sopenharmony_ci        console.info(`setSpeedTimeWithoutCallback end time is : ${end}`)
1876f6603c60Sopenharmony_ci        let execution = parseInt(end - start)
1877f6603c60Sopenharmony_ci        console.info("setSpeedTimeWithoutCallback execution time  is :" + execution)
1878f6603c60Sopenharmony_ci        totalTime = totalTime + execution;
1879f6603c60Sopenharmony_ci        await avPlayer.release().then(() => {
1880f6603c60Sopenharmony_ci            console.info('setSpeedTimeWithoutCallback avPlayer is release')
1881f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
1882f6603c60Sopenharmony_ci        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1883f6603c60Sopenharmony_ci    }
1884f6603c60Sopenharmony_ci    let avg = totalTime/10;
1885f6603c60Sopenharmony_ci    console.info("setSpeedTimeWithoutCallback avg time  is :" + avg)
1886f6603c60Sopenharmony_ci    done();
1887f6603c60Sopenharmony_ci}
1888f6603c60Sopenharmony_ci
1889f6603c60Sopenharmony_ciexport async function setSpeedTimeWithCallback(src, avPlayer, done) {
1890f6603c60Sopenharmony_ci    avPlayer = await idle(src, avPlayer)
1891f6603c60Sopenharmony_ci    await setSpeedTimeCallback(avPlayer, done)
1892f6603c60Sopenharmony_ci    await setSource(avPlayer, src);
1893f6603c60Sopenharmony_ci}
1894f6603c60Sopenharmony_ci
1895f6603c60Sopenharmony_cifunction setSpeedTimeCallback(avPlayer, done) {
1896f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
1897f6603c60Sopenharmony_ci    let start;
1898f6603c60Sopenharmony_ci    let end;
1899f6603c60Sopenharmony_ci    let execution;
1900f6603c60Sopenharmony_ci    let loopTime = 0;
1901f6603c60Sopenharmony_ci    let totalTime = 0;
1902f6603c60Sopenharmony_ci    console.info(`case setCallback in, surfaceID is ${surfaceID}`);
1903f6603c60Sopenharmony_ci    avPlayer.on('stateChange', async (state, reason) => {
1904f6603c60Sopenharmony_ci        console.info(`case stateChange called, state is ${state}, reason is ${reason}`);
1905f6603c60Sopenharmony_ci        console.info(`case state is ${state}`);
1906f6603c60Sopenharmony_ci        switch (state) {
1907f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.INITIALIZED:
1908f6603c60Sopenharmony_ci                avPlayer.surfaceId = surfaceID;
1909f6603c60Sopenharmony_ci                console.info('setSpeedTimeCallback play state is INITIALIZED')
1910f6603c60Sopenharmony_ci            // step 1: initialized -> prepared
1911f6603c60Sopenharmony_ci                avPlayer.prepare((err) => {
1912f6603c60Sopenharmony_ci                    if (err != null) {
1913f6603c60Sopenharmony_ci                        console.error(`case prepare error, errMessage is ${err.message}`);
1914f6603c60Sopenharmony_ci                        expect().assertFail();
1915f6603c60Sopenharmony_ci                        done();
1916f6603c60Sopenharmony_ci                    } else {
1917f6603c60Sopenharmony_ci                        console.info('setSpeedTimeCallback play state is prepared')
1918f6603c60Sopenharmony_ci                    }
1919f6603c60Sopenharmony_ci                });
1920f6603c60Sopenharmony_ci                break;
1921f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PREPARED:
1922f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
1923f6603c60Sopenharmony_ci                console.info('setSpeedTimeCallback avPlayer state is prepared')
1924f6603c60Sopenharmony_ci                avPlayer.play()
1925f6603c60Sopenharmony_ci                break;
1926f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PLAYING:
1927f6603c60Sopenharmony_ci                console.info('setSpeedTimeCallback play state is PLAYING')
1928f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
1929f6603c60Sopenharmony_ci                if(loopTime == 10){
1930f6603c60Sopenharmony_ci                    avPlayer.release().then(() => {
1931f6603c60Sopenharmony_ci                        console.info('setSpeedTimeCallback avPlayer is release')
1932f6603c60Sopenharmony_ci                        expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
1933f6603c60Sopenharmony_ci                        let avg = totalTime/10;
1934f6603c60Sopenharmony_ci                        console.info("setSpeedTimeCallback avg time  is :" + avg)
1935f6603c60Sopenharmony_ci                        done();
1936f6603c60Sopenharmony_ci                    }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1937f6603c60Sopenharmony_ci                }else{
1938f6603c60Sopenharmony_ci                    start = Date.now();
1939f6603c60Sopenharmony_ci                    console.info(`setSpeedTimeCallback start time is : ${start}`)
1940f6603c60Sopenharmony_ci                    loopTime++
1941f6603c60Sopenharmony_ci                    avPlayer.setSpeed(media.PlaybackSpeed.SPEED_FORWARD_1_00_X);
1942f6603c60Sopenharmony_ci                }
1943f6603c60Sopenharmony_ci                break;
1944f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PAUSED:
1945f6603c60Sopenharmony_ci                console.info('setSpeedTimeCallback play state is PAUSED')
1946f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PAUSED);
1947f6603c60Sopenharmony_ci                avPlayer.play().then(() => {
1948f6603c60Sopenharmony_ci                    console.info('setSpeedTimeCallback avPlayer from pause to play')
1949f6603c60Sopenharmony_ci                }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1950f6603c60Sopenharmony_ci                break;
1951f6603c60Sopenharmony_ci            default:
1952f6603c60Sopenharmony_ci                break;
1953f6603c60Sopenharmony_ci        }
1954f6603c60Sopenharmony_ci    });
1955f6603c60Sopenharmony_ci    avPlayer.on('speedDone', async (speed) => {
1956f6603c60Sopenharmony_ci        end = Date.now();
1957f6603c60Sopenharmony_ci        console.info(`setSpeedTimeCallback end time is : ${end}`)
1958f6603c60Sopenharmony_ci        execution = parseInt(end - start)
1959f6603c60Sopenharmony_ci        console.info("setSpeedTimeCallback execution time  is :" + execution)
1960f6603c60Sopenharmony_ci        totalTime = totalTime + execution;
1961f6603c60Sopenharmony_ci        console.info('speedDone success,and speed value is:' + speed)
1962f6603c60Sopenharmony_ci        avPlayer.pause()
1963f6603c60Sopenharmony_ci    });
1964f6603c60Sopenharmony_ci}
1965f6603c60Sopenharmony_ci
1966f6603c60Sopenharmony_ciexport async function setBitrateTimeWithoutCallback(src, avPlayer, done) {
1967f6603c60Sopenharmony_ci    let totalTime = 0;
1968f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
1969f6603c60Sopenharmony_ci    for(var i = 0;i < 10;i++){
1970f6603c60Sopenharmony_ci        avPlayer = await idle(src, avPlayer)
1971f6603c60Sopenharmony_ci        await setSource(avPlayer, src);
1972f6603c60Sopenharmony_ci        console.info('setBitrateTimeWithoutCallback setSource');
1973f6603c60Sopenharmony_ci        await sleep(20)
1974f6603c60Sopenharmony_ci        avPlayer.surfaceId = surfaceID;
1975f6603c60Sopenharmony_ci        await avPlayer.prepare().then(() => {
1976f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
1977f6603c60Sopenharmony_ci            console.info('setBitrateTimeWithoutCallback avPlayer state is prepared')
1978f6603c60Sopenharmony_ci        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1979f6603c60Sopenharmony_ci        let start = Date.now();
1980f6603c60Sopenharmony_ci        console.info(`setBitrateTimeWithoutCallback start time is : ${start}`)
1981f6603c60Sopenharmony_ci        let bitrate = 96000
1982f6603c60Sopenharmony_ci        await avPlayer.setBitrate(bitrate)
1983f6603c60Sopenharmony_ci        let end = Date.now();
1984f6603c60Sopenharmony_ci        console.info(`setBitrateTimeWithoutCallback end time is : ${end}`)
1985f6603c60Sopenharmony_ci        let execution = parseInt(end - start)
1986f6603c60Sopenharmony_ci        console.info("setBitrateTimeWithoutCallback execution time  is :" + execution)
1987f6603c60Sopenharmony_ci        totalTime = totalTime + execution;
1988f6603c60Sopenharmony_ci        await avPlayer.release().then(() => {
1989f6603c60Sopenharmony_ci            console.info('setBitrateTimeWithoutCallback avPlayer is release')
1990f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
1991f6603c60Sopenharmony_ci        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
1992f6603c60Sopenharmony_ci    }
1993f6603c60Sopenharmony_ci    let avg = totalTime/10;
1994f6603c60Sopenharmony_ci    console.info("setBitrateTimeWithoutCallback avg time  is :" + avg)
1995f6603c60Sopenharmony_ci    done();
1996f6603c60Sopenharmony_ci}
1997f6603c60Sopenharmony_ci
1998f6603c60Sopenharmony_ciexport async function setVolumeTimeWithoutCallback(src, avPlayer, done) {
1999f6603c60Sopenharmony_ci    let totalTime = 0;
2000f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
2001f6603c60Sopenharmony_ci    for(var i = 0;i < 10;i++){
2002f6603c60Sopenharmony_ci        avPlayer = await idle(src, avPlayer)
2003f6603c60Sopenharmony_ci        await setSource(avPlayer, src);
2004f6603c60Sopenharmony_ci        console.info('setVolumeTimeWithoutCallback setSource');
2005f6603c60Sopenharmony_ci        await sleep(20)
2006f6603c60Sopenharmony_ci        avPlayer.surfaceId = surfaceID;
2007f6603c60Sopenharmony_ci        await avPlayer.prepare().then(() => {
2008f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
2009f6603c60Sopenharmony_ci            console.info('setVolumeTimeWithoutCallback avPlayer state is prepared')
2010f6603c60Sopenharmony_ci        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
2011f6603c60Sopenharmony_ci        let start = Date.now();
2012f6603c60Sopenharmony_ci        console.info(`setVolumeTimeWithoutCallback start time is : ${start}`)
2013f6603c60Sopenharmony_ci        let volume = 1.0
2014f6603c60Sopenharmony_ci        avPlayer.setVolume(volume)
2015f6603c60Sopenharmony_ci        let end = Date.now();
2016f6603c60Sopenharmony_ci        console.info(`setVolumeTimeWithoutCallback end time is : ${end}`)
2017f6603c60Sopenharmony_ci        let execution = parseInt(end - start)
2018f6603c60Sopenharmony_ci        console.info("setVolumeTimeWithoutCallback execution time  is :" + execution)
2019f6603c60Sopenharmony_ci        totalTime = totalTime + execution;
2020f6603c60Sopenharmony_ci        await avPlayer.release().then(() => {
2021f6603c60Sopenharmony_ci            console.info('setVolumeTimeWithoutCallback avPlayer is release')
2022f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
2023f6603c60Sopenharmony_ci        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
2024f6603c60Sopenharmony_ci    }
2025f6603c60Sopenharmony_ci    let avg = totalTime/10;
2026f6603c60Sopenharmony_ci    console.info("setVolumeTimeWithoutCallback avg time  is :" + avg)
2027f6603c60Sopenharmony_ci    done();
2028f6603c60Sopenharmony_ci}
2029f6603c60Sopenharmony_ci
2030f6603c60Sopenharmony_ciexport async function setVolumeTimeWithCallback(src, avPlayer, done) {
2031f6603c60Sopenharmony_ci    avPlayer = await idle(src, avPlayer)
2032f6603c60Sopenharmony_ci    await setVolumeTimeCallback(avPlayer, done)
2033f6603c60Sopenharmony_ci    await setSource(avPlayer, src);
2034f6603c60Sopenharmony_ci}
2035f6603c60Sopenharmony_ci
2036f6603c60Sopenharmony_cifunction setVolumeTimeCallback(avPlayer, done) {
2037f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
2038f6603c60Sopenharmony_ci    let start;
2039f6603c60Sopenharmony_ci    let end;
2040f6603c60Sopenharmony_ci    let execution;
2041f6603c60Sopenharmony_ci    let loopTime = 0;
2042f6603c60Sopenharmony_ci    let totalTime = 0;
2043f6603c60Sopenharmony_ci    console.info(`case setCallback in, surfaceID is ${surfaceID}`);
2044f6603c60Sopenharmony_ci    avPlayer.on('stateChange', async (state, reason) => {
2045f6603c60Sopenharmony_ci        console.info(`case stateChange called, state is ${state}, reason is ${reason}`);
2046f6603c60Sopenharmony_ci        console.info(`case state is ${state}`);
2047f6603c60Sopenharmony_ci        switch (state) {
2048f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.INITIALIZED:
2049f6603c60Sopenharmony_ci                avPlayer.surfaceId = surfaceID;
2050f6603c60Sopenharmony_ci                console.info('setVolumeTimeCallback play state is INITIALIZED')
2051f6603c60Sopenharmony_ci            // step 1: initialized -> prepared
2052f6603c60Sopenharmony_ci                avPlayer.prepare((err) => {
2053f6603c60Sopenharmony_ci                    if (err != null) {
2054f6603c60Sopenharmony_ci                        console.error(`case prepare error, errMessage is ${err.message}`);
2055f6603c60Sopenharmony_ci                        expect().assertFail();
2056f6603c60Sopenharmony_ci                        done();
2057f6603c60Sopenharmony_ci                    } else {
2058f6603c60Sopenharmony_ci                        console.info('setVolumeTimeCallback play state is prepared')
2059f6603c60Sopenharmony_ci                    }
2060f6603c60Sopenharmony_ci                });
2061f6603c60Sopenharmony_ci                break;
2062f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PREPARED:
2063f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
2064f6603c60Sopenharmony_ci                console.info('setVolumeTimeCallback avPlayer state is prepared')
2065f6603c60Sopenharmony_ci                avPlayer.play()
2066f6603c60Sopenharmony_ci                break;
2067f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PLAYING:
2068f6603c60Sopenharmony_ci                console.info('setVolumeTimeCallback play state is PLAYING')
2069f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
2070f6603c60Sopenharmony_ci                if(loopTime == 10){
2071f6603c60Sopenharmony_ci                    avPlayer.release().then(() => {
2072f6603c60Sopenharmony_ci                        console.info('setVolumeTimeCallback avPlayer is release')
2073f6603c60Sopenharmony_ci                        expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
2074f6603c60Sopenharmony_ci                        let avg = totalTime/10;
2075f6603c60Sopenharmony_ci                        console.info("setVolumeTimeCallback avg time  is :" + avg)
2076f6603c60Sopenharmony_ci                        done();
2077f6603c60Sopenharmony_ci                    }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
2078f6603c60Sopenharmony_ci                }else{
2079f6603c60Sopenharmony_ci                    start = Date.now();
2080f6603c60Sopenharmony_ci                    console.info(`setVolumeTimeCallback start time is : ${start}`)
2081f6603c60Sopenharmony_ci                    loopTime++
2082f6603c60Sopenharmony_ci                    let volume = 1.0
2083f6603c60Sopenharmony_ci                    avPlayer.setVolume(volume)
2084f6603c60Sopenharmony_ci                }
2085f6603c60Sopenharmony_ci                break;
2086f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PAUSED:
2087f6603c60Sopenharmony_ci                console.info('setVolumeTimeCallback play state is PAUSED')
2088f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PAUSED);
2089f6603c60Sopenharmony_ci                avPlayer.play().then(() => {
2090f6603c60Sopenharmony_ci                    console.info('setVolumeTimeCallback avPlayer from pause to play')
2091f6603c60Sopenharmony_ci                }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
2092f6603c60Sopenharmony_ci                break;
2093f6603c60Sopenharmony_ci            default:
2094f6603c60Sopenharmony_ci                break;
2095f6603c60Sopenharmony_ci        }
2096f6603c60Sopenharmony_ci    });
2097f6603c60Sopenharmony_ci    avPlayer.on('volumeChange', (vol) => {
2098f6603c60Sopenharmony_ci        end = Date.now();
2099f6603c60Sopenharmony_ci        console.info(`setVolumeTimeCallback end time is : ${end}`)
2100f6603c60Sopenharmony_ci        execution = parseInt(end - start)
2101f6603c60Sopenharmony_ci        console.info("setVolumeTimeCallback execution time  is :" + execution)
2102f6603c60Sopenharmony_ci        totalTime = totalTime + execution;
2103f6603c60Sopenharmony_ci        console.info('volumeChange success,and new volume is :' + vol)
2104f6603c60Sopenharmony_ci        avPlayer.pause()
2105f6603c60Sopenharmony_ci    });
2106f6603c60Sopenharmony_ci}
2107f6603c60Sopenharmony_ci
2108f6603c60Sopenharmony_ciexport async function firstFrameTime(src, avPlayer,  done) {
2109f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
2110f6603c60Sopenharmony_ci    let start;
2111f6603c60Sopenharmony_ci    avPlayer = await idle(src, avPlayer)
2112f6603c60Sopenharmony_ci    await setSource(avPlayer, src);
2113f6603c60Sopenharmony_ci    console.info('firstFrameTime setSource');
2114f6603c60Sopenharmony_ci    await sleep(20)
2115f6603c60Sopenharmony_ci    avPlayer.surfaceId = surfaceID;
2116f6603c60Sopenharmony_ci    await avPlayer.prepare().then(() => {
2117f6603c60Sopenharmony_ci        expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
2118f6603c60Sopenharmony_ci        console.info('firstFrameTime avPlayer state is prepared')
2119f6603c60Sopenharmony_ci    }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
2120f6603c60Sopenharmony_ci    await avPlayer.on('startRenderFrame', () => {
2121f6603c60Sopenharmony_ci        console.info('startRenderFrame success')
2122f6603c60Sopenharmony_ci        let end = Date.now();
2123f6603c60Sopenharmony_ci        console.info(`firstFrameTime end time is : ${end}`)
2124f6603c60Sopenharmony_ci        let execution = parseInt(end - start)
2125f6603c60Sopenharmony_ci        console.info("firstFrameTime execution time  is :" + execution)
2126f6603c60Sopenharmony_ci        sleep(100)
2127f6603c60Sopenharmony_ci        avPlayer.release().then(() => {
2128f6603c60Sopenharmony_ci            console.info('firstFrameTime avPlayer is release')
2129f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
2130f6603c60Sopenharmony_ci            avPlayer = null;
2131f6603c60Sopenharmony_ci            done();
2132f6603c60Sopenharmony_ci        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
2133f6603c60Sopenharmony_ci    })
2134f6603c60Sopenharmony_ci    start = Date.now();
2135f6603c60Sopenharmony_ci    console.info(`firstFrameTime start time is : ${start}`)
2136f6603c60Sopenharmony_ci    await avPlayer.play().then(() => {
2137f6603c60Sopenharmony_ci        console.info('firstFrameTime play success');
2138f6603c60Sopenharmony_ci    }, (err) => {
2139f6603c60Sopenharmony_ci        console.error('firstFrameTime play filed,error message is :' + err.message)
2140f6603c60Sopenharmony_ci    })
2141f6603c60Sopenharmony_ci}
2142f6603c60Sopenharmony_ci
2143f6603c60Sopenharmony_ciasync function playToPauseLoop(avPlayer){
2144f6603c60Sopenharmony_ci    await avPlayer.play().then(() => {
2145f6603c60Sopenharmony_ci        console.info('playToPauseLoop play success');
2146f6603c60Sopenharmony_ci        expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
2147f6603c60Sopenharmony_ci    }, (err) => {
2148f6603c60Sopenharmony_ci        console.error('playToPauseLoop play filed,error message is :' + err.message)
2149f6603c60Sopenharmony_ci    })
2150f6603c60Sopenharmony_ci    if(avPlayer.state == AV_PLAYER_STATE.PLAYING){
2151f6603c60Sopenharmony_ci        avPlayer.loop = true;
2152f6603c60Sopenharmony_ci        await mediaTestBase.msleepAsync(2);
2153f6603c60Sopenharmony_ci        console.info('playToPauseLoop avPlayer from play to pause')
2154f6603c60Sopenharmony_ci    }
2155f6603c60Sopenharmony_ci    await avPlayer.pause().then(() => {
2156f6603c60Sopenharmony_ci        console.info('playToPauseLoop pause success');
2157f6603c60Sopenharmony_ci        expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PAUSED);
2158f6603c60Sopenharmony_ci    }, (err) => {
2159f6603c60Sopenharmony_ci        console.error('playToPauseLoop pause filed,error message is :' + err.message)
2160f6603c60Sopenharmony_ci    })
2161f6603c60Sopenharmony_ci}
2162f6603c60Sopenharmony_ci
2163f6603c60Sopenharmony_ciexport async function avPlayerWithoutCallBack(src, avPlayer, done) {
2164f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
2165f6603c60Sopenharmony_ci    console.info(`case avPlayerWithoutCallBack Initialized in, surfaceID is ${surfaceID}`);
2166f6603c60Sopenharmony_ci    avPlayer = await idle(src, avPlayer)
2167f6603c60Sopenharmony_ci    setSource(avPlayer, src);
2168f6603c60Sopenharmony_ci    console.info('avPlayerWithoutCallBack setSource');
2169f6603c60Sopenharmony_ci    await sleep(20);
2170f6603c60Sopenharmony_ci    if(avPlayer.state == AV_PLAYER_STATE.INITIALIZED) {
2171f6603c60Sopenharmony_ci        avPlayer.surfaceId = surfaceID;
2172f6603c60Sopenharmony_ci        await preparePromise(avPlayer);
2173f6603c60Sopenharmony_ci        await sleep(2000);
2174f6603c60Sopenharmony_ci    }
2175f6603c60Sopenharmony_ci    if(avPlayer.state == AV_PLAYER_STATE.PREPARED){
2176f6603c60Sopenharmony_ci        console.info('avPlayerWithoutCallBack avPlayer from PREPARED to play')
2177f6603c60Sopenharmony_ci        // play to pause loop 1000 times
2178f6603c60Sopenharmony_ci        for(var i = 0;i < 1000; i++){
2179f6603c60Sopenharmony_ci            await playToPauseLoop(avPlayer)
2180f6603c60Sopenharmony_ci            console.info(`case avPlayerWithoutCallBack playToPauseLoop is ${i}`);
2181f6603c60Sopenharmony_ci        }
2182f6603c60Sopenharmony_ci    }
2183f6603c60Sopenharmony_ci    await avPlayer.stop().then(() => {
2184f6603c60Sopenharmony_ci        console.info('avPlayerWithoutCallBack avPlayer from play to stop')
2185f6603c60Sopenharmony_ci        avPlayer.release().then(() => {
2186f6603c60Sopenharmony_ci            console.info('avPlayerWithoutCallBack avPlayer from stop to release')
2187f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
2188f6603c60Sopenharmony_ci            done();
2189f6603c60Sopenharmony_ci        }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
2190f6603c60Sopenharmony_ci    }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
2191f6603c60Sopenharmony_ci}
2192f6603c60Sopenharmony_ci
2193f6603c60Sopenharmony_cifunction setAVPlayerPlay(src, avPlayer, done) {
2194f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
2195f6603c60Sopenharmony_ci    console.info(`case setAVPlayerPlay in, surfaceID is ${surfaceID}`);
2196f6603c60Sopenharmony_ci    avPlayer.on('stateChange', async (state, reason) => {
2197f6603c60Sopenharmony_ci        console.info(`case stateChange called, state is ${state}, reason is ${reason}`);
2198f6603c60Sopenharmony_ci        console.info(`case state is ${state}`);
2199f6603c60Sopenharmony_ci        switch (state) {
2200f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.INITIALIZED:
2201f6603c60Sopenharmony_ci                avPlayer.surfaceId = surfaceID;
2202f6603c60Sopenharmony_ci                console.info('setAVPlayerPlay play state is INITIALIZED')
2203f6603c60Sopenharmony_ci            // step 1: initialized -> prepared -> play
2204f6603c60Sopenharmony_ci                avPlayer.prepare().then(() => {
2205f6603c60Sopenharmony_ci                    avPlayer.play()
2206f6603c60Sopenharmony_ci                }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
2207f6603c60Sopenharmony_ci                break;
2208f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PLAYING:
2209f6603c60Sopenharmony_ci                console.info('setAVPlayerPlay play state is PLAYING')
2210f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
2211f6603c60Sopenharmony_ci                if(avPlayer.duration > 3000){
2212f6603c60Sopenharmony_ci                    mediaTestBase.msleepAsync(3000);
2213f6603c60Sopenharmony_ci                    avPlayer.seek(avPlayer.duration, media.SeekMode.SEEK_NEXT_SYNC)
2214f6603c60Sopenharmony_ci                }else{
2215f6603c60Sopenharmony_ci                    mediaTestBase.msleepAsync(500);
2216f6603c60Sopenharmony_ci                    avPlayer.seek(avPlayer.duration, media.SeekMode.SEEK_NEXT_SYNC)
2217f6603c60Sopenharmony_ci                }
2218f6603c60Sopenharmony_ci                break;
2219f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.COMPLETED:
2220f6603c60Sopenharmony_ci                expect(avPlayer.currentTime).assertEqual(avPlayer.duration);
2221f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual('completed');
2222f6603c60Sopenharmony_ci                avPlayer.release().then(() => {
2223f6603c60Sopenharmony_ci                }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
2224f6603c60Sopenharmony_ci                break;
2225f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.RELEASED:
2226f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual('released');
2227f6603c60Sopenharmony_ci                avPlayer = null;
2228f6603c60Sopenharmony_ci                done();
2229f6603c60Sopenharmony_ci                break;
2230f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.ERROR:
2231f6603c60Sopenharmony_ci                expect().assertFail();
2232f6603c60Sopenharmony_ci                avPlayer.release().then(() => {
2233f6603c60Sopenharmony_ci                }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
2234f6603c60Sopenharmony_ci                break;
2235f6603c60Sopenharmony_ci            default:
2236f6603c60Sopenharmony_ci                break;
2237f6603c60Sopenharmony_ci        }
2238f6603c60Sopenharmony_ci    });
2239f6603c60Sopenharmony_ci    avPlayer.on('error', async (err) => {
2240f6603c60Sopenharmony_ci        console.error(`case error called, errMessage is ${err.message}`);
2241f6603c60Sopenharmony_ci        expect().assertFail();
2242f6603c60Sopenharmony_ci        await avPlayer.release().then(() => {
2243f6603c60Sopenharmony_ci            avPlayer = null;
2244f6603c60Sopenharmony_ci            done();
2245f6603c60Sopenharmony_ci        });
2246f6603c60Sopenharmony_ci    });
2247f6603c60Sopenharmony_ci}
2248f6603c60Sopenharmony_ci
2249f6603c60Sopenharmony_ciexport async function avPlayerPlay(src, avPlayer, done) {
2250f6603c60Sopenharmony_ci    avPlayer = await idle(src, avPlayer)
2251f6603c60Sopenharmony_ci    await setAVPlayerPlay(src, avPlayer, done);
2252f6603c60Sopenharmony_ci    await setSource(avPlayer, src);
2253f6603c60Sopenharmony_ci}
2254f6603c60Sopenharmony_ci
2255f6603c60Sopenharmony_ciexport async function testAVPlayerFun(src, avPlayer, playTest, playTime, done) {
2256f6603c60Sopenharmony_ci    console.info(`case media source: ${src}`)
2257f6603c60Sopenharmony_ci    await media.createAVPlayer().then((video) => {
2258f6603c60Sopenharmony_ci        if (typeof(video) != 'undefined') {
2259f6603c60Sopenharmony_ci            console.info('case createAVPlayer success');
2260f6603c60Sopenharmony_ci            avPlayer = video;
2261f6603c60Sopenharmony_ci            expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.IDLE);
2262f6603c60Sopenharmony_ci        } else {
2263f6603c60Sopenharmony_ci            console.error('case createAVPlayer failed');
2264f6603c60Sopenharmony_ci            expect().assertFail();
2265f6603c60Sopenharmony_ci            done();
2266f6603c60Sopenharmony_ci        }
2267f6603c60Sopenharmony_ci    }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
2268f6603c60Sopenharmony_ci    setAVPlayerFunCb(src, avPlayer, playTest, playTime, done);
2269f6603c60Sopenharmony_ci    setSource(avPlayer, src);
2270f6603c60Sopenharmony_ci}
2271f6603c60Sopenharmony_ci
2272f6603c60Sopenharmony_ciexport function setAVPlayerSeekCb(src, avPlayer, playTest, playTime, done) {
2273f6603c60Sopenharmony_ci    let volumeCnt = [0];
2274f6603c60Sopenharmony_ci    let endOfStreamCnt = 0;
2275f6603c60Sopenharmony_ci    let seekDoneCnt = 0;
2276f6603c60Sopenharmony_ci    let speedDoneCnt = [0];
2277f6603c60Sopenharmony_ci    let playCnt = 0;
2278f6603c60Sopenharmony_ci    let surfaceID = globalThis.value;
2279f6603c60Sopenharmony_ci    console.info(`case setCallback in, surfaceID is ${surfaceID}`);
2280f6603c60Sopenharmony_ci    avPlayer.on('stateChange', async (state, reason) => {
2281f6603c60Sopenharmony_ci        console.info(`case stateChange called, state is ${state}, reason is ${reason}`);
2282f6603c60Sopenharmony_ci        if (reason == media.StateChangeReason.BACKGROUND) {
2283f6603c60Sopenharmony_ci            avPlayer.release().then(() => {
2284f6603c60Sopenharmony_ci            }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
2285f6603c60Sopenharmony_ci        }
2286f6603c60Sopenharmony_ci        switch (state) {
2287f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.INITIALIZED:
2288f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.INITIALIZED);
2289f6603c60Sopenharmony_ci                avPlayer.surfaceId = surfaceID;
2290f6603c60Sopenharmony_ci                console.info('case initialized -> prepared');
2291f6603c60Sopenharmony_ci                // step 1,10: initialized -> prepared
2292f6603c60Sopenharmony_ci                avPlayer.prepare((err) => {
2293f6603c60Sopenharmony_ci                    avPlayer.loop = true;
2294f6603c60Sopenharmony_ci                    if (err != null) {
2295f6603c60Sopenharmony_ci                        console.error(`case prepare error, errMessage is ${err.message}`);
2296f6603c60Sopenharmony_ci                        expect().assertFail();
2297f6603c60Sopenharmony_ci                        done();
2298f6603c60Sopenharmony_ci                    } else {
2299f6603c60Sopenharmony_ci                        checkPlayTest(avPlayer, playTest);
2300f6603c60Sopenharmony_ci                    }
2301f6603c60Sopenharmony_ci                });
2302f6603c60Sopenharmony_ci                break;
2303f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PREPARED:
2304f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
2305f6603c60Sopenharmony_ci                checkPlayTest(avPlayer, playTest);
2306f6603c60Sopenharmony_ci                expect(avPlayer.currentTime).assertEqual(0);
2307f6603c60Sopenharmony_ci                offCallback(avPlayer, ['volumeChange']);
2308f6603c60Sopenharmony_ci                // step 2,11: prepared -> seek 0
2309f6603c60Sopenharmony_ci                avPlayer.seek(0, 2);  // 2: CLOSEST SYNC
2310f6603c60Sopenharmony_ci                break;
2311f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.PLAYING:
2312f6603c60Sopenharmony_ci                playCnt++;
2313f6603c60Sopenharmony_ci                if (playCnt == 1) {
2314f6603c60Sopenharmony_ci                    // step 4: seek + pause
2315f6603c60Sopenharmony_ci                    expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PLAYING);
2316f6603c60Sopenharmony_ci                    avPlayer.seek(avPlayer.duration / 2, media.SeekMode.SEEK_PREV_SYNC);
2317f6603c60Sopenharmony_ci                    avPlayer.pause((err) => {
2318f6603c60Sopenharmony_ci                        if (err != null) {
2319f6603c60Sopenharmony_ci                            mediaTestBase.assertErr('pause', err, done);
2320f6603c60Sopenharmony_ci                        }
2321f6603c60Sopenharmony_ci                    });
2322f6603c60Sopenharmony_ci                } else if (playCnt == 3) {
2323f6603c60Sopenharmony_ci                    // step 12: seek duration
2324f6603c60Sopenharmony_ci                    avPlayer.seek(avPlayer.duration, media.SeekMode.SEEK_PREV_SYNC);
2325f6603c60Sopenharmony_ci                    avPlayer.stop((err) => {
2326f6603c60Sopenharmony_ci                        if (err == null) {
2327f6603c60Sopenharmony_ci                            avPlayer.release((err) => {
2328f6603c60Sopenharmony_ci                                if (err != null) {
2329f6603c60Sopenharmony_ci                                    mediaTestBase.assertErr('release', err, done);
2330f6603c60Sopenharmony_ci                                }
2331f6603c60Sopenharmony_ci                            })
2332f6603c60Sopenharmony_ci                        }  else {
2333f6603c60Sopenharmony_ci                            mediaTestBase.assertErr('stop', err, done);
2334f6603c60Sopenharmony_ci                        }
2335f6603c60Sopenharmony_ci                    });
2336f6603c60Sopenharmony_ci                }
2337f6603c60Sopenharmony_ci                break;
2338f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.RELEASED:
2339f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.RELEASED);
2340f6603c60Sopenharmony_ci                // step 18: release -> done
2341f6603c60Sopenharmony_ci                avPlayer = null;
2342f6603c60Sopenharmony_ci                expect(volumeCnt[0]).assertEqual(0);
2343f6603c60Sopenharmony_ci                expect(endOfStreamCnt).assertLarger(0);
2344f6603c60Sopenharmony_ci                done();
2345f6603c60Sopenharmony_ci                break;
2346f6603c60Sopenharmony_ci            case AV_PLAYER_STATE.ERROR:
2347f6603c60Sopenharmony_ci                expect().assertFail();
2348f6603c60Sopenharmony_ci                avPlayer.release().then(() => {
2349f6603c60Sopenharmony_ci                }, mediaTestBase.failureCallback).catch(mediaTestBase.catchCallback);
2350f6603c60Sopenharmony_ci                break;
2351f6603c60Sopenharmony_ci            default:
2352f6603c60Sopenharmony_ci                break;
2353f6603c60Sopenharmony_ci        }
2354f6603c60Sopenharmony_ci    });
2355f6603c60Sopenharmony_ci
2356f6603c60Sopenharmony_ci    avPlayer.on('endOfStream', () => {
2357f6603c60Sopenharmony_ci        console.info(`case endOfStream called`);
2358f6603c60Sopenharmony_ci        endOfStreamCnt++;
2359f6603c60Sopenharmony_ci        // step 9: seek + reset
2360f6603c60Sopenharmony_ci        avPlayer.seek(avPlayer.duration / 2, 3); // 3: CLOSEST
2361f6603c60Sopenharmony_ci        avPlayer.reset((err) => {
2362f6603c60Sopenharmony_ci            if (err == null) {
2363f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.IDLE);
2364f6603c60Sopenharmony_ci                console.info('case reset success!!');
2365f6603c60Sopenharmony_ci                setSource(avPlayer, src);
2366f6603c60Sopenharmony_ci            }  else {
2367f6603c60Sopenharmony_ci                mediaTestBase.assertErr('reset', err, done);
2368f6603c60Sopenharmony_ci            }
2369f6603c60Sopenharmony_ci        });
2370f6603c60Sopenharmony_ci    });
2371f6603c60Sopenharmony_ci    avPlayer.on('seekDone', async (seekDoneTime) => {
2372f6603c60Sopenharmony_ci        seekDoneCnt++;
2373f6603c60Sopenharmony_ci        console.info(`case seekDone called, seekDoneCnt is ${seekDoneCnt}, seekDoneTime is ${seekDoneTime}`);
2374f6603c60Sopenharmony_ci        switch (seekDoneCnt) {
2375f6603c60Sopenharmony_ci            case 1:
2376f6603c60Sopenharmony_ci                expect(avPlayer.state).assertEqual(AV_PLAYER_STATE.PREPARED);
2377f6603c60Sopenharmony_ci                // step 3: seek(prepared) -> play
2378f6603c60Sopenharmony_ci                avPlayer.play((err) => {
2379f6603c60Sopenharmony_ci                    if (err != null) {
2380f6603c60Sopenharmony_ci                        mediaTestBase.assertErr('play', err, done);
2381f6603c60Sopenharmony_ci                    }
2382f6603c60Sopenharmony_ci                });
2383f6603c60Sopenharmony_ci                break;
2384f6603c60Sopenharmony_ci            case 2:
2385f6603c60Sopenharmony_ci                // step 5: seek + play
2386f6603c60Sopenharmony_ci                avPlayer.seek(avPlayer.duration / 2, media.SeekMode.SEEK_NEXT_SYNC);
2387f6603c60Sopenharmony_ci                avPlayer.play();
2388f6603c60Sopenharmony_ci                break;
2389f6603c60Sopenharmony_ci            case 3:
2390f6603c60Sopenharmony_ci                // step 6: seek  + setVolume
2391f6603c60Sopenharmony_ci                avPlayer.setVolume(0.5);
2392f6603c60Sopenharmony_ci                avPlayer.seek(avPlayer.duration / 2, media.SeekMode.SEEK_CLOSEST_SYNC);
2393f6603c60Sopenharmony_ci                avPlayer.play();
2394f6603c60Sopenharmony_ci                break;
2395f6603c60Sopenharmony_ci            case 4:
2396f6603c60Sopenharmony_ci                // step 7: seek + seek
2397f6603c60Sopenharmony_ci                avPlayer.seek(avPlayer.duration / 2);
2398f6603c60Sopenharmony_ci                avPlayer.seek(avPlayer.duration, media.SeekMode.SEEK_NEXT_SYNC);
2399f6603c60Sopenharmony_ci                avPlayer.play();
2400f6603c60Sopenharmony_ci                break;
2401f6603c60Sopenharmony_ci            case 5:
2402f6603c60Sopenharmony_ci                // step 8: seek duration
2403f6603c60Sopenharmony_ci                avPlayer.seek(avPlayer.duration, media.SeekMode.SEEK_PREV_SYNC);
2404f6603c60Sopenharmony_ci                break;
2405f6603c60Sopenharmony_ci            default:
2406f6603c60Sopenharmony_ci                avPlayer.play();
2407f6603c60Sopenharmony_ci                break;
2408f6603c60Sopenharmony_ci        }
2409f6603c60Sopenharmony_ci    });
2410f6603c60Sopenharmony_ci    setCallback(avPlayer, 'volumeChange', volumeCnt);
2411f6603c60Sopenharmony_ci    setCallback(avPlayer, 'speedDone', speedDoneCnt);
2412f6603c60Sopenharmony_ci    setCallback(avPlayer, 'bitrateDone', null);
2413f6603c60Sopenharmony_ci    setCallback(avPlayer, 'timeUpdate', null);
2414f6603c60Sopenharmony_ci    setCallback(avPlayer, 'bufferingUpdate', null);
2415f6603c60Sopenharmony_ci    setCallback(avPlayer, 'durationUpdate', null);
2416f6603c60Sopenharmony_ci    setCallback(avPlayer, 'startRenderFrame', null);
2417f6603c60Sopenharmony_ci    setCallback(avPlayer, 'videoSizeChange', null);
2418f6603c60Sopenharmony_ci    setCallback(avPlayer, 'audioInterrupt', null);
2419f6603c60Sopenharmony_ci    setCallback(avPlayer, 'availableBitrates', null);
2420f6603c60Sopenharmony_ci    avPlayer.on('error', async (err) => {
2421f6603c60Sopenharmony_ci        console.error(`case error called, errMessage is ${err.message}`);
2422f6603c60Sopenharmony_ci    });
2423f6603c60Sopenharmony_ci}
2424f6603c60Sopenharmony_ci
2425f6603c60Sopenharmony_ciexport async function testAVPlayerSeek(src, avPlayer, playTest, playTime, done) {
2426f6603c60Sopenharmony_ci    console.info(`case media source: ${src}`)
2427f6603c60Sopenharmony_ci    media.createAVPlayer((err, video) => {
2428f6603c60Sopenharmony_ci        console.info(`case media err: ${err}`)
2429f6603c60Sopenharmony_ci        if (typeof(video) != 'undefined') {
2430f6603c60Sopenharmony_ci            console.info('case createAVPlayer success');
2431f6603c60Sopenharmony_ci            avPlayer = video;
2432f6603c60Sopenharmony_ci            setAVPlayerSeekCb(src, avPlayer, playTest, playTime, done);
2433f6603c60Sopenharmony_ci            setSource(avPlayer, src);
2434f6603c60Sopenharmony_ci        }
2435f6603c60Sopenharmony_ci        if (err != null) {
2436f6603c60Sopenharmony_ci            console.error(`case createAVPlayer error, errMessage is ${err.message}`);
2437f6603c60Sopenharmony_ci            expect().assertFail();
2438f6603c60Sopenharmony_ci            done();
2439f6603c60Sopenharmony_ci        }
2440f6603c60Sopenharmony_ci    });
2441f6603c60Sopenharmony_ci}
2442