|
<
uniapp完成灌音上传功用
html部门
我是写了个灌音的图片
面击以后弹出一个弹出层(仿了下qq的款式)
款式怎样写我便没有赘述了各人城市
js部门
那是重面敲乌板!!!
创立真例
为了齐局皆好获得到,能够随时开端灌音,随时避免灌音,我把他扔进齐局了
- const recorderManager = uni.getRecorderManager();//创立一个灌音真例
- const innerAudioContext = uni.createInnerAudioContext();//用去播放的真例
- // 为了避免苹果脚机静音没法播放
- uni.setInnerAudioOption({
- obeyMuteSwitch: false
- })
- innerAudioContext.autoplay = true;
- export default {
复造代码 开端灌音
- this.timecount = '00:00:00';//初初化灌音工夫
- this.hour = 0;
- this.minute = 0;
- this.second = 0;
- this.getTimeIntervalplus();//启拆的一个计时器,挪用开端计时
- const options = {//参数
- duration: 600000,
- sampleRate: 44100,
- numberOfChannels: 1,
- encodeBitRate: 192000,
- format: 'mp3',
- frameSize: 50
- }
- recorderManager.start(options);
复造代码
完毕灌音
需求限定最短时少的能够做下判定,我那边出写
- recorderManager.stop();//完毕灌音
- clearInterval(this.timer);//完毕计时
复造代码 播放灌音
- innerAudioContext.src = this.voicePath;//播放的地点(上里录的当地地点)
- innerAudioContext.play();//播放
复造代码 停息播放
- innerAudioContext.pause();//停息播放
- clearInterval(this.timer);//肃清按时器
复造代码 提交灌音到后端
- //完毕灌音提交灌音
- submitrecord: function() {
- this.count += 1;//那是界说了一个齐局的变量去避免屡次提交
- if (this.count == 1){
- console.log(this.count);
- var https = getApp().globalData.https;
- if (this.recordednum == 2) {
- this.recordednum = 3;
- recorderManager.stop();
- clearInterval(this.timer);
- }
- if (this.voicePath != '') {
- console.log(this.voicePath);
- uni.uploadFile({
- url: https + 'Uploads/uploadVoiceVideo',
- filePath: this.voicePath,
- name: 'file',
- success: (res) => {
- this.count = 0;
- //初初化
- this.initialize()//我启拆了一个初初化按时器的函数
- this.timer = this.timecount;
- this.show_recording = false;
- var data = JSON.parse(res.data);
- if (this.current == 0) {//判定是哪一个列内里录的音插归去
- this.firsvideo.push(data.address);
- } else if (this.current == 1) {
- this.secovideo.push(data.address);
- console.log(this.secovideo);
- } else if (this.current == 2) {
- this.thrivideo.push(data.address);
- }
- uni.showToast({
- title: '提交胜利!',
- icon: 'none',
- duration: 1200
- })
- },
- fail: (err) => {
- uni.hideLoading();
- uni.showToast({
- tilte: '上传失利~',
- icon: 'none',
- duration: 1200
- })
- return
- }
- });
- } else {
- console.log("灌音失利")
- uni.showToast({
- tilte: '灌音失利',
- icon: 'none',
- duration: 1200
- })
- uni.hideLoading();
- this.show_recording = false;
- this.checkPermission()
- this.rerecord()
- }
- } else {
- uni.showToast({
- title: '请勿反复提交',
- icon: 'none',
- duration: 2000
- })
- this.count=0;
- }
- },
复造代码 从头录造
- //从头录造
- rerecord: function() {
- //初初化按时器
- this.initialize()
- this.getTimeIntervalplus();//开端计时
- const options = {
- duration: 600000,
- sampleRate: 44100,
- numberOfChannels: 1,
- encodeBitRate: 192000,
- format: 'mp3',
- frameSize: 50
- }
- recorderManager.start(options);//开端灌音
- },
复造代码 onLoad部门
- onLoad(option) {
- var appointment_message = option.appointment_message;
- appointment_message = JSON.parse(appointment_message);
- this.appointment_message = appointment_message;
- let that = this;
- recorderManager.onStop(function(res) {
- console.log('recorder stop' + JSON.stringify(res));
- that.voiceDuration = res.duration;
- that.voicePath = res.tempFilePath;
- console.log(res);
- });
- },
复造代码 计时器
- // 计时器删
- getTimeIntervalplus() {
- clearInterval(this.timer);
- this.timer = setInterval(() => {
- this.second += 1;
- if (this.second >= 60) {
- this.minute += 1;
- this.second = 0;
- }
- if (this.minute >= 10) {
- this.recordednum = 3;
- recorderManager.stop();
- clearInterval(this.timer);
- }
- this.second2 = this.second;
- this.minute2 = this.minute;
- this.timecount = this.showNum(this.hour) + ":" + this.showNum(this.minute) + ":" + this
- .showNum(this.second);
- - console.log("this.timecount", this.timecount)
- }, 1000);
- },
复造代码 数据部门
- data() {
- return {
- action: 'https://yl.letter-song.top/api/Uploads/uploadPicture', //上传图片地点
- textareavalue: '', //笔墨形貌值
- fileList2: [], //返回图片途径2
- fileList3: [], //返回图片途径3
- fileList: [], //返回图片途径1
- firsvideo: [], //灌音途径1
- secovideo: [], //灌音途径2
- thrivideo: [], //灌音途径3
- appointment_message: '', //预定疑息上个页里传参过去的
- list: [{ //标签表
- name: '过往病症'
- }, {
- name: '远期病症'
- }, {
- name: '本次病症',
- }],
- current: 0, //选中项
- sty: { //滑块款式
- height: '4px',
- borderRadius: '2rpx',
- borderTopLeftRadius: '10px',
- backgroundColor: '#3ECEB5'
- },
- activeItem: { //选中项款式
- color: '#333333',
- fontWeight: '600',
- fontSize: '36rpx',
- },
- show_recording: false, //调起灌音弹窗
- recordednum: 1, //1:初初形态2.灌音形态3完毕
- voicePath: '', //本次音频灌音途径
- voiceDuration: '',
- timecount: '00:00:00',
- timecount2: "",
- hour: 0,
- minute: 0,
- second: 0,
- hour2: 0,
- minute2: 0,
- second2: 0,
- isZant: false,
- timer: '',
- yuming: '那是域名',
- permiss: 0, //0为开启灌音权限1已开启灌音权限,
- count: 0
- }
- },
复造代码 免责声明:假如进犯了您的权益,请联络站少,我们会实时删除侵权内乱容,感谢协作! |
1、本网站属于个人的非赢利性网站,转载的文章遵循原作者的版权声明,如果原文没有版权声明,按照目前互联网开放的原则,我们将在不通知作者的情况下,转载文章;如果原文明确注明“禁止转载”,我们一定不会转载。如果我们转载的文章不符合作者的版权声明或者作者不想让我们转载您的文章的话,请您发送邮箱:Cdnjson@163.com提供相关证明,我们将积极配合您!
2、本网站转载文章仅为传播更多信息之目的,凡在本网站出现的信息,均仅供参考。本网站将尽力确保所提供信息的准确性及可靠性,但不保证信息的正确性和完整性,且不对因信息的不正确或遗漏导致的任何损失或损害承担责任。
3、任何透过本网站网页而链接及得到的资讯、产品及服务,本网站概不负责,亦不负任何法律责任。
4、本网站所刊发、转载的文章,其版权均归原作者所有,如其他媒体、网站或个人从本网下载使用,请在转载有关文章时务必尊重该文章的著作权,保留本网注明的“稿件来源”,并自负版权等法律责任。
|