Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vue中import压缩包后,在浏览器中调试,只能调用开始录音,无法调用结束录音 #78

Closed
longerking opened this issue Mar 17, 2020 · 2 comments

Comments

@longerking
Copy link

<script>
	import Recorder from '../../libs/recorder/recorder.mp3.min.js'

	export default {
		data() {
			return {
				rec: null,
				recBlob: null
			}
		},
		onLoad() {
			this.recOpen()
		},
		methods: {
			recOpen() {
				// 打开录音权限
				console.log("查看引入的包")
				console.log(Recorder)
				// 获取麦克风权限
				var that = this
				that.rec  = null
				this.recBlob = null
				var newRec = Recorder({
					type: "mp3",
					sampleRate: 16000,
					bitRate: 16,
					onProcess: function(buffers,powerLevel,bufferDuration,bufferSampleRate,newBufferIdx,asyncEnd){
						console.log("什么时候打开这个回调?在这儿可以绘制图像")
					}
				})
				
				newRec.open(function(){
					that.rec = newRec
					console.log("已经打开录音,可以点击录制开始录音了")
				}),function(msg,isUserNotAllow){
					// 拒绝授权
					console.log("拒绝打开录音权限")
				}
				
			},
			recStart() {
				if(this.rec&&Recorder.IsOpen()){
					this.recBlob = null
					this.rec.start();
					console.log("已经开始录音")
				}else{
					console.log("未打开录音")
				}
			},
			recStop() {
				if(!(this.rec&&Recorder.IsOpen())){
						console.log("未打开录音",1);
						return;
				};
				// console.log(this.rec.stop)
				this.rec.stop( 
					function(blob,duration){
						console.log("查看blob")
						this.rec.close()
						console.log(blob,(window.URL||webkitURL).createObjectURL(blob),"时长:"+duration+"ms");
						
						// this.recBlob=blob;
						console.log("已录制mp3:"+duration+"ms "+blob.size+"字节,可以点击播放、上传了");
					},function(msg){
						console.log("录音失败:"+msg);
				});
			}
		}
	}
</script>
@longerking
Copy link
Author

报错信息

Uncaught ReferenceError: _parseInt2 is not defined

@xiangyuecn
Copy link
Owner

整个源码里面都没有发现_parseInt2这个字符串,我拿/assets/demo-vue里面的代码测试了一下recorder.mp3.min.js也没有出现这个问题,是不是你的开发环境帮你加料了?😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants