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

/ 6,330评论 / 25311阅读 / 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. HenryIsona说道:

    prednisone online india: order prednisone – prednisone online sale

  2. MarvinMek说道:

    zithromax 500mg price how to buy zithromax online zithromax cost

  3. CharlesGib说道:

    cost of prednisone 10mg tablets: 50mg prednisone tablet – price of prednisone 5mg

  4. Billyeroge说道:

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

  5. Billyeroge说道:

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

  6. MarvinMek说道:

    doxycycline order online buy cheap doxycycline where to purchase doxycycline

  7. MarvinMek说道:

    prednisone 20mg price prednisone 15 mg daily prednisone buying

  8. HenryIsona说道:

    buying neurontin without a prescription: neurontin 100mg caps – neurontin brand name 800mg best price

  9. Richardfrota说道:

    buy neurontin: neurontin cap 300mg – neurontin 300 mg price in india

  10. HenryIsona说道:

    purchase doxycycline online: doxycycline 500mg – odering doxycycline

  11. MarvinMek说道:

    zithromax for sale usa zithromax canadian pharmacy zithromax 500

  12. HenryIsona说道:

    how to get neurontin: neurontin tablets no script – neurontin 600 mg

  13. Billyeroge说道:

    http://doxycyclinea.online/# buy doxycycline for dogs

  14. Billyeroge说道:

    https://zithromaxa.store/# can you buy zithromax over the counter

  15. CharlesGib说道:

    doxycycline mono: generic doxycycline – doxycycline tetracycline

  16. MarvinMek说道:

    amoxicillin 500mg prescription can you buy amoxicillin over the counter amoxicillin 500mg buy online uk

  17. MarvinMek说道:

    neurontin 300mg neurontin 100 mg caps neurontin 204

  18. MarvinMek说道:

    zithromax 500 price zithromax cost uk buy azithromycin zithromax

  19. HenryIsona说道:

    cost of neurontin 600 mg: prescription medication neurontin – how much is neurontin pills

  20. Billyeroge说道:

    http://zithromaxa.store/# buy azithromycin zithromax

  21. HenryIsona说道:

    doxycycline hydrochloride 100mg: generic doxycycline – doxycycline 50 mg

  22. Billyeroge说道:

    http://gabapentinneurontin.pro/# price of neurontin

  23. Billyeroge说道:

    https://doxycyclinea.online/# order doxycycline

  24. MarvinMek说道:

    neurontin 400 mg cost neurontin cap 300mg price neurontin price

  25. MarvinMek说道:

    neurontin 600 mg cost neurontin 400 mg price generic neurontin 300 mg

  26. Richardfrota说道:

    prednisone 50mg cost: prednisone 20mg – prednisone 4 mg daily

  27. CharlesGib说道:

    amoxicillin tablets in india: amoxicillin no prescription – amoxicillin 500 mg tablets

  28. HenryIsona说道:

    where can i buy prednisone without a prescription: 54 prednisone – how to buy prednisone

  29. Richardfrota说道:

    doxycycline pills: doxycycline 100mg – doxycycline 50 mg

  30. CharlesGib说道:

    zithromax z-pak price without insurance: zithromax 500mg price in india – zithromax prescription

  31. MarvinMek说道:

    buy doxycycline without prescription uk order doxycycline 100mg without prescription generic doxycycline

  32. HenryIsona说道:

    buy amoxicillin 500mg online: where to buy amoxicillin pharmacy – medicine amoxicillin 500mg

  33. Billyeroge说道:

    http://zithromaxa.store/# how to get zithromax over the counter

  34. HenryIsona说道:

    doxycycline hyclate: generic doxycycline – buy doxycycline online uk

  35. Billyeroge说道:

    http://gabapentinneurontin.pro/# neurontin buy from canada

  36. Billyeroge说道:

    https://prednisoned.online/# can i buy prednisone online in uk

  37. MarvinMek说道:

    buy amoxicillin online cheap generic amoxil 500 mg amoxicillin online pharmacy

  38. MarvinMek说道:

    neurontin 300 neurontin without prescription neurontin 600 mg pill

  39. Richardfrota说道:

    prednisone 2.5 mg cost: prednisone 30 mg coupon – prednisone 300mg

  40. HenryIsona说道:

    amoxicillin where to get: amoxicillin 500 mg online – how to buy amoxycillin

  41. MarvinMek说道:

    how much is prednisone 10 mg prednisone 20mg buy online over the counter prednisone medicine

  42. HenryIsona说道:

    neurontin 300 mg: neurontin discount – neurontin 900 mg

  43. CharlesGib说道:

    amoxicillin for sale online: amoxicillin order online no prescription – amoxicillin order online

  44. HenryIsona说道:

    buy azithromycin zithromax: buy zithromax online australia – zithromax capsules australia

  45. HenryIsona说道:

    buying amoxicillin online: purchase amoxicillin online – amoxicillin cost australia

  46. HenryIsona说道:

    amoxicillin no prescipion: amoxicillin online purchase – amoxicillin online no prescription

  47. Richardfrota说道:

    where to get zithromax: buy cheap zithromax online – purchase zithromax online

  48. CharlesGib说道:

    neurontin brand name in india: buy gabapentin online – neurontin capsules 600mg

  49. HenryIsona说道:

    how much is generic neurontin: how to get neurontin – drug neurontin 20 mg

发表回复

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