[vue3]audio音乐进度条(二)跟随播放进度

/ 6,335评论 / 25327阅读 / 2点赞

上一期我们介绍了外观设计,这把我们聊聊让进度条跟随播放进度走

预期效果


准备


实现

<div id="root_div" class="cmusic_displayFlex_class" style="height:150px;justify-content:space-between;align-items: center;">
    <!-- 音频 -->
    <audio id="cmusic_audio" ref="cmusic_audio" controls muted
        @timeupdate="audio_lengthChange()" :src="url_audio">
    </audio>

    <span id="cmusic_control_span_progressBar">
        <div class="cmusic_displayFlex_class cmusic_control_progress_div" style="flex-direction: row;">
            <span id="cmusic_control_span_loadProgress" :style="cmusic_control_loadProgress_style"></span>
            <span id="cmusic_control_span_progress" :style="cmusic_control_progress_style"></span>
        </div>
    </span>
<div>
<style>
/*外框*/
#cmusic_control_span_progressBar{
    border-radius: 50px;
    height: 20px;
    width: 100%;
    display: inline-flex;
    align-items: center;
    position: relative;
    background: transparent;
    box-shadow: inset 2px 2px 4px #bcc5d6,
        inset -2px -2px 5px #feffff;
    border: 2px solid #d0f4ff;
    justify-content: center;
    transition: all 0.8s ease;
}
/*布局类*/
.cmusic_displayFlex_class {
    width: 100%;
    display: flex;
    flex-direction: column;
    margin-left: auto;
    margin-right: auto;
}
.cmusic_control_progress_div {
    position:absolute;
    width:94% !important;
    height:100%;
    align-items: center;
}
/*进度条*/
#cmusic_control_span_progress,
#cmusic_control_span_loadProgress{
    background: linear-gradient(90deg, #c4f4fe, #66ccff);
    border-radius: 50px;
    position: absolute;
    width:100%;
    height: 60%;
    pointer-events: none;
    transition: width 0.5s ease;
    box-shadow: 2px 2px 10px #ccd3ff,
    -2px -2px 10px #ccd3ff;
}
/*加载进度条*/
#cmusic_control_span_loadProgress {
    background: linear-gradient(90deg, #abecd6, #fff9d2);
}
</style>
<!-- 引入vue -->
<script src="https://unpkg.com/vue@3.2.33"></script>
<script>
const { createApp } = Vue

var cmusic_json = {
    //数据
    data() {
        return {
            url_audio:"https://blog.coolight.cool/wp-content/uploads/2022/05/大喜_洛天依.m4a",
            cmusic_control_loadProgress_style:"width:80%",
            cmusic_control_progress_style:"width:50%"
        }
    },
    //函数
    methods:{
        //监听播放时长,修改进度条长度
        audio_lengthChange:function(){
            let caudio = this.$refs.cmusic_audio;
            //duration是音频总时长
            //如果音频元数据加载完成,才能获得其总时长,后续才能进行计算
            if (!isNaN(caudio.duration)){
                this.cmusic_control_progress_style = "width:" + (parseInt(caudio.currentTime / caudio.duration * 100)).toString() + "%;";
            }else{
                this.cmusic_control_progress_style = "width:0%;";
            }
        }
    }
};

