修复音频暂停再播放问题

Signed-off-by: ywx1281445 <yuandongping@huawei.com>
This commit is contained in:
ywx1281445 2024-05-15 16:12:12 +08:00
parent dde6dcdd8e
commit 9b42ccc093
2 changed files with 16 additions and 13 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -70,17 +70,19 @@ export struct PlayView {
if (this.fileName !== '') {
Logger.info(TAG, `handleChangePlayState this.isPlay= ${this.playState}`);
if (!this.playState) {
Logger.info(TAG, `handleChangePlayState play start`);
this.audioModel.play(() => {
Logger.info(TAG, `handleChangePlayState play success`);
this.playState = !this.playState;
AppStorage.SetOrCreate('playState', this.playState);
})
this.playState = true;
AppStorage.SetOrCreate('playState', true);
});
} else {
Logger.info(TAG, `handleChangePlayState pause start`);
this.audioModel.pause(() => {
Logger.info(TAG, `handleChangePlayState pause success`);
this.playState = !this.playState;
AppStorage.SetOrCreate('playState', this.playState);
})
this.playState = false;
AppStorage.SetOrCreate('playState', false);
});
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2023-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -58,11 +58,12 @@ export class AudioModel {
}
onFinish(callback) {
console.info(`${TAG}set onFinish`)
Logger.info(TAG, `set onFinish`);
this.audioPlayer.on('finish', () => {
Logger.info(TAG, `audioPlayer finish called`)
this.audioPlayer.seek(0)
callback()
Logger.info(TAG, `audioPlayer finish called`);
this.audioPlayer.seek(0);
this.finish();
callback();
});
}
@ -96,7 +97,7 @@ export class AudioModel {
finish() {
if (typeof (this.audioPlayer) != `undefined`) {
this.audioPlayer.stop()
this.audioPlayer.pause();
}
}
}