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

/ 6,350评论 / 25357阅读 / 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. Manuelloupe说道:

    reputable mexican pharmacies online mexican border pharmacies shipping to usa medication from mexico pharmacy

  2. Robertswela说道:

    buying from online mexican pharmacy: mexico drug stores pharmacies – mexican online pharmacies prescription drugs

  3. KennethFobby说道:

    http://mexicanpharmacy1st.com/# mexican border pharmacies shipping to usa

  4. Williamlyday说道:

    https://mexicanpharmacy1st.online/# best online pharmacies in mexico

  5. Williamlyday说道:

    https://mexicanpharmacy1st.shop/# buying prescription drugs in mexico

  6. Robertswela说道:

    mexican mail order pharmacies: mexican drugstore online – mexico pharmacies prescription drugs

  7. KennethFobby说道:

    https://mexicanpharmacy1st.online/# п»їbest mexican online pharmacies

  8. Manuelloupe说道:

    mexican drugstore online mexican mail order pharmacies mexico drug stores pharmacies

  9. Albertnab说道:

    mexican pharmaceuticals online: mexican pharmaceuticals online – reputable mexican pharmacies online

  10. Manuelloupe说道:

    buying prescription drugs in mexico online medication from mexico pharmacy pharmacies in mexico that ship to usa

  11. Albertnab说道:

    mexican online pharmacies prescription drugs: mexico pharmacies prescription drugs – medication from mexico pharmacy

  12. Robertswela说道:

    mexican rx online: buying prescription drugs in mexico online – mexican online pharmacies prescription drugs

  13. Thomasliest说道:

    mexican border pharmacies shipping to usa: mexico drug stores pharmacies – reputable mexican pharmacies online

  14. Robertswela说道:

    mexican drugstore online: pharmacies in mexico that ship to usa – mexican pharmaceuticals online

  15. Manuelloupe说道:

    mexican pharmaceuticals online п»їbest mexican online pharmacies п»їbest mexican online pharmacies

  16. Williamlyday说道:

    https://mexicanpharmacy1st.online/# mexican drugstore online

  17. Williamlyday说道:

    http://mexicanpharmacy1st.com/# medication from mexico pharmacy

  18. Robertswela说道:

    mexican rx online: mexico drug stores pharmacies – best online pharmacies in mexico

  19. Manuelloupe说道:

    mexico drug stores pharmacies mexican pharmaceuticals online mexican drugstore online

  20. Albertnab说道:

    mexican mail order pharmacies: buying prescription drugs in mexico – mexican rx online

  21. KennethFobby说道:

    http://mexicanpharmacy1st.com/# buying prescription drugs in mexico online

  22. Manuelloupe说道:

    best online pharmacies in mexico best online pharmacies in mexico mexican online pharmacies prescription drugs

  23. Robertswela说道:

    pharmacies in mexico that ship to usa: best online pharmacies in mexico – mexican pharmacy

  24. Manuelloupe说道:

    pharmacies in mexico that ship to usa mexican rx online mexican drugstore online

  25. Robertswela说道:

    mexican drugstore online: buying prescription drugs in mexico online – buying prescription drugs in mexico

  26. Williamlyday说道:

    https://mexicanpharmacy1st.com/# buying prescription drugs in mexico

  27. Williamlyday说道:

    http://mexicanpharmacy1st.com/# medication from mexico pharmacy

  28. Thomasliest说道:

    medicine in mexico pharmacies: reputable mexican pharmacies online – п»їbest mexican online pharmacies

  29. Robertswela说道:

    best mexican online pharmacies: buying prescription drugs in mexico – mexico drug stores pharmacies

  30. Williamlyday说道:

    https://mexicanpharmacy1st.online/# mexico drug stores pharmacies

  31. Manuelloupe说道:

    buying prescription drugs in mexico online п»їbest mexican online pharmacies buying from online mexican pharmacy

  32. Manuelloupe说道:

    mexican rx online mexican rx online mexican rx online

  33. Albertnab说道:

    buying from online mexican pharmacy: п»їbest mexican online pharmacies – mexico drug stores pharmacies

  34. Thomasliest说道:

    mexican rx online: mexican mail order pharmacies – mexican mail order pharmacies

  35. KennethFobby说道:

    https://mexicanpharmacy1st.online/# mexican border pharmacies shipping to usa

  36. Albertnab说道:

    buying prescription drugs in mexico online: mexico drug stores pharmacies – medication from mexico pharmacy

  37. Robertswela说道:

    mexico pharmacy: mexico pharmacy – mexican online pharmacies prescription drugs

  38. KennethFobby说道:

    https://mexicanpharmacy1st.com/# mexican border pharmacies shipping to usa

  39. Manuelloupe说道:

    mexican border pharmacies shipping to usa pharmacies in mexico that ship to usa medication from mexico pharmacy

  40. Robertswela说道:

    mexican pharmacy: mexican mail order pharmacies – mexican pharmacy

  41. Williamlyday说道:

    https://mexicanpharmacy1st.online/# mexican drugstore online

  42. Williamlyday说道:

    https://mexicanpharmacy1st.online/# mexico drug stores pharmacies

  43. Williamlyday说道:

    https://mexicanpharmacy1st.shop/# mexican border pharmacies shipping to usa

  44. Robertswela说道:

    best online pharmacies in mexico: mexican mail order pharmacies – mexican online pharmacies prescription drugs

  45. HenryIsona说道:

    purchase amoxicillin online: ampicillin amoxicillin – buy amoxicillin 500mg usa

  46. MarvinMek说道:

    doxycycline 100mg doxycycline doxycycline 50mg

  47. Billyeroge说道:

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

  48. MarvinMek说道:

    otc prednisone cream over the counter prednisone cheap prednisone brand name india

  49. HenryIsona说道:

    doxycycline 100mg capsules: order doxycycline online – doxycycline generic

发表回复

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