• uniapp的录音与播放


    录音

    onLoad(options) {
        let that=this
        this.recorderManager = uni.getRecorderManager(); //创建录音管理
    },
    
    methods:{
        //开始录音
        startRecord(index){
        let that=this
        uni.authorize({
            scope:"scope.record",
            success(){
            uni.showToast({
                icon:"none",
                title:"开始录音"
            })
            that.recorderManager.start();
            that.recorderManager.onStart()
            console.log("录音执行")
            },
            fail() {
            uni.showModal({
                title: '提示',
                content: '您未授权录音,功能将无法使用',
                showCancel: true,
                confirmText: "授权",
                confirmColor: "#52a2d8",
                success(res) {
                    if(res.confirm){
                    uni.openSetting({
                    
                                })
                }else{
                                        
                }
                }
            })
            }
        })
        },
    
    
        //结束录音
        endRecord(index){
        let that=this
        uni.stopRecord({
            success:function(e){
            that.recorderManager.stop();
                that.recorderManager.onStop((res=>{
                that.audioTempFile=res.tempFilePath
                that.uploadAudio(index)
            }))
            }
        })
        }
    }        

    播放音频文件

    onLoad(options) {
        let innerAudioContext = uni.createInnerAudioContext();    //创建音频文件
        innerAudioContext.autoplay = false;    //不自动播放
        innerAudioContext.src = this.audioSrc;    //音频文件链接
        this.innerAudioContext=innerAudioContext
    },
    
    methods:{
        //开始音频文件
        startAudio(){
            this.innerAudioContext.play(() => {
        console.log('开始播放');
            });
        this.innerAudioContext.onError((res) => {
            console.log(res.errMsg);
            console.log(res.errCode);
        });
        },
    
        //结束音频
        endAudio(){
        let that=this
        uni.showToast({
            icon:"none",
            title:"已结束"
        })
        this.innerAudioContext.stop(() => {
            console.log('已暂停');
        });
        this.innerAudioContext.onError((res) => {
            console.log(res.errMsg);
            console.log(res.errCode);
        });
        },
    
        //暂停音频文件
        pauseAudio(desc){
            let that=this
        uni.showToast({
            icon:"none",
            title:desc
        })
        this.innerAudioContext.pause(() => {
            console.log('已暂停');
        });
        this.innerAudioContext.onError((res) => {
            console.log(res.errMsg);
             console.log(res.errCode);
        });
        }
    }    
  • 相关阅读:
    搭建docker私有registory (harbor)
    消息队列原理及ActiveMQ、RocketMQ、RabbitMQ、Kafka区别总结
    too many users are authenticated
    docker环境部署nginx、tomcat、redis
    docekr环境部署mysql、kafaka、kafkamanager和mongodb
    在IE6 情况下让PNG图片透明的3种方法
    ecshop商品列表页出现一个空的搜索结果
    ecshop去掉国家省市区,实现手动填写收货地址
    ecshop始终显示全部分类
    ecshop商品列表页增加/显示货号SN
  • 原文地址:https://www.cnblogs.com/sisxxw/p/15185357.html
Copyright © 2020-2023  润新知