zoukankan      html  css  js  c++  java
  • 微信小程序如何播放音频,这里以本地mp3文件举例。

    参考: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.
    
        }
    })
    

      

    苦心人,天不负
  • 相关阅读:
    纯快排
    Quick Sort(快速排序)
    归并排序 ALDS1_5_B:Merge Sort
    单调栈(POJ2559)
    Sequence
    Codeforces Round #503
    度度熊学队列
    Always Online hdu 6350
    Hills And Valleys
    Problem G. Depth-First Search
  • 原文地址:https://www.cnblogs.com/taxun/p/14348015.html
Copyright © 2011-2022 走看看