时间:2019-05-07 来源:小程序工厂
黄***:
麻烦提供可复现机型,以及可复现代码
w***:
我再测试了一下,录制之后用临时路径是可以播放的。但是我通过uploadfile接口,将视频文件上传到腾讯云存储上,超过3秒的文件就不能播放了。
wx.canvasGetImageData方法有bug??
w***:
微信小程序代码
视频上传代码
wx.chooseVideo({
sourceType: ['album', 'camera'],
compressed: true,
maxDuration: 60,
camera: 'back',
success: function (res) {
var tempFile = res;
var vedioName = (new Date()).getTime() + ".mp4";
wx.uploadFile({
url: "/api/v2/uploadVideo", //仅为示例,非真实的接口地址
filePath: tempFile.tempFilePath,
name: vedioName,
success: function (res) {
consol.log("上传成功");
});
});
});
视频播放代码
服务器代码
上传代码
@RequestMapping(value = "/uploadVideo", method = RequestMethod.POST)
@ResponseBody
public void uploadVideo(HttpServletRequest request) throws Exception {
DiskFileItemFactory fileItemFactory = new DiskFileItemFactory();
ServletFileUpload fileUpload = new ServletFileUpload(fileItemFactory);
fileUpload.setHeaderEncoding("UTF-8");
List
Map
String fileName = null;
for (FileItem fileItem : list) {
if(fileItem.isFormField()){
//如果是表单项
String name = fileItem.getFieldName();
String string = fileItem.getString("utf-8");
//表单项的集合
map.put(name, string);
}else{
//上传项
fileName = fileItem.getName();
InputStream is = fileItem.getInputStream();
// 获得文件要上传的路径(后面的路径可以自定义):
String pathPre = “/opt/tomcat_web/”;
String filePath = pathPre + fileName;
OutputStream os = new FileOutputStream(filePath);
byte[] byts = new byte[1024];
int len = 0;
while ( (len = is.read(byts)) != -1 ) {
os.write(byts, 0, len);
os.flush();
}
is.close();
os.close();
}
}
}
下载代码
@RequestMapping(value = "/downloadFile", method = RequestMethod.GET)
public void downloadFile(@RequestParam String fileName, HttpServletRequest request, HttpServletResponse response) throws Exception{
// 下载文件,从服务器端读取文件,将文件内容写回客户端
String pathPre = “/opt/tomcat_web/”;
String filePath = pathPre + fileName;
InputStream in = new BufferedInputStream(new FileInputStream(filePath));
String header = "attachment; filename=\"" + fileName + "\"";
response.setHeader("Content-Disposition", header);
response.setContentType("application/octet-stream; charset=utf-8");
OutputStream out = response.getOutputStream();
int temp;
while ((temp = in.read()) != -1) {
out.write(temp);
}
out.close();
in.close();
}
H***:
你好,我们也遇到了您描述的问题了。我试了一下你们微信小程序,现在已经可以播放超过3秒的视频了,请问您是怎么解决的?
w***:
兄弟,代码改为支持分片下载就好了
微信小程序tabar list第一个必须要是index,微信小程序教程