Skip to content
Snippets Groups Projects
Commit 3244329e authored by Ron Lucke's avatar Ron Lucke Committed by Till Glöggler
Browse files

fix #572

parent 7c0c1530
No related branches found
No related tags found
No related merge requests found
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
:max="Math.round(durationSeconds)" :max="Math.round(durationSeconds)"
@input="rangeAction" @input="rangeAction"
/> />
<span class="cw-audio-time">{{ currentTime }} / {{ durationTime }}</span> <span class="cw-audio-time">{{ currentTime }} {{ durationTime ? '/ ' + durationTime : '' }}</span>
<button v-if="hasPlaylist" class="cw-audio-button cw-audio-prevbutton" :title="$gettext('Zurück')" @click="prevAudio" /> <button v-if="hasPlaylist" class="cw-audio-button cw-audio-prevbutton" :title="$gettext('Zurück')" @click="prevAudio" />
<button v-if="!playing" class="cw-audio-button cw-audio-playbutton" :title="$gettext('Abspielen')" @click="playAudio" /> <button v-if="!playing" class="cw-audio-button cw-audio-playbutton" :title="$gettext('Abspielen')" @click="playAudio" />
...@@ -189,7 +189,6 @@ export default { ...@@ -189,7 +189,6 @@ export default {
userRecorderEnabled: false, userRecorderEnabled: false,
recorder: null, recorder: null,
chunks: [], chunks: [],
blob: null,
timer: 0, timer: 0,
isRecording: false, isRecording: false,
newRecording: false, newRecording: false,
...@@ -239,7 +238,10 @@ export default { ...@@ -239,7 +238,10 @@ export default {
return this.seconds2time(this.currentSeconds); return this.seconds2time(this.currentSeconds);
}, },
durationTime() { durationTime() {
return this.seconds2time(this.durationSeconds); if (this.durationSeconds > 0) {
return this.seconds2time(this.durationSeconds);
}
return false;
}, },
title() { title() {
return this.block?.attributes?.payload?.title; return this.block?.attributes?.payload?.title;
...@@ -360,10 +362,22 @@ export default { ...@@ -360,10 +362,22 @@ export default {
attributes.payload.folder_id = ''; attributes.payload.folder_id = '';
attributes.payload.recorder_enabled = false; attributes.payload.recorder_enabled = false;
if (this.currentSource === 'studip_file') { if (this.currentSource === 'studip_file') {
if (this.currentFileId === '') {
this.companionWarning({
info: this.$gettext('Bitte wählen Sie eine Datei aus.')
});
return false;
}
attributes.payload.file_id = this.currentFileId; attributes.payload.file_id = this.currentFileId;
} else if (this.currentSource === 'web') { } else if (this.currentSource === 'web') {
attributes.payload.web_url = this.currentWebUrl; attributes.payload.web_url = this.currentWebUrl;
} else if (this.currentSource === 'studip_folder') { } else if (this.currentSource === 'studip_folder') {
if (this.currentFolderId === '') {
this.companionWarning({
info: this.$gettext('Bitte wählen Sie einen Ordner aus.')
});
return false;
}
attributes.payload.folder_id = this.currentFolderId; attributes.payload.folder_id = this.currentFolderId;
attributes.payload.recorder_enabled = this.currentRecorderEnabled; attributes.payload.recorder_enabled = this.currentRecorderEnabled;
} else { } else {
...@@ -382,7 +396,12 @@ export default { ...@@ -382,7 +396,12 @@ export default {
} }
}, },
setDuration() { setDuration() {
this.durationSeconds = this.$refs.audio.duration; let duration = this.$refs.audio.duration
if (!isNaN(duration) && isFinite(duration)) {
this.durationSeconds = duration;
} else {
this.durationSeconds = 0;
}
}, },
playAudio() { playAudio() {
const audio = this.$refs.audio; const audio = this.$refs.audio;
...@@ -415,6 +434,9 @@ export default { ...@@ -415,6 +434,9 @@ export default {
}, },
onTimeUpdateListener() { onTimeUpdateListener() {
this.currentSeconds = this.$refs.audio.currentTime; this.currentSeconds = this.$refs.audio.currentTime;
if (this.durationSeconds === 0) {
this.setDuration();
}
}, },
onEndedListener() { onEndedListener() {
this.stopAudio(); this.stopAudio();
...@@ -471,12 +493,10 @@ export default { ...@@ -471,12 +493,10 @@ export default {
this.stopAudio(); this.stopAudio();
if (this.currentPlaylistItem < this.files.length - 1) { if (this.currentPlaylistItem < this.files.length - 1) {
this.currentPlaylistItem = this.currentPlaylistItem + 1; this.currentPlaylistItem = this.currentPlaylistItem + 1;
} else { this.$nextTick(()=> {
this.currentPlaylistItem = 0; this.playAudio();
});
} }
this.$nextTick(()=> {
this.playAudio();
});
}, },
async loadFile() { async loadFile() {
...@@ -499,28 +519,19 @@ export default { ...@@ -499,28 +519,19 @@ export default {
}, },
enableRecorder() { enableRecorder() {
let view = this; let view = this;
navigator.mediaDevices.getUserMedia({audio: true}).then(_stream => { navigator.mediaDevices.getUserMedia({ audio: true })
let stream = _stream; .then(function(stream) {
view.recorder = new MediaRecorder(stream, {mimeType: 'audio/ogg; codecs=opus'}); view.recorder = new MediaRecorder(stream, {type: 'audio/webm; codecs:vp9' });
view.userRecorderEnabled = true; view.userRecorderEnabled = true;
view.recorder.ondataavailable = e => {
view.recorder.ondataavailable = e => { view.chunks.push(e.data);
view.chunks.push(e.data); };
if(view.recorder.state == 'inactive') { })
this.blob = new Blob(view.chunks, {type: 'audio/ogg; codecs=opus' }); .catch(() => {
} view.companionWarning({
}; info: view.$gettext('Sie müssen ein Mikrofon freigeben, um eine Aufnahme starten zu können.')
view.recorder.start(); });
view.recorder.stop();
view.chunks = [];
view.blob = null;
}).catch(error => {
view.companionWarning({
info: view.$gettext('Sie müssen ein Mikrofon freigeben, um eine Aufnahme starten zu können.')
}); });
console.debug(error);
});
}, },
startRecording() { startRecording() {
let view = this; let view = this;
...@@ -546,19 +557,20 @@ export default { ...@@ -546,19 +557,20 @@ export default {
let view = this; let view = this;
let user = this.usersById({id: this.userId}); let user = this.usersById({id: this.userId});
let file = {}; let file = {};
let blob = new Blob(view.chunks, {type: 'audio/webm; codecs:vp9' });
file.attributes = {}; file.attributes = {};
file.attributes.name = (user.attributes["formatted-name"]).replace(/\s+/g, '_') + '.ogg'; file.attributes.name = (user.attributes["formatted-name"]).replace(/\s+/g, '_') + '.webm';
let fileObj = false; let fileObj = false;
try { try {
fileObj = await this.createFile({ fileObj = await this.createFile({
file: file, file: file,
filedata: view.blob, filedata: blob,
folder: {id: this.currentFolderId} folder: {id: this.currentFolderId}
}); });
} }
catch(e) { catch(e) {
this.companionError({ this.companionError({
info: this.$gettext('Es ist ein Fehler aufgetretten! Die Aufnahme konnte nicht gespeichert werden.') info: this.$gettext('Es ist ein Fehler aufgetreten! Die Aufnahme konnte nicht gespeichert werden.')
}); });
console.debug(e); console.debug(e);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment