视频blob数据未使用xhr发布

时间:2016-05-21 09:39:04

标签: javascript php html

我正在使用rtcmulticonnection.js。我想将视频保存在服务器上。这里有两个文件“index.html”和“save.php”。 import java.awt.Color; import java.awt.FlowLayout; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JApplet; import javax.swing.JButton; public class Square extends JApplet{ int size; Color color; JButton plus, minus, reset, changeColor; public void init(){ color = Color.GREEN; size = 100; plus = new JButton("+"); minus = new JButton("-"); reset = new JButton("reset"); changeColor = new JButton("color"); setLayout(new FlowLayout()); add(plus); add(minus); add(reset); add(changeColor); plus.addActionListener(new ButtonHandler(this)); minus.addActionListener(new ButtonHandler(this)); reset.addActionListener(new ButtonHandler(this)); changeColor.addActionListener(new ButtonHandler(this)); } public void paint(Graphics g){ g.setColor(color); g.fillRect(20, 20, size, size); } class ButtonHandler implements ActionListener{ Square myApplet; ButtonHandler(Square sq){ this.myApplet = sq; } public void actionPerformed(ActionEvent e){ if(e.getSource()==myApplet.plus) myApplet.size+=10; if(e.getSource()==myApplet.minus) myApplet.size-=10; if(e.getSource()==myApplet.reset) myApplet.size=100; if(e.getSource()==myApplet.changeColor){ if(myApplet.color==Color.GREEN) myApplet.color=Color.RED; else myApplet.color=Color.GREEN; } myApplet.repaint(); } } } 不会发布数据 这里是源文件链接 “https://github.com/muaz-khan/RTCMultiConnection/blob/master/v2.2.2/demos/audio-video-screen-sharing-recording.html

的index.html

request.open("POST", url);

save.php

document.getElementById('recordAudioVideo').onclick = function() {
    var localVideoStream = rmc.streams.selectFirst({
        video: true,
        local: true
    });
    if (!localVideoStream) return;
    var recordingSession = {
        audio: true,
        video: true
    };
    var button = this;
    if (button.innerHTML == 'Record Audio/Video') {
        button.innerHTML = 'Stop Recording Audio/Video';
        // http://www.rtcmulticonnection.org/docs/startRecording/
        localVideoStream.startRecording(recordingSession);
    } else if (button.innerHTML == 'Stop Recording Audio/Video') {
        // http://www.rtcmulticonnection.org/docs/stopRecording/
        localVideoStream.stopRecording(function(blob) {
            //alert('Audio blob size in bytes: ' + blob.audio.size);
            //alert('Video blob size in bytes: ' + blob.video.size);
            var fileType = 'video'; // or "audio"
var fileName = 'ABCDEF.webm';  // or "wav"

var formData = new FormData();
formData.append(fileType + '-filename', fileName);
formData.append(fileType + '-blob', blob);
console.log(formData);
xhr('save.php', formData, function (fName) {
    window.open(location.href + fName);
});

function xhr(url, data, callback) {
    var request = new XMLHttpRequest();
    request.onreadystatechange = function () {
        if (request.readyState == 4 && request.status == 200) {
            callback(location.href + request.responseText);
        }
    };
    request.open("POST", url);
    request.send(data);
}
            button.innerHTML = 'Record Audio/Video';
        }, recordingSession);
    }

问题出在

<?php
// Muaz Khan     - www.MuazKhan.com 
// MIT License   - https://www.webrtc-experiment.com/licence/
// Documentation - https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRTC
foreach(array('video', 'audio') as $type) {
    if (isset($_FILES["${type}-blob"])) {

        echo 'uploads/';

        $fileName = $_POST["${type}-filename"];
        $uploadDirectory = './'.$fileName;

        if (!move_uploaded_file($_FILES["${type}-blob"]["tmp_name"], $uploadDirectory)) {
            echo(" problem moving uploaded file");
        }

        echo($fileName);
    }
}
?>

request.open("POST", url); request.send(data); 不会发布数据。它不会调用request.open("POST", url);。因为我已经提醒一些文本以查看是否调用了save.php。所以它没有在client上显示任何警告。我可以解决这个问题。它也没有显示发布错误。

0 个答案:

没有答案