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

摘要:
https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/InnerAudioContext.htmlPage({data:当前:

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

    }
})

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

免责声明:文章转载自《微信小程序如何播放音频,这里以本地mp3文件举例。》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Windows利用easyBCD装Ubuntu双系统一起学Android之ContentProvider下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

如何在CentOS里切换操作系统所用的语言,中英文切换

 操作系统CentOS 7.5,安装的时候选择的事中文,后来想改成英文    1、点左上角的“应用程序”---->再点“系统工具”----->“设置”       2、点“区域语言”,再点右侧的“汉语(中国)”         3、由“”汉语(中国)”改选为“English (United States)”,点右上角的“完成”按钮 4、点“R...

c++ string 的函数replace()用法

basic_string::replace 将原string 中的元素或子串替换。返回替换后的string。 (1)用string 或C-string 代替操作string 中从 _Pos1 开始的 _Num1 个字符 basic _ string& replace( size _ type _Pos1 ,size _ type _Num1 ,...

CSS中关于多个class样式设置的不同写法

html中:  <div class="containerA"> 这是AAAAAAAAAAAAAAAAAAAAAAA样式 <div class="containerB"> 这是BBBBBBBBBBBBBBBBBBBBBB样式 </div> </div>  css中: .containerA .containe...

MFC/HALCON混合编程系列一_相机打开图像_简单处理_

1.说明         通过相机打开一幅图像,然后处理此图像并显示最终结果。使用的Hdevelop的代码如下:   从Hdevelop导出的C++代码如下: /////////////////////////////////////////////////////////////////////////////// // File generated...

Bootstrap Dual Listbox动态数据实现

效果图如下:  一:需要依赖的文件 <link rel="stylesheet" href="assets/css/bootstrap.min.css" /> <link rel="stylesheet" href="assets/css/bootstrap-duallistbox.min.css" /> <script s...

[asp常用代码]文件上传代码

调用实例: UploadDemo.html<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><title>Upload Demo</title><meta name="keywords" co...