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

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

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