4***@qq.com
4***@qq.com
  • 发布:2019-11-04 10:39
  • 更新:2019-11-04 16:28
  • 阅读:2332

mui 录制视频、语音后,上传到后台,视频、音频无法播放

分类:MUI

mui 拍照、上传照片保存到后台成功,录音、短视频拍摄完成后,同样的上传方法 到后台,音频无法播放,MP4电脑端打开智能播放声音,无图像。不知道问题出在哪?

//1.录音  
            function luYin(){  
                recorder=plus.audio.getRecorder();  //录音对象  
                if(recorder == null){  
                    mui.alert("调用麦克风失败!", "提示信息", "关闭", null);  
                    return ;  
                }  
                voiceTime =(new Date()).valueOf();   
                var voicePath="_doc/audio/";  
                recorder.record({  
                        filename:voicePath,  
                        samplerate:16000//,  
                        // format:"wav" //iOS平台支持"wav"、"aac"、"amr"格式,默认为"wav"*//  
                    },function(path){  
                        //录音成功回调  
                        mui.toast("正在提交.."+path);  
                        uploadFileToFwq(path);  
                    },function(e){  
                        //录音错误回调  
                        mui.toast("录音失败!" + JSON.stringify(e));  
                        return ;  
                })  
            }  
//4.录像  
            function videoCapture(){  
                var camera = plus.camera.getCamera();  
                camera.startVideoCapture(function(e) {  
                    //t 摄像操作保存的文件路径  
                    mui.toast('录制完成:'+e)  
                    console.log(e)  
                   plus.io.resolveLocalFileSystemURL(e, function(entry) {  
                        var url = entry.toLocalURL();  
                        uploadFileToFwq(url);  
                    });  
                }, function(e) {  
                    console.log("取消录制");  
                }, {  
                    filename: '_doc/video/',//录像文件保存的路径  
                    format: camera.supportedVideoFormats[0],//摄像的文r件格式  
                    index: 1, //摄像默认使用的摄像头  
                    videoMaximumDuration:10,//视频长度  
                    resolution: camera.supportedVideoResolutions[0]//摄像使用的分辨率  

                })  
            }  
//上传附件到服务器  
            function uploadFileToFwq(fileSrc) {  
                console.log("fileSrc="+fileSrc)  
                var task = plus.uploader.createUpload(  
                    baseurl + "saveHfAndFile.wds",   
                    {  
                        processData:false,  
                        contentType:"multipart/form-data",  
                        method: "POST",//,  
                        //blocksize: 204800,  
                        priority: 100  
//                      blocksize: 1024000//上传任务每次上传的文件块大小,单位为Byte(字节),默认102400  
                    },  
                    function(t, status) {  
                        // 上传完成  
                        mui.toast(JSON.stringify(t));  
                        console.log(JSON.stringify(t));  
                        var sub_webview = plus.webview.getWebviewById("bjgzap_chat_list.html");  
                        sub_webview.evalJS("searchInfoNew()");//调用子页面方法  
                    }  
                );  
                task.addFile(decodeURI(fileSrc), {  
                    key: "file"  
                });  
                task.start();  
            }  
2019-11-04 10:39 负责人:无 分享
已邀请:
4***@qq.com

4***@qq.com (作者)

手机直接录制的mp4是decoder=h264,mui上传的视频是decoder=hvc1 / 0x31637668

4***@qq.com

4***@qq.com (作者)

手机直接录制的mp4是decoder=h264,mui上传的视频是decoder=hvc1 / 0x31637668

s***@163.com

s***@163.com

努力,加油

4***@qq.com

4***@qq.com (作者)

对mui上传的mp4视频只能播放声音,无图像的视频编码
需要引用jar包:
ws.schil包下的两个包:jave-native-win64-2.4.6.jar jave-core-2.4.6.jar
编码后 MP4,确实可以正常显示图片了

import java.io.File;  
import ws.schild.jave.AudioAttributes;  
import ws.schild.jave.Encoder;  
import ws.schild.jave.EncoderException;  
import ws.schild.jave.EncodingAttributes;  
import ws.schild.jave.MultimediaObject;  
import ws.schild.jave.VideoAttributes;  

public class Mp4Test2 {  

    public static void main(String[] args) {  

        /**  
         * 1.mp4 :  
            ws.schild.jave.MultimediaInfo (format=mov, duration=21600, video=ws.schild.jave.VideoInfo (decoder=h264, size=ws.schild.jave.VideoSize (width=1920, height=1080), bitRate=-1, frameRate=90000.0), audio=ws.schild.jave.AudioInfo (decoder=mpeg4aac, samplingRate=48000, channels=2, bitRate=-1))  
        true  
        2.mp4 :  
            ws.schild.jave.MultimediaInfo (format=mov, duration=1300, video=ws.schild.jave.VideoInfo (decoder=hvc1 / 0x31637668, size=ws.schild.jave.VideoSize (width=3840, height=2160), bitRate=-1, frameRate=90000.0), audio=ws.schild.jave.AudioInfo (decoder=mpeg4aac, samplingRate=48000, channels=2, bitRate=-1))  
        true  
         */  
        File source = new File("d:/temp/2.mp4");  
        File target = new File("d:/temp/2_2.mp4");  
        try {  
            AudioAttributes audio = new AudioAttributes();  
            audio.setCodec("libmp3lame");//音频编码  
            audio.setBitRate(new Integer(800000));  
            audio.setChannels(new Integer(1));  

            VideoAttributes video = new VideoAttributes();  
            video.setCodec("libx264");///设置编码器  
            video.setBitRate(new Integer(3200000));//设置比特率  
            video.setFrameRate(new Integer(15));//数字设置小了,视频会卡顿  

            EncodingAttributes attrs = new EncodingAttributes();  
            attrs.setFormat("mp4");  
            attrs.setAudioAttributes(audio);  
            attrs.setVideoAttributes(video);  

            Encoder encoder = new Encoder();  
            MultimediaObject multimediaObject = new MultimediaObject(source);  

            encoder.encode(multimediaObject, target, attrs);  
        } catch (EncoderException e) {  
            e.printStackTrace();  
        }  
    }  

}  

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