mirror of
https://gitee.com/openharmony/applications_app_samples
synced 2024-11-28 03:00:49 +00:00
修复音频暂停再播放问题
Signed-off-by: ywx1281445 <yuandongping@huawei.com>
This commit is contained in:
parent
dde6dcdd8e
commit
9b42ccc093
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user