我正在尝试保存通过Video.js录制的视频以保存在服务器上,下面是我的代码
<script>
var player = videojs("myVideo",
{
controls: true,
width: 320,
height: 240,
plugins: {
record: {
audio: true,
video: true,
maxLength: 41,
debug: true
}
}
});
player.on('startRecord', function()
{
console.log('started recording!');
});
player.on('finishRecord', function()
{
console.log('finished recording: ', player.recordedData);
});
function uploadFunction()
{
**//WRITE CODE TO SAVE player.recordedData.video in specified folder//**
}
</script>
实施实施:https://www.propertybihar.com/neo/videxp1/index.html
我正在经历一个先前提出的问题,dint为我工作 How can javascript upload a blob?
答案 0 :(得分:1)
如果向下滚动到"Upload" section on the README,您会看到此代码剪切掉了您想要的内容,但流式应用程序除外:
var segmentNumber = 0;
player.on('timestamp', function() {
if (player.recordedData && player.recordedData.length > 0) {
var binaryData = player.recordedData[player.recordedData.length - 1];
segmentNumber++;
var formData = new FormData();
formData.append('SegmentNumber', segmentNumber);
formData.append('Data', binaryData);
$.ajax({
url: '/api/Test',
method: 'POST',
data: formData,
cache: false,
processData: false,
contentType: false,
success: function (res) {
console.log("segment: " + segmentNumber);
}
});
}
});
这是为了连续上传数据而配置的,但我发现我必须为自己的设置做一些更改:
player.recordedData
不是数组而只是一个blob。< / LI>
因此,我的上传代码如下所示:
if (player.recordedData) {
var binaryData = player.recordedData.video;
// ... Rest of that FormData and $.ajax snippet from previous snippet
}
如果我不这样做,那么检查要上传的现有数据总是失败。我还手动触发此代码,而不是将其附加到player
对象的&#34; timestamp&#34; 事件。当然,您需要具有接受此上传的服务器端代码。