左开阳
左开阳
  • 发布:2018-12-05 11:33
  • 更新:2020-06-19 17:23
  • 阅读:2142

mui使用plus.uploader.createUpload上传视频报错:Uncaught SyntaxError: Unexpected token h in JSON at position 0

分类:HBuilder

使用plus.uploader.createUpload上传视频报错:Uncaught SyntaxError: Unexpected token h in JSON at position 0 at home/clock-the-editor.html:1

上传几秒钟的视频可以正常上传,但是上传10秒以上的视频就会报Uncaught SyntaxError: Unexpected token h in JSON at position 0 at home/clock-the-editor.html:1,

  
//视频录制  
function VideoRecording(){  
	var cmr = plus.camera.getCamera();  
	var res = cmr.supportedVideoResolutions[0];  
	var fmt = cmr.supportedVideoFormats[0];  
	cmr.startVideoCapture( function( path ){  
			videotag=1;  
			plus.nativeUI.showWaiting("上传中...");  
			createUpload(path); //上传视频  
		},  
		function( error ) {  
			//console.log( "视频录制出错failed: "   error.message );  
		},  
		{resolution:res,format:fmt}  
	);  
}  
//从相册中选择视频  
function videoFromCamera(){  
	plus.gallery.pick( function(path){  
    		videotag=2;  
    		plus.nativeUI.showWaiting("上传中...");  
    		createUpload(path);  //上传视频  
    }, function ( e ) {  
    		console.log( "取消选择视频" );  
    }, {filter:"video"} );  
}  
  
// 创建上传任务(图片裁剪)  
function createUpload(path) { //path是  
	if(isChinese(path) == true){  
		plus.nativeUI.alert("资源路径含有特殊字符");  
		plus.nativeUI.closeWaiting();  
		return;  
	}  
	var task = plus.uploader.createUpload(urlHead   "uploadProof", {  
			method: "POST",  
			blocksize: 204800,  
			priority: 100  
		},  
		function(data, status) {  
			data = JSON.parse(data.responseText);  
			// 上传完成  
			plus.nativeUI.closeWaiting();  
			if(status == 200) {  
				if(data['code'] !== 0) {  
					plus.nativeUI.alert(data['msg']);  
					return;  
				}  
				var dic=data["data"];  
				  
				if(pictag == 2||pictag == 1){  
					//数组  
					showPicPath=data["data"]["showPicPath"];  
					createImg(showPicPath);  
					pictag=0;  
				}  
				  
				if(voicetag == 1){  
					//音频  
					voiceduration=dic["duration"];  
					voicePath=dic["showPicPath"];  
					document.getElementById("upvoice").style.display="none";  
					createVoice(voicePath);  
					voicetag=0;  
				}  
				  
				if(videotag == 1||videotag == 2){  
					//视频封面  
					coverUrl=dic["coverUrl"];  
					showCoverUrl=dic["showCoverUrl"];//视频播放地址  
					//视频长度  
					videoduration=dic["duration"];  
					//视频地址  
					videoPath=dic["showPicPath"];  
					document.getElementById("upvideo").style.display="none";  
					createVideo();  
					videotag=0;  
				}  
				var that = this;	  
			} else {  
				plus.nativeUI.closeWaiting();  
				plus.nativeUI.alert("Upload failed: "   status);  
			}  
		}  
	);  
	task.addFile(path, {  
		key: "fileList"  
	});  
	task.start();  
}  
  

2018-12-05 11:33 负责人:无 分享
已邀请:
1***@qq.com

1***@qq.com - 小小前端开发者

请问楼主解决了吗

该问题目前已经被锁定, 无法添加新回复