代码拉取完成,页面将自动刷新
同步操作将从 OpenHarmony-SIG/knowledge_demo_temp 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
本文档为《标准设备应用开发—动画与音乐》课程文档,课程项目可实现音乐播放和动画效果。
阿里云盘:https://www.aliyundrive.com/s/fgto2FbUpbK
百度网盘:https://pan.baidu.com/s/1vwkNAn7iXbcol05pfjki5A?pwd=wqty
@State pointerAngle: number = 0 // 指针旋转角度
@State turntableAngle: number = 0 // 唱盘旋转角度
private turntableTimer: number // 唱盘定时器
Image($r("app.media.img_pointer"))
.objectFit(ImageFit.Contain)
.aspectRatio(1.32)
.width('40%')
.alignSelf(ItemAlign.Start)
.rotate({
x: 0,
y: 0,
z: 1,
centerX: 0,
centerY: 0,
angle: this.pointerAngle
})
.offset({ x: '50%', y: '0%' })
playAnimation() {
// if (this.turntableTimer) {
// return
// }
// 唱盘转动动画
let fun = () => {
animateTo({ duration: 1500, curve: Curve.Linear, playMode: PlayMode.Normal },
() => {
this.turntableAngle = this.turntableAngle + 90;
})
}
fun()
// this.turntableTimer = setInterval(fun, 1500)
// 唱盘指针下拨动画
animateTo({ duration: 1000, curve: Curve.EaseInOut, playMode: PlayMode.Normal },
() => {
this.pointerAngle = 39;
})
}
// 暂停音乐动画
pauseAnimation() {
// 清除唱盘转动定时器
// if (this.turntableTimer) {
// this.turntableAngle = this.turntableAngle
// clearInterval(this.turntableTimer)
// this.turntableTimer = undefined
// }
// 唱盘指针上拨动画
animateTo({ duration: 1500, curve: Curve.EaseInOut, playMode: PlayMode.Normal },
() => {
this.pointerAngle = 0;
})
}
4.编写播放事件并绑定
// 播放或暂停音乐
onPlayOrPauseMusic() {
if (this.isPlaying) {
CommonLog.info("Start to pause music")
this.pauseAnimation()
}
else {
CommonLog.info("Start to play music")
this.playAnimation()
}
this.isPlaying = !this.isPlaying
}
进度条拖动
// 音乐进度变化
onChangeMusicProgress(value: number, mode: SliderChangeMode) {
if (this.isSwitching) {
CommonLog.info('onChangeMusicProgress ignored, isSwitching');
return;
}
this.isSwitching = true
CommonLog.info('value:' + value + 'mode:' + mode.toString())
this.currentProgress = value
if (this.totalTimeText != '00:00') {
let currentMS = this.currentProgress / 100 * this.playerManager.getTotalTimeMs()
this.currentTimeText = this.getShownTimer(currentMS)
CommonLog.info('onChangeMusicProgress:' + currentMS)
this.playerManager.seek(currentMS)
} else {
CommonLog.info('onChangeMusicProgress:bbb')
this.currentProgress = 0
}
this.isSwitching = false
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。