• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

微信小程序如何播放音频,这里以本地mp3文件举例。

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

参考:https://blog.csdn.net/bangyiqing/article/details/104966135      官方文档:https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/InnerAudioContext.html

 

Page({
    data: {
        show: true,
        current: 0,
        playTwo: true,
    },
    // 点击领取礼包
    getward: function() {
        this.setData({
            show: false
        })
    },
    // 点击在看一次
    gofirst: function() {
        this.setData({
            show: true,
            current: 0
        })
    },
    // 音乐图标旋转
    playTwo: function() {
        this.setData({
            playTwo: !this.data.playTwo
        })
        if (this.data.playTwo) {
            this.data.innerAudioContext.play();
        } else {
            this.data.innerAudioContext.pause();
        }
    },
    handleChange: function(event) {
        console.log(event.detail)
        if (event.detail.source === "touch") {
            this.setData({
                current: event.detail.current
            })
        }
    },
    playmp3: function(event) {
        let srcurl = "/packageC/activety/小啊Giao.mp3"
        this.data.innerAudioContext.autoplay = true
        this.data.innerAudioContext.src = srcurl
        this.data.innerAudioContext.onPlay(() => {
            console.log(\'开始播放\')
        })
        this.mp3stop()
    },
    // 监听音频停止事件
    mp3stop: function(e) {
        let that = this
        that.data.innerAudioContext.onEnded((res) => {
            that.data.innerAudioContext.play();
        })
    },
    onLoad: function(options) {
        this.setData({
            innerAudioContext: wx.createInnerAudioContext()
        })
    },
    onReady: function() {},
    onShow: function() {
        this.playmp3()
    },
    onHide: function() {
        // this.data.innerAudioContext.destroy()
    },
    onUnload: function() {
        this.data.innerAudioContext.destroy()
    },
    onPullDownRefresh: function() {
        //Do some when page pull down.

    }
})

  

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
微信小程序音乐播放器发布时间:2022-07-18
下一篇:
微信小程序—添加背景音乐发布时间:2022-07-18
热门推荐
    热门话题
    阅读排行榜

    扫描微信二维码

    查看手机版网站

    随时了解更新最新资讯

    139-2527-9053

    在线客服(服务时间 9:00~18:00)

    在线QQ客服
    地址:深圳市南山区西丽大学城创智工业园
    电邮:jeky_zhao#qq.com
    移动电话:139-2527-9053

    Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap