视频JS特定时间间隔ajax发布webm文件未打开,firefox中不支持MIME类型的错误

时间:2018-10-04 07:47:44

标签: video.js

VIDEOJS:将video.js 7.2.0与videojs-record 2.4.1和recordrtc 5.4.8配合使用,特定的时间间隔为2秒。

第一次Ajax触发时,上传的视频格式是正确的,并且也在chrome和firefox中打开。

但是第二次上传的视频也无法在chrome和firefox中打开。 在firefox中,它显示不受支持的文件格式。

感谢您的帮助。对不起,我的英语不好。

下面的我的JavaScript代码:

var player = videojs("myVideo", {
controls: true,
width: 320,
height: 240,
fluid: false,
plugins: {
    record: {
        audio: true,
        video: true,
        maxLength: 30,
        debug: true,
        //audioEngine: 'recordrtc',
        videoMimeType: 'video/webm; codecs=vp8',
        // fire the timestamp event every 2 seconds
        timeSlice: 2000,}
}
}, function(){
    // print version information at startup
    var msg = 'Using video.js ' + videojs.VERSION + ' with videojs-record ' + videojs.getPluginVersion('record') + ' and recordrtc ' + RecordRTC.version;
    videojs.log(msg);
});

   var segmentNumber = 0;
   player.on('timestamp', function() {

if (player.recordedData && player.recordedData.length > 0) {
    //console.log(player.recordedData);
    var binaryData = player.recordedData[player.recordedData.length - 1];
    //console.log(binaryData);


    segmentNumber++;
    //console.log("The counter value is: "+segmentNumber);  

    var formData = new FormData();
    formData.append('SegmentNumber', segmentNumber);
    formData.append('Data', binaryData);
    formData.append('file', binaryData.name);
    $.ajax({
        url: 'upload.php',
        method: 'POST',
        data: formData,
        cache: false,
        processData: false,
        contentType: false,
        success: function (res) {
            console.log("segment: " + segmentNumber);
            $("#result-new-video").append("<p>" + res + "</p>")
            //alert("segment: " + segmentNumber);
            var binaryData;
            }
        });
    }
});

在上传文件的PHP中,代码如下(upload.php):

<?php
$fileName = $_POST["file"];
$uploadDirectory = 'uploads/' . $fileName;
if (!move_uploaded_file($_FILES["Data"]["tmp_name"], $uploadDirectory)) { 
   echo("tmp_name problem moving uploaded file");
 }
 ?>

0 个答案:

没有答案