提交 2b3a8d8c 编写于 作者: X XUXIAOBO 提交者: Gitee

音频播放器js添加遍历播放码流用例以及修改测试码流。Signed-off-by: XUXIAOBO <xuxiaobo5@huawei.com>

上级 212476b5
......@@ -38,7 +38,7 @@ describe('PlayerLocalTestAudioFUNC', function () {
const LOOP_STATE = 11;
const SECOND_INDEX = 1;
const RAND_NUM = 5;
const TIME_OUT = 35000;
const TIME_OUT = 40000;
const MAX_VOLUME = 1;
beforeAll(function() {
......@@ -125,8 +125,7 @@ describe('PlayerLocalTestAudioFUNC', function () {
}
}
function setCallback(mySteps, done) {
console.info(`case setCallback`);
function setSrcCallback(mySteps) {
audioPlayer.on('dataLoad', () => {
mySteps.shift();
console.info(`case dataLoad called`);
......@@ -135,7 +134,9 @@ describe('PlayerLocalTestAudioFUNC', function () {
expect(audioPlayer.state).assertEqual('paused');
nextStep(mySteps);
});
}
function setPlayCallback(mySteps) {
audioPlayer.on('play', () => {
mySteps.shift();
console.info(`case play called`);
......@@ -149,7 +150,9 @@ describe('PlayerLocalTestAudioFUNC', function () {
expect(audioPlayer.state).assertEqual('playing');
nextStep(mySteps);
});
}
function setPauseCallback(mySteps) {
audioPlayer.on('pause', () => {
mySteps.shift();
console.info(`case pause called`);
......@@ -158,14 +161,18 @@ describe('PlayerLocalTestAudioFUNC', function () {
expect(audioPlayer.state).assertEqual('paused');
nextStep(mySteps);
});
}
function setResetCallback(mySteps) {
audioPlayer.on('reset', () => {
mySteps.shift();
console.info(`case reset called`);
expect(audioPlayer.state).assertEqual('idle');
nextStep(mySteps);
});
}
function setStopCallback(mySteps) {
audioPlayer.on('stop', () => {
if (mySteps[0] == RESET_STATE) {
console.info(`case reset stop called`);
......@@ -178,7 +185,9 @@ describe('PlayerLocalTestAudioFUNC', function () {
expect(audioPlayer.state).assertEqual('stopped');
nextStep(mySteps);
});
}
function setSeekCallback(mySteps) {
audioPlayer.on('timeUpdate', (seekDoneTime) => {
if (typeof (seekDoneTime) == 'undefined') {
console.info(`case seek filed,errcode is ${seekDoneTime}`);
......@@ -201,7 +210,9 @@ describe('PlayerLocalTestAudioFUNC', function () {
nextStep(mySteps);
}
});
}
function setVolumeCallback(mySteps) {
audioPlayer.on('volumeChange', () => {
console.info(`case setvolume called`);
mySteps.shift();
......@@ -211,7 +222,9 @@ describe('PlayerLocalTestAudioFUNC', function () {
}
nextStep(mySteps);
});
}
function setFinishCallback(mySteps) {
audioPlayer.on('finish', () => {
mySteps.shift();
expect(audioPlayer.state).assertEqual('stopped');
......@@ -219,7 +232,9 @@ describe('PlayerLocalTestAudioFUNC', function () {
console.info(`case finish called`);
nextStep(mySteps);
});
}
function setErrorCallback(mySteps) {
audioPlayer.on('error', (err) => {
console.info(`case error called,errName is ${err.name}`);
console.info(`case error called,errCode is ${err.code}`);
......@@ -234,7 +249,19 @@ describe('PlayerLocalTestAudioFUNC', function () {
}
nextStep(mySteps);
});
}
function setCallback(mySteps, done) {
console.info(`case setCallback`);
setSrcCallback(mySteps);
setPlayCallback(mySteps);
setPauseCallback(mySteps);
setResetCallback(mySteps);
setStopCallback(mySteps);
setSeekCallback(mySteps);
setVolumeCallback(mySteps);
setFinishCallback(mySteps);
setErrorCallback(mySteps);
setTimeout(function() {
if (!isTimeOut) {
console.info(`case is time out!`);
......@@ -832,4 +859,4 @@ describe('PlayerLocalTestAudioFUNC', function () {
setCallback(mySteps, done);
audioPlayer.src = AUDIO_SOURCE;
})
})
\ No newline at end of file
})
......@@ -21,11 +21,15 @@ describe('PlayerLocalTestAudioFormat', function () {
const MAX_VOLUME = 1;
const PLAY_TIME = 3000;
const SEEK_TIME = 10000; // 10s
let isToSeek = false;
let isToDuration = false;
beforeAll(function() {
console.info('beforeAll case');
})
beforeEach(function() {
isToSeek = false;
isToDuration = false;
console.info('beforeEach case');
})
......@@ -41,24 +45,16 @@ describe('PlayerLocalTestAudioFormat', function () {
for(let t = Date.now(); Date.now() - t <= time;);
}
function playSource(audioSource, done) {
let audioPlayer = media.createAudioPlayer();
let isToSeek = false;
let isToDuration = false;
if (typeof (audioPlayer) == 'undefined') {
console.info('case create player is faild');
expect().assertFail();
done();
return;
}
function setSrcCallback(audioPlayer) {
audioPlayer.on('dataLoad', () => {
console.info('case set source success');
expect(audioPlayer.state).assertEqual('paused');
expect(audioPlayer.currentTime).assertEqual(0);
audioPlayer.play();
});
}
function setPlayCallback(audioPlayer) {
audioPlayer.on('play', () => {
console.info('case start to play');
expect(audioPlayer.state).assertEqual('playing');
......@@ -69,13 +65,17 @@ describe('PlayerLocalTestAudioFormat', function () {
audioPlayer.seek(SEEK_TIME);
}
});
}
function setPauseCallback(audioPlayer) {
audioPlayer.on('pause', () => {
console.info('case now is paused');
expect(audioPlayer.state).assertEqual('paused');
audioPlayer.setVolume(MAX_VOLUME);
});
}
function setResetCallback(audioPlayer, done) {
audioPlayer.on('reset', () => {
console.info('case reset success');
expect(audioPlayer.state).assertEqual('idle');
......@@ -83,13 +83,17 @@ describe('PlayerLocalTestAudioFormat', function () {
audioPlayer = undefined;
done();
});
}
function setStopCallback(audioPlayer) {
audioPlayer.on('stop', () => {
console.info('case stop success');
expect(audioPlayer.state).assertEqual('stopped');
audioPlayer.reset();
});
}
function setSeekCallback(audioPlayer, done) {
audioPlayer.on('timeUpdate', (seekDoneTime) => {
if (typeof (seekDoneTime) == "undefined") {
console.info(`case seek filed,errcode is ${seekDoneTime}`);
......@@ -108,19 +112,25 @@ describe('PlayerLocalTestAudioFormat', function () {
expect(audioPlayer.duration).assertEqual(seekDoneTime);
}
});
}
function setVolumeCallback(audioPlayer) {
audioPlayer.on('volumeChange', () => {
console.info('case set volume value to ' + MAX_VOLUME);
audioPlayer.play();
isToSeek = true;
});
}
function setFinishCallback(audioPlayer) {
audioPlayer.on('finish', () => {
console.info('case play end');
expect(audioPlayer.state).assertEqual('stopped');
audioPlayer.stop();
});
}
function setErrorCallback(audioPlayer, done) {
audioPlayer.on('error', (err) => {
console.info(`case error called,errName is ${err.name}`);
console.info(`case error called,errCode is ${err.code}`);
......@@ -129,6 +139,25 @@ describe('PlayerLocalTestAudioFormat', function () {
expect().assertFail();
done();
});
}
function playSource(audioSource, done) {
let audioPlayer = media.createAudioPlayer();
if (typeof (audioPlayer) == 'undefined') {
console.info('case create player is faild');
expect().assertFail();
done();
return;
}
setSrcCallback(audioPlayer);
setPlayCallback(audioPlayer);
setPauseCallback(audioPlayer);
setResetCallback(audioPlayer, done);
setStopCallback(audioPlayer);
setSeekCallback(audioPlayer, done);
setVolumeCallback(audioPlayer);
setFinishCallback(audioPlayer);
setErrorCallback(audioPlayer, done);
audioPlayer.src = audioSource;
}
......@@ -563,4 +592,4 @@ describe('PlayerLocalTestAudioFormat', function () {
it('SUB_MEDIA_PLAYER_LOCAL_Format_M4A_01_0700', 0, async function (done) {
playSource(BASIC_PATH + '62.m4a', done);
})
})
\ No newline at end of file
})
......@@ -127,8 +127,7 @@ describe('PlayerLocalTestAudioAPI', function () {
}
}
function setCallback(mySteps, done) {
console.info(`case setCallback`);
function setSrcCallback(mySteps) {
audioPlayer.on('dataLoad', () => {
mySteps.shift();
console.info(`case dataLoad called`);
......@@ -137,7 +136,9 @@ describe('PlayerLocalTestAudioAPI', function () {
expect(audioPlayer.state).assertEqual('paused');
nextStep(mySteps);
});
}
function setPlayCallback(mySteps) {
audioPlayer.on('play', () => {
mySteps.shift();
console.info(`case play called`);
......@@ -150,7 +151,9 @@ describe('PlayerLocalTestAudioAPI', function () {
expect(audioPlayer.state).assertEqual('playing');
nextStep(mySteps);
});
}
function setPauseCallback(mySteps) {
audioPlayer.on('pause', () => {
mySteps.shift();
console.info(`case pause called`);
......@@ -159,14 +162,18 @@ describe('PlayerLocalTestAudioAPI', function () {
expect(audioPlayer.state).assertEqual('paused');
nextStep(mySteps);
});
}
function setResetCallback(mySteps) {
audioPlayer.on('reset', () => {
mySteps.shift();
console.info(`case reset called`);
expect(audioPlayer.state).assertEqual('idle');
nextStep(mySteps);
});
}
function setStopCallback(mySteps) {
audioPlayer.on('stop', () => {
if (mySteps[0] == RESET_STATE) {
console.info(`case reset stop called`);
......@@ -179,7 +186,9 @@ describe('PlayerLocalTestAudioAPI', function () {
expect(audioPlayer.state).assertEqual('stopped');
nextStep(mySteps);
});
}
function setSeekCallback(mySteps) {
audioPlayer.on('timeUpdate', (seekDoneTime) => {
if (typeof (seekDoneTime) == 'undefined') {
console.info(`case seek filed,errcode is ${seekDoneTime}`);
......@@ -202,7 +211,9 @@ describe('PlayerLocalTestAudioAPI', function () {
nextStep(mySteps);
}
});
}
function setVolumeCallback(mySteps) {
audioPlayer.on('volumeChange', () => {
console.info(`case setvolume called`);
mySteps.shift();
......@@ -212,7 +223,9 @@ describe('PlayerLocalTestAudioAPI', function () {
}
nextStep(mySteps);
});
}
function setFinishCallback(mySteps) {
audioPlayer.on('finish', () => {
mySteps.shift();
expect(audioPlayer.state).assertEqual('stopped');
......@@ -220,7 +233,9 @@ describe('PlayerLocalTestAudioAPI', function () {
console.info(`case finish called`);
nextStep(mySteps);
});
}
function setErrorCallback(mySteps) {
audioPlayer.on('error', (err) => {
console.info(`case error called,errName is ${err.name}`);
console.info(`case error called,errCode is ${err.code}`);
......@@ -240,7 +255,19 @@ describe('PlayerLocalTestAudioAPI', function () {
nextStep(mySteps);
}
});
}
function setCallback(mySteps, done) {
console.info(`case setCallback`);
setSrcCallback(mySteps);
setPlayCallback(mySteps);
setPauseCallback(mySteps);
setResetCallback(mySteps);
setStopCallback(mySteps);
setSeekCallback(mySteps);
setVolumeCallback(mySteps);
setFinishCallback(mySteps);
setErrorCallback(mySteps);
setTimeout(function() {
if (!isTimeOut) {
console.info(`case is time out!`);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册