收藏
回答

录音实时流上传怎么实现?

//开始录音的时候

start: function () {

this.setData({

sayimg: '',//图片样式

anmationShow: true,

})

//开始录音

wx.showLoading({

title: '录音中',

mask: true

})

recorderManager.start(options);

recorderManager.onStart(() => {

console.log('recorder start')

});

//错误回调

recorderManager.onError((res) => {

console.log(res);

})


recorderManager.onFrameRecorded((res) => {

const { frameBuffer } = res

console.log('frameBuffer', frameBuffer)

sendSocketMessage(frameBuffer)

})

let socketOpen = false

const socketMsgQueue = []

wx.connectSocket({

url: 'wss://地址'

})

wx.onSocketOpen(function (res) {

socketOpen = true

})

function sendSocketMessage(msg) {

console.log(msg)

if (socketOpen) {

wx.sendSocketMessage({

data: msg

})

} else {

socketMsgQueue.push(msg)

}

console.log(msg)

}

wx.onSocketError(function(res){

console.log('WebSocket连接打开失败')

})

wx.onSocketMessage(function (res) {

console.log('收到服务器内容' + JSON.stringify(res))

})

},

//停止录音

stop: function () {

wx.hideLoading();

this.setData({

sayimg: '',

anmationShow: false,

})

var that = this;

recorderManager.stop();

recorderManager.onStop((res) => {

that.tempFilePath = res.tempFilePath;

console.log('recorder end')

console.log('停止录音', res.tempFilePath)

const { tempFilePath } = res;

})

},


回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容
问题标签