var cmusic_app = Vue.createApp(cmusic_json);
var cmusic_vue = cmusic_app.mount("#root_div");
</script>
  1. MarvinMek说道:

    prednisone 10mg tablet price buy prednisone 1 mg mexico prednisone 500 mg tablet

  2. Richardfrota说道:

    zithromax 500mg over the counter: zithromax capsules – zithromax 250 mg

  3. MarvinMek说道:

    doxycycline generic doxycycline medication buy doxycycline online

  4. HenryIsona说道:

    neurontin 400 mg cost: neurontin generic brand – neurontin 300 mg cost

  5. Billyeroge说道:

    http://amoxila.pro/# amoxicillin script

  6. HenryIsona说道:

    prednisone: india buy prednisone online – buy prednisone online paypal

  7. CharlesGib说道:

    doxycycline 50mg: doxycycline 100mg online – buy doxycycline 100mg

  8. Billyeroge说道:

    https://zithromaxa.store/# how to buy zithromax online

  9. HenryIsona说道:

    prednisone over the counter cost: prednisone 54 – prednisone daily

  10. MarvinMek说道:

    buy amoxicillin 500mg uk buy amoxicillin online cheap amoxicillin capsule 500mg price

  11. HenryIsona说道:

    doxycycline prices: doxycycline generic – buy generic doxycycline

  12. Billyeroge说道:

    https://zithromaxa.store/# zithromax 250 mg tablet price

  13. HenryIsona说道:

    zithromax tablets: how to get zithromax – where to buy zithromax in canada

  14. MarvinMek说道:

    amoxicillin 500 mg capsule amoxicillin capsule 500mg price amoxicillin buy online canada

  15. Billyeroge说道:

    https://gabapentinneurontin.pro/# order neurontin online

  16. Billyeroge说道:

    https://zithromaxa.store/# zithromax order online uk

  17. Richardfrota说道:

    buy brand neurontin: prescription drug neurontin – neurontin 10 mg

  18. HenryIsona说道:

    doxycycline order online: doxycycline 50 mg – 100mg doxycycline

  19. CharlesGib说道:

    neurontin 330 mg: neurontin cream – neurontin price in india

  20. Richardfrota说道:

    neurontin uk: neurontin cost in singapore – neurontin tablets 300mg

  21. CharlesGib说道:

    amoxicillin cost australia: generic amoxicillin online – amoxicillin online without prescription

  22. MarvinMek说道:

    how can i order prednisone prednisone 5 mg tablet rx prednisone 50

  23. MarvinMek说道:

    buy doxycycline monohydrate doxycycline hyclate doxycycline 50 mg

  24. HenryIsona说道:

    neurontin 300 mg pill: neurontin brand coupon – 32 neurontin

  25. HenryIsona说道:

    prednisone over the counter australia: prednisone price canada – prednisone 4mg

  26. Billyeroge说道:

    http://prednisoned.online/# prednisone 4mg tab

  27. MarvinMek说道:

    doxycycline 50 mg doxycycline hyc 100mg doxycycline 100mg capsules

  28. Billyeroge说道:

    https://doxycyclinea.online/# how to order doxycycline

  29. HenryIsona说道:

    online doxycycline: order doxycycline online – where to purchase doxycycline

  30. Billyeroge说道:

    http://prednisoned.online/# prednisone 2 mg daily

  31. Richardfrota说道:

    amoxicillin price canada: amoxicillin 500mg – where can you get amoxicillin

  32. MarvinMek说道:

    how to buy doxycycline online doxycycline 50mg doxycycline 100mg tablets

  33. CharlesGib说道:

    buy cheap amoxicillin online: where can i buy amoxicillin over the counter uk – amoxicillin 500mg capsules price

  34. MarvinMek说道:

    order amoxicillin 500mg amoxil pharmacy canadian pharmacy amoxicillin

  35. HenryIsona说道:

    100 mg prednisone daily: prednisone brand name us – over the counter prednisone cream

  36. HenryIsona说道:

    doxycycline medication: purchase doxycycline online – generic doxycycline

  37. MarvinMek说道:

    amoxicillin 500mg for sale uk where to get amoxicillin over the counter amoxicillin azithromycin

  38. HenryIsona说道:

    amoxicillin online without prescription: prescription for amoxicillin – amoxicillin script

  39. Billyeroge说道:

    http://prednisoned.online/# prednisone coupon

  40. MarvinMek说道:

    zithromax prescription buy zithromax online fast shipping zithromax 500 tablet

  41. HenryIsona说道:

    zithromax generic price: zithromax capsules – zithromax online no prescription

  42. MarvinMek说道:

    neurontin cost generic buying neurontin without a prescription neurontin medicine

  43. Richardfrota说道:

    drug neurontin 20 mg: neurontin brand name 800mg – neurontin brand name in india

  44. CharlesGib说道:

    prednisone pill: prednisone 50 mg tablet canada – prednisone cost in india

  45. HenryIsona说道:

    neurontin capsules 100mg: where to buy neurontin – buying neurontin online

  46. Billyeroge说道:

    https://zithromaxa.store/# buy zithromax online with mastercard

  47. Richardfrota说道:

    cheap zithromax pills: zithromax 250 mg – generic zithromax 500mg

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注