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

/ 6,322评论 / 25293阅读 / 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. Williamfug说道:

    canadian neighbor pharmacy: my canadian pharmacy – drugs from canada

  2. DavidTaK说道:

    top 10 online pharmacy in india online pharmacy india indian pharmacy paypal

  3. Williamfug说道:

    trusted canadian pharmacy: canadian pharmacy scam – best online canadian pharmacy

  4. Felipelam说道:

    https://pharmnoprescription.icu/# canadian pharmacy no prescription required

  5. Felipelam说道:

    https://pharmindia.online/# top online pharmacy india

  6. Williamfug说道:

    canadian prescription drugstore review: pills no prescription – canadian mail order prescriptions

  7. DavidTaK说道:

    canada cloud pharmacy pharmacy rx world canada onlinepharmaciescanada com

  8. Williamfug说道:

    prescription drugs online canada: canadian pharmacy no prescription – non prescription online pharmacy india

  9. Donaldkenty说道:

    purple pharmacy mexico price list: medication from mexico pharmacy – mexican drugstore online

  10. DavidTaK说道:

    no prescription needed online pharmacy no prescription buying prescription drugs in india

  11. Williamfug说道:

    reputable indian pharmacies: indian pharmacy paypal – mail order pharmacy india

  12. DonaldtAg说道:

    canada pharmacy not requiring prescription: pharm world store – uk pharmacy no prescription

  13. Felipelam说道:

    https://pharmnoprescription.icu/# canada drugs no prescription

  14. DavidTaK说道:

    canadian pharmacy without prescription online pharmacy canadian pharmacy no prescription needed

  15. Felipelam说道:

    https://pharmmexico.online/# reputable mexican pharmacies online

  16. DonaldtAg说道:

    buying from online mexican pharmacy: mexico pharmacies prescription drugs – best online pharmacies in mexico

  17. Felipelam说道:

    http://pharmindia.online/# reputable indian pharmacies

  18. Williamfug说道:

    top 10 pharmacies in india: online pharmacy india – mail order pharmacy india

  19. Donaldkenty说道:

    mail order pharmacy india: top 10 online pharmacy in india – india online pharmacy

  20. DavidTaK说道:

    canada drugs no prescription buy medication online without prescription canadian drugs no prescription

  21. DonaldtAg说道:

    mexican drugstore online: mexican mail order pharmacies – mexican drugstore online

  22. DavidTaK说道:

    pharmacy no prescription required pharm world store mail order pharmacy no prescription

  23. Williamfug说道:

    online canadian pharmacy coupon: no prescription needed canadian pharmacy – online pharmacy discount code

  24. DavidTaK说道:

    mexican drugstore online purple pharmacy mexico price list mexican pharmaceuticals online

  25. Williamfug说道:

    pharmacy online 365 discount code: pharm world – canadian pharmacy discount coupon

  26. Felipelam说道:

    http://pharmindia.online/# top 10 pharmacies in india

  27. Felipelam说道:

    http://pharmworld.store/# canadian prescription pharmacy

  28. DavidTaK说道:

    online pharmacy no prescription needed cheapest pharmacy cheapest pharmacy to get prescriptions filled

  29. Williamfug说道:

    buying prescription drugs from canada: online pharmacy – foreign pharmacy no prescription

  30. Jeromeviaph说道:

    http://pharmworld.store/# online pharmacy no prescription

  31. DavidTaK说道:

    prescription free canadian pharmacy cheapest pharmacy international pharmacy no prescription

  32. DonaldtAg说道:

    online shopping pharmacy india: indianpharmacy com – top 10 online pharmacy in india

  33. DavidTaK说道:

    best online pharmacies in mexico best online pharmacies in mexico medicine in mexico pharmacies

  34. Williamfug说道:

    best mexican online pharmacies: mexican pharmacy – mexico pharmacy

  35. DonaldtAg说道:

    canadian pharmacy no prescription: online pharmacy no prescription – prescription drugs online canada

  36. Donaldkenty说道:

    online pharmacy no prescription: pharm world store – legal online pharmacy coupon code

  37. Williamfug说道:

    cheap canadian pharmacy: canadian online drugs – adderall canadian pharmacy

  38. DavidTaK说道:

    purple pharmacy mexico price list mexico pharmacies prescription drugs mexican drugstore online

  39. Jeromeviaph说道:

    https://pharmmexico.online/# pharmacies in mexico that ship to usa

  40. Felipelam说道:

    https://pharmworld.store/# overseas pharmacy no prescription

  41. Felipelam说道:

    http://pharmmexico.online/# medication from mexico pharmacy

  42. Williamfug说道:

    canada pharmacy online: canada pharmacy 24h – canadianpharmacymeds

  43. Jamesexite说道:

    order viagra: Buy Viagra online cheap – Viagra online price

  44. Charlesvox说道:

    http://levitrav.store/# Buy Vardenafil 20mg

  45. Elmersoalf说道:

    Viagra without a doctor prescription Canada Buy Viagra online cheap cheap viagra

  46. Georgefrege说道:

    Cheapest Sildenafil online: sildenafil online – Viagra online price

  47. Charlesvox说道:

    https://cialist.pro/# Buy Cialis online

发表回复

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