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

/ 6,346评论 / 25345阅读 / 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. Billyeroge说道:

    http://gabapentinneurontin.pro/# buy neurontin online no prescription

  2. Billyeroge说道:

    https://zithromaxa.store/# zithromax price canada

  3. Richardfrota说道:

    doxycycline 200 mg: doxycycline 100 mg – buy doxycycline 100mg

  4. HenryIsona说道:

    generic zithromax medicine: zithromax 1000 mg online – zithromax 500 mg lowest price drugstore online

  5. MarvinMek说道:

    buying amoxicillin in mexico amoxicillin tablets in india buy amoxicillin

  6. CharlesGib说道:

    doxycycline 100mg dogs: doxycycline 100mg tablets – how to buy doxycycline online

  7. MarvinMek说道:

    prednisone 4mg tab generic prednisone pills how to buy prednisone online

  8. HenryIsona说道:

    can you buy zithromax over the counter in canada: zithromax antibiotic – where to get zithromax

  9. MarvinMek说道:

    doxycycline hyc doxycycline hyclate buy doxycycline

  10. Billyeroge说道:

    http://amoxila.pro/# cost of amoxicillin 875 mg

  11. HenryIsona说道:

    over the counter prednisone medicine: prednisone rx coupon – buying prednisone

  12. Billyeroge说道:

    http://zithromaxa.store/# buy zithromax without prescription online

  13. Billyeroge说道:

    http://prednisoned.online/# prednisone buy without prescription

  14. MarvinMek说道:

    zithromax z-pak zithromax 500 mg lowest price drugstore online zithromax cost canada

  15. HenryIsona说道:

    doxycycline 100mg: where to get doxycycline – doxycycline pills

  16. Richardfrota说道:

    gabapentin 100mg: canada neurontin 100mg lowest price – prescription drug neurontin

  17. CharlesGib说道:

    buy doxycycline 100mg: doxycycline 100mg tablets – where can i get doxycycline

  18. CharlesGib说道:

    amoxicillin 500 mg purchase without prescription: amoxicillin medicine – cheap amoxicillin 500mg

  19. MarvinMek说道:

    order neurontin online neurontin 600 mg cost neurontin prices

  20. MarvinMek说道:

    can i buy prednisone over the counter in usa prednisone 5093 prednisone 5 50mg tablet price

  21. HenryIsona说道:

    buy neurontin online no prescription: neurontin 100mg tablet – buy cheap neurontin

  22. Billyeroge说道:

    http://amoxila.pro/# amoxicillin medicine over the counter

  23. HenryIsona说道:

    where to buy amoxicillin 500mg: amoxicillin order online no prescription – amoxicillin generic

  24. MarvinMek说道:

    amoxicillin medicine where can you get amoxicillin amoxicillin buy canada

  25. Billyeroge说道:

    https://doxycyclinea.online/# buy cheap doxycycline online

  26. Richardfrota说道:

    neurontin prices: neurontin buy online – 32 neurontin

  27. HenryIsona说道:

    prednisone tablets 2.5 mg: prednisone 20mg buy online – prednisone 20mg capsule

  28. MarvinMek说道:

    prednisone generic brand name prednisone 10mg prednisone buy

  29. CharlesGib说道:

    how to get amoxicillin over the counter: amoxicillin azithromycin – order amoxicillin online uk

  30. MarvinMek说道:

    where can i get doxycycline doxycycline without prescription doxycycline 100mg price

  31. HenryIsona说道:

    prednisone 5093: prednisone without a prescription – buy prednisone online without a prescription

  32. Billyeroge说道:

    http://zithromaxa.store/# zithromax pill

  33. HenryIsona说道:

    where can i purchase zithromax online: zithromax order online uk – order zithromax without prescription

  34. MarvinMek说道:

    20 mg of prednisone purchase prednisone no prescription average cost of prednisone

  35. Billyeroge说道:

    https://amoxila.pro/# amoxicillin 750 mg price

  36. HenryIsona说道:

    10 mg prednisone tablets: prednisone uk price – how much is prednisone 10 mg

  37. Richardfrota说道:

    neurontin mexico: neurontin 100mg caps – neurontin 600 mg pill

  38. MarvinMek说道:

    amoxicillin 500mg buy online canada price of amoxicillin without insurance buy amoxicillin online cheap

  39. CharlesGib说道:

    amoxicillin buy no prescription: cost of amoxicillin – order amoxicillin no prescription

  40. MarvinMek说道:

    over the counter prednisone pills prednisone over the counter prednisone 2.5 mg

  41. Richardfrota说道:

    amoxicillin pills 500 mg: where to buy amoxicillin pharmacy – amoxicillin in india

  42. HenryIsona说道:

    order doxycycline 100mg without prescription: where to get doxycycline – buy doxycycline without prescription

  43. CharlesGib说道:

    can you buy zithromax over the counter in mexico: zithromax prescription online – zithromax 500 mg lowest price drugstore online

  44. Billyeroge说道:

    https://prednisoned.online/# prednisone canada

  45. HenryIsona说道:

    buy zithromax canada: buy zithromax 500mg online – zithromax purchase online

  46. MarvinMek说道:

    amoxicillin tablets in india amoxicillin 1000 mg capsule medicine amoxicillin 500

  47. Billyeroge说道:

    https://doxycyclinea.online/# buy doxycycline cheap

  48. Billyeroge说道:

    http://prednisoned.online/# prednisone 5 mg tablet

  49. HenryIsona说道:

    purchase amoxicillin online: amoxicillin canada price – amoxicillin cost australia

发表回复

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