trying to fix video record, save before bigger changes
This commit is contained in:
parent
0a180eac6f
commit
624ac2323b
@ -229,7 +229,7 @@ def teststartpage():
|
|||||||
def jsonform():
|
def jsonform():
|
||||||
#user is not yet registered and should not be here
|
#user is not yet registered and should not be here
|
||||||
if not "slaeform_user_id" in session:
|
if not "slaeform_user_id" in session:
|
||||||
return redirect(url_for(teststartpage)) #TODO replace this later with actual startpage
|
return redirect("/teststart") #TODO replace this later with actual startpage
|
||||||
|
|
||||||
|
|
||||||
current_block = config[session["current_block_name"]]
|
current_block = config[session["current_block_name"]]
|
||||||
@ -316,6 +316,12 @@ def sendpage_json():
|
|||||||
print("Error occurred: {e}".format(e=str(e)))
|
print("Error occurred: {e}".format(e=str(e)))
|
||||||
return "There was a problem while adding the response to the Database"
|
return "There was a problem while adding the response to the Database"
|
||||||
|
|
||||||
|
# handle possible Video that was send
|
||||||
|
video = request.files['recordedVideo']
|
||||||
|
#video_name = './uploads/' + str(date) + "_" + str(session_user_id)
|
||||||
|
video.save(f'./uploads/{video.filename}')
|
||||||
|
|
||||||
|
|
||||||
# Now move to the next stimulus or block
|
# Now move to the next stimulus or block
|
||||||
update_session()
|
update_session()
|
||||||
|
|
||||||
|
@ -48,7 +48,12 @@
|
|||||||
"name": "text_feedback",
|
"name": "text_feedback",
|
||||||
"required": "false",
|
"required": "false",
|
||||||
"size": "250"
|
"size": "250"
|
||||||
}
|
},
|
||||||
|
"question3":{
|
||||||
|
"type": "videoinput",
|
||||||
|
"name": "video_feedback",
|
||||||
|
"required": "false"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"database_table" :{
|
"database_table" :{
|
||||||
"table_name": "default_block3_test",
|
"table_name": "default_block3_test",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
body {
|
body {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100vh;
|
height: 100%;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
@ -52,6 +52,13 @@ body {
|
|||||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
video {
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: 100%;
|
||||||
|
width: auto;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
.videocontrols {
|
.videocontrols {
|
||||||
width: 100px; /* Set a specific width for the buttons */
|
width: 100px; /* Set a specific width for the buttons */
|
||||||
height: 70px; /* Set a specific height for the buttons */
|
height: 70px; /* Set a specific height for the buttons */
|
||||||
|
@ -0,0 +1,132 @@
|
|||||||
|
|
||||||
|
const buttonCamera = document.getElementById('buttonCamera');
|
||||||
|
const buttonRecord = document.getElementById('buttonRecord');
|
||||||
|
const buttonDelete = document.getElementById('buttonDelete');
|
||||||
|
const videoDisplay = document.getElementById('videoDisplay');
|
||||||
|
const buttonCameraIcon = document.getElementById('buttonCameraIcon');
|
||||||
|
const buttonRecordIcon = document.getElementById('buttonRecordIcon');
|
||||||
|
//const buttonDeleteIcon = document.getElementById('buttonDeleteIcon');
|
||||||
|
var mediaRecorder = null;
|
||||||
|
var stream = null;
|
||||||
|
let recordedVideoBlob = null;
|
||||||
|
let isRecording = false;
|
||||||
|
let videoAccess = false;
|
||||||
|
|
||||||
|
//handle form submission:
|
||||||
|
document.getElementById("question_form").addEventListener("submit", function (event) {
|
||||||
|
event.preventDefault(); // Prevent the default form submission
|
||||||
|
|
||||||
|
// Create a FormData object
|
||||||
|
const formData = new FormData(event.target);
|
||||||
|
|
||||||
|
// Append the recorded video Blob to the FormData object
|
||||||
|
formData.append("recordedVideo", recordedVideoBlob, "recordedVideo.webm");
|
||||||
|
|
||||||
|
// Use fetch to send the form data and video to the backend
|
||||||
|
console.log("try to send the form and video");
|
||||||
|
fetch("/send_json", {
|
||||||
|
method: "POST",
|
||||||
|
body: formData
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
console.log('Success:', data);
|
||||||
|
// Handle success response
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error:', error);
|
||||||
|
// Handle error response
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
async function cameraButton() {
|
||||||
|
if (!videoAccess) { //test what happens if user doesnt give the permission
|
||||||
|
console.log("cameraButton case videoAccess = false");
|
||||||
|
// maybe a try catch block?
|
||||||
|
try {
|
||||||
|
stream = await navigator.mediaDevices.getUserMedia({
|
||||||
|
video: true,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
//TODO when this occurs the user should get a hint to reload the page or to allow it next to the url
|
||||||
|
newerror = error
|
||||||
|
console.log("Error: ", error);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
console.log("stream is active");
|
||||||
|
videoAccess = true
|
||||||
|
|
||||||
|
videoDisplay.srcObject = stream
|
||||||
|
|
||||||
|
buttonCameraIcon.src = ICON_PATHS.cameraofficon; //todo, not sure if this works
|
||||||
|
buttonCameraIcon.alt = "Camera-off Icon";
|
||||||
|
buttonRecord.style.display = 'inline-block';
|
||||||
|
buttonDelete.style.display = 'inline-block';
|
||||||
|
videoDisplay.style.display = 'inline-block';
|
||||||
|
|
||||||
|
mediaRecorder = new MediaRecorder(stream, {
|
||||||
|
mimeType: "video/webm", //could use other video format: https://www.iana.org/assignments/media-types/media-types.xhtml#video
|
||||||
|
// I probably want to change the bitrate: https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/MediaRecorder
|
||||||
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
console.log("cameraButton case videoAccess = true");
|
||||||
|
|
||||||
|
stream = null;
|
||||||
|
videoAccess = false
|
||||||
|
|
||||||
|
buttonCameraIcon.src = ICON_PATHS.cameraicon; //todo, not sure if this works
|
||||||
|
buttonCameraIcon.alt = "Camera Icon";
|
||||||
|
buttonRecord.style.display = 'none';
|
||||||
|
buttonDelete.style.display = 'none';
|
||||||
|
videoDisplay.style.display = 'none';
|
||||||
|
}
|
||||||
|
console.log("camera button function ends");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function recordButton() {
|
||||||
|
console.log("recordButton pressed");
|
||||||
|
if (!isRecording) {
|
||||||
|
console.log("recordButton pressed case isRecording = false");
|
||||||
|
deleteButton();
|
||||||
|
buttonDelete.setAttribute("disabled", "");
|
||||||
|
buttonDeleteIcon.classList.add("buttondisable");
|
||||||
|
videoDisplay.srcObject = stream;
|
||||||
|
videoDisplay.src = null;
|
||||||
|
mediaRecorder.start();
|
||||||
|
|
||||||
|
buttonRecordIcon.src = ICON_PATHS.stopicon;
|
||||||
|
buttonRecordIcon.alt = 'record icon';
|
||||||
|
isRecording = true;
|
||||||
|
console.log('Recording started');
|
||||||
|
|
||||||
|
} else {
|
||||||
|
console.log("recordButton pressed case isRecording = true");
|
||||||
|
mediaRecorder.stop();
|
||||||
|
|
||||||
|
console.log("recording stops, now change source");
|
||||||
|
videoDisplay.srcObject = null;
|
||||||
|
videoDisplay.src = URL.createObjectURL(mediaRecorder.data);
|
||||||
|
recordedVideoBlob = mediaRecorder.data;
|
||||||
|
|
||||||
|
buttonRecordIcon.src = ICON_PATHS.recordicon;
|
||||||
|
buttonRecordIcon.alt = 'Stop Icon';
|
||||||
|
isRecording = false;
|
||||||
|
console.log('Recording stopped');
|
||||||
|
|
||||||
|
buttonDelete.removeAttribute("disabled");
|
||||||
|
buttonDeleteIcon.classList.remove("buttondisable");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function deleteButton() {
|
||||||
|
//todo delete data
|
||||||
|
videoDisplay.srcObject = stream;
|
||||||
|
videoDisplay.src = null;
|
||||||
|
buttonDelete.setAttribute("disabled", "");
|
||||||
|
buttonDeleteIcon.classList.add("buttondisable");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
<div class="container">
|
||||||
<h2>All available pages</h2>
|
<h2>All available pages</h2>
|
||||||
<ul>
|
<ul>
|
||||||
<p>--------------------------------------------</p>
|
<p>--------------------------------------------</p>
|
||||||
@ -24,6 +25,7 @@
|
|||||||
<p>--------------------------------------------</p>
|
<p>--------------------------------------------</p>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
@ -10,6 +10,7 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
<div class="container">
|
||||||
<h2>Gib Feedback als Video</h2>
|
<h2>Gib Feedback als Video</h2>
|
||||||
<div class="centertext">
|
<div class="centertext">
|
||||||
|
|
||||||
@ -34,7 +35,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="spacer" aria-hidden="true" style="height:15px"></div>
|
<div class="spacer" aria-hidden="true" style="height:15px"></div>
|
||||||
<div class="centertext">
|
<div class="centertext">
|
||||||
<video autoplay muted playsinline width="1280" height="720" id="videoDisplay"></video>
|
<video autoplay muted playsinline id="videoDisplay"></video>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
const buttonCamera = document.getElementById('buttonCamera');
|
const buttonCamera = document.getElementById('buttonCamera');
|
||||||
@ -135,7 +136,7 @@
|
|||||||
buttonDeleteIcon.classList.add("buttondisable");
|
buttonDeleteIcon.classList.add("buttondisable");
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
@ -8,10 +8,10 @@
|
|||||||
<h3>{{title}}</h3>
|
<h3>{{title}}</h3>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="video-container">
|
<div class="video-container">
|
||||||
<iframe width={{width}} height={{height}} class="center" src="{{ video_url }}" title="YouTube video player"
|
<iframe width={{width}} height={{height}} class="center" src="{{ video_url }}" title="YouTube video player"
|
||||||
frameborder="0"
|
frameborder="0"
|
||||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
|
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
|
||||||
allowfullscreen></iframe>
|
allowfullscreen></iframe>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
@ -32,9 +32,16 @@ required
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='styles.css')}}"" /> <!-- styles.css {{ url_for('static', filename='styles.css')}}-->
|
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='styles.css')}}" />
|
||||||
|
<!-- styles.css {{ url_for('static', filename='styles.css')}}-->
|
||||||
<title>Testform</title>
|
<title>Testform</title>
|
||||||
<link rel=" shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
|
<link rel=" shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
|
||||||
|
<script>const ICON_PATHS = {
|
||||||
|
cameraofficon: "{{ url_for('static', filename='icons/camera-off-icon.png') }}",
|
||||||
|
cameraicon: "{{ url_for('static', filename='icons/camera-icon.png') }}",
|
||||||
|
stopicon: "{{ url_for('static', filename='icons/stop-icon.png') }}",
|
||||||
|
recordicon: "{{ url_for('static', filename='icons/record-icon.png') }}"
|
||||||
|
};</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
@ -51,7 +58,7 @@ required
|
|||||||
|
|
||||||
|
|
||||||
<h2>Questions</h2>
|
<h2>Questions</h2>
|
||||||
<form action="http://localhost:5000/send_json" method="post">
|
<form id="question_form" action="http://localhost:5000/send_json" method="post">
|
||||||
{% for question in questions %}
|
{% for question in questions %}
|
||||||
{% if (questions[question]["type"] == "likert") %}
|
{% if (questions[question]["type"] == "likert") %}
|
||||||
<div class="likercontainer">
|
<div class="likercontainer">
|
||||||
@ -72,12 +79,47 @@ required
|
|||||||
cols="60" maxlength="{{ questions[question]['size'] }}"
|
cols="60" maxlength="{{ questions[question]['size'] }}"
|
||||||
{{required(questions[question])}}></textarea>
|
{{required(questions[question])}}></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
{% elif (questions[question]["type"] == "videoinput") %}
|
||||||
|
<h2>Gib Feedback als Video</h2>
|
||||||
|
<div class="centertext">
|
||||||
|
|
||||||
|
<button type="button" class="videocontrols" id="buttonCamera" onclick="cameraButton()">
|
||||||
|
<img id="buttonCameraIcon" src="{{ url_for('static', filename='icons/camera-icon.png')}}"
|
||||||
|
alt="Camera Icon">
|
||||||
|
</button>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="spacer" aria-hidden="true" style="height:30px"></div>
|
||||||
|
<div class="centertext">
|
||||||
|
|
||||||
|
<button type="button" class="videocontrols" id="buttonRecord" style="display:none"
|
||||||
|
onclick="recordButton()">
|
||||||
|
<img id="buttonRecordIcon" src="{{ url_for('static', filename='icons/record-icon.png')}}"
|
||||||
|
alt="Camera Icon">
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button type="button" class="videocontrols" id="buttonDelete" style="display:none" disabled
|
||||||
|
onclick="deleteButton()">
|
||||||
|
<img id="buttonDeleteIcon" src="{{ url_for('static', filename='icons/trash-icon.png')}}"
|
||||||
|
alt="Delete Icon" class="buttondisable">
|
||||||
|
</button>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="spacer" aria-hidden="true" style="height:15px"></div>
|
||||||
|
<div class="centertext">
|
||||||
|
<video autoplay muted playsinline id="videoDisplay"></video>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="{{ url_for('static', filename='videoscript.js')}}">
|
||||||
|
|
||||||
|
</script>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>Error: Block {{config["question 1"]["blocks"][block]["type"]}} could not be loaded!</p>
|
<p>Error: Block {{config["question 1"]["blocks"][block]["type"]}} could not be loaded!</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<div class="button-container">
|
<div class="button-container">
|
||||||
<p><input id="submitbutton" type="submit" value="submit" ; /></p>
|
<p><input id="submitbutton" type="submit" value="submit" ; /></p>
|
||||||
|
<!-- TODO maybe I want to use this instead: <button id="submitbutton" type="submit">Submit</button> -->
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -9,10 +9,12 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
<div class="container">
|
||||||
<p>This is just a test page for the single page option of the json configuration, but without something to submit</p>
|
<p>This is just a test page for the single page option of the json configuration, but without something to submit</p>
|
||||||
<form action="http://localhost:5000/send_json" method="post">
|
<form action="http://localhost:5000/send_json" method="post">
|
||||||
<input type="hidden" name="submittedString" value="Hello, backend!">
|
<input type="hidden" name="submittedString" value="Hello, backend!">
|
||||||
<p><input id="submitbutton" type = "submit" value = "submit";/></p>
|
<p><input id="submitbutton" type = "submit" value = "submit";/></p>
|
||||||
</form>
|
</form>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -9,6 +9,7 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
<div class="container">
|
||||||
<p>This is just a test page for the single page option of the json configuration</p>
|
<p>This is just a test page for the single page option of the json configuration</p>
|
||||||
<form action="http://localhost:5000/send_json" method="post">
|
<form action="http://localhost:5000/send_json" method="post">
|
||||||
<input
|
<input
|
||||||
@ -19,5 +20,6 @@
|
|||||||
<label for="accepted">Akzeptieren sie die Datenschutzerklaerung</label>
|
<label for="accepted">Akzeptieren sie die Datenschutzerklaerung</label>
|
||||||
<p><input id="submitbutton" type = "submit" value = "submit";/></p>
|
<p><input id="submitbutton" type = "submit" value = "submit";/></p>
|
||||||
</form>
|
</form>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue
Block a user