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

/ 6,925评论 / 27125阅读 / 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. 8DAY说道:

    Introducing to you the most prestigious online entertainment address today. Visit now to experience now!

  2. Derekjup说道:

    get cheap clomid without a prescription: rexpharm – can i buy generic clomid without a prescription

  3. Brandenven说道:

    amoxicillin 500 tablet: Com Pharm – buy amoxicillin 500mg usa

  4. StevenWearo说道:

    prednisone 20 mg tablets: cheap prednisone – can you buy prednisone

  5. Brandenven说道:

    where buy generic clomid tablets: generic clomid – can you get clomid online

  6. StevenWearo说道:

    can i purchase clomid now: clomid rex pharm – buy cheap clomid without prescription

  7. Derekjup说道:

    clomid without rx: cheap clomid – where to buy clomid online

  8. I have to thank you for the efforts you have put in writing this blog. I am hoping to see the same high-grade blog posts by you in the future as well. In fact, your creative writing abilities has encouraged me to get my own, personal blog now 😉

  9. StevenWearo说道:

    how much is prednisone 5mg: order Prednisone – prednisone in mexico

  10. Brandenven说道:

    prednisone canada pharmacy: 80 mg prednisone daily – prednisone 2.5 mg price

  11. Really liked reading this entry. It’s extremely articulate and packed with helpful information. Thank you for sharing this.

  12. Brandenven说道:

    order clomid no prescription: clomid purchase online rex pharm – can i order generic clomid no prescription

  13. Derekjup说道:

    amoxicillin 250 mg capsule: amoxil com pharm – where to buy amoxicillin

  14. StevenWearo说道:

    generic prednisone otc: Prednisone Without Prescription – prednisone 10 tablet

  15. StevenWearo说道:

    order amoxicillin no prescription: Amoxicillin for sale – amoxicillin 500mg price

  16. Brandenven说道:

    can i get clomid no prescription: get cheap clomid without insurance – can i purchase clomid tablets

  17. Introducing to you the most prestigious online entertainment address today. Visit now to experience now!

  18. Brandenven说道:

    cost of clomid now: clomid purchase online rex pharm – order generic clomid without rx

  19. Узнай все о варикоцеле левого яичка варикоцеле причины

  20. This is the perfect site for everyone who hopes to find out about this topic. You realize so much its almost hard to argue with you (not that I personally would want to…HaHa). You certainly put a new spin on a topic that has been written about for a long time. Wonderful stuff, just excellent.

  21. Adored the insight in this article. It’s highly detailed and full of useful information. Fantastic job!

  22. Fantastic entry. I found the details extremely helpful. Adored the method you detailed everything.

  23. Derekjup说道:

    cost of cheap clomid: clomid – get clomid online

  24. Узнай все о варикоцеле левого яичка заболевание варикоцеле

发表回复

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