I'm having issues in this process . First is that I have a button in disabled state(true) and I need to change that value to false when the video is uploaded . I have this scenary and I think I got a windows object inside the changing method . Any idea, help please . I'm getting undefined value for the variable.
data: () => ({
buttonState: true} }),
changeBehavior() {
let self
(function () {
const input = document.getElementById('uploader')
self = this
console.log(this)
const changing = ({ target: { files } }) => {
if (input.files.length > 0) {
// self.buttonState = false
const video = document.getElementById('output-video')
video.src = URL.createObjectURL(files[0])
}
}
input.addEventListener('change', changing)
})()
const au = document.getElementById('output-video')
au.onloadedmetadata = () => {
const hidden = document.getElementById('hiddenSlider')
hidden.removeAttribute('hidden')
const muteHidden = document.getElementById('muteHidden')
muteHidden.removeAttribute('hidden')
self = this
self.range = [0, au.duration]
this.max = au.duration
const secNum = parseInt(au.duration, 10)
let hours = Math.floor(secNum / 3600)
let minutes = Math.floor((secNum - (hours * 3600)) / 60)
let seconds = secNum - (hours * 3600) - (minutes * 60)
if (hours < 10) {
hours = '0' + hours
}
if (minutes < 10) {
minutes = '0' + minutes
}
if (seconds < 10) {
seconds = '0' + seconds
}
document.getElementById('renderizado').innerHTML =
hours + ':' + minutes + ':' + seconds
}
},
<v-btn
id="run"
class="accent-3 blue ml-15"
dark
#click="$refs.inputUpload.click()"
>
<input
v-show="false"
id="uploader"
ref="inputUpload"
accept=".mkv,video/*"
type="file"
#click="changeBehavior"
>
Select to Upload Video
</v-btn>
<v-btn
id="doTrimming"
block
class="accent-3 blue mt-5"
dark
:disabled="buttonState"
#click="cutIt"
>
Trim Video Now
</v-btn>
Where you define self you need to assign this to it then.
changeBehavior() {
const self = this;
const callback = function() {
// now you can access the vue instance when in another functions scope
self.buttonState = true;
}
}
Related
I'm trying to use the react-native-calendars library in my code.
I'm trying to understand this snipped of the code here
loadItems = (day: DateData) => {
const items = this.state.items || {};
setTimeout(() => {
for (let i = -15; i < 85; i++) {
const time = day.timestamp + i * 24 * 60 * 60 * 1000;
const strTime = this.timeToString(time);
if (!items[strTime]) {
items[strTime] = [];
const numItems = Math.floor(Math.random() * 3 + 1);
for (let j = 0; j < numItems; j++) {
items[strTime].push({
name: 'Item for ' + strTime + ' #' + j,
height: Math.max(50, Math.floor(Math.random() * 150)),
day: strTime
});
}
}
}
const newItems: AgendaSchedule = {};
Object.keys(items).forEach(key => {
newItems[key] = items[key];
});
this.setState({
items: newItems
});
}, 1000);
}
The entire code snip can be found here: https://gist.github.com/jonasgroendahl/f5e938cdf0a77c2e1509ded22630ba7d
Currently I know this part of the code generates an item for everyday. I'm looking to change this up but I'm not sure what happening line by line. If anyone can please break this down and explain it to me would be great. Thanks.
This question already has answers here:
MediaRecorder.stop() doesn't clear the recording icon in the tab
(2 answers)
Closed 4 months ago.
This has been racking my brain for a week.
I have getDisplayMedia working just fine, however I want to turn off the "sharing permission" after recording has been stopped.
I've seen this work here:
https://www.webrtc-experiment.com/RecordRTC/
Set the form to record the Full Screen
Start recording
Stop recording
You will see the "permission dialog" disappear.
How can I programmatically do this?
Current Code:
recBtn.onclick = () => {
stopBtn.disabled = false;
recBtn.disabled = true;
limRange.disabled = true;
navigator.mediaDevices
.getDisplayMedia ({
audio: {
sampleRate: 44100,
echoCancellation: false,
noiseSuppression: false
},
video: { mediaSource: "screen" },
})
.then ( ( stream ) =>
{
mediaRecorder = new MediaRecorder( stream );
//music.play();
mediaRecorder.addEventListener("dataavailable", (e) =>
{
// manage timer
if ( seconds >= 60 ) {
seconds = 0;
minutes += 1;
}
seconds += 1;
if ( minutes > 9 && seconds > 9 )
{
p.innerHTML = minutes + ":" + seconds;
}
else if ( minutes > 9 )
{
p.innerHTML = minutes + ":0" + seconds;
}
else if ( seconds > 9 )
{
p.innerHTML = "0" + minutes + ":" + seconds;
}
else {
p.innerHTML = "0" + minutes + ":0" + seconds;
}
// push data
chunks.push(e.data);
});
mediaRecorder.onstop = ( e ) =>
{
//console.log( chunks );
const blob = new Blob( chunks , { type: "audio/mp3" });
//console.log( minutes, seconds );
var offlineAudioContext = new OfflineAudioContext (
2,
44100 * ((minutes * 60) + seconds),
44100
);
var soundSource = offlineAudioContext.createBufferSource();
var audioContext = new window.AudioContext();
var reader = new FileReader();
var buff;
reader.readAsArrayBuffer(blob); // video file
reader.onload = function ()
{
var videoFileAsBuffer = reader.result; // arraybuffer
audioContext
.decodeAudioData(videoFileAsBuffer)
.then( function ( decodedAudioData )
{
myBuffer = decodedAudioData;
soundSource.buffer = myBuffer;
soundSource.connect(offlineAudioContext.destination);
soundSource.start();
offlineAudioContext
.startRendering()
.then( function ( renderedBuffer )
{
console.log(renderedBuffer); // outputs audiobuffer
buff = renderedBuffer;
let wav = audioBufferToWav(buff);
console.log(wav);
let bblob = new window.Blob([new DataView(wav)], {
type: "audio/mp3",
});
const audioURL = URL.createObjectURL(bblob);
audioRecorded.src = audioURL;
/*const fileName =
"recording-" +
recs +
"-" +
minutes +
"_" +
seconds +
".mp3";*/
var fileName = "Block " + block_letter.toUpperCase() + " - " + block_filename + '.mp3';
let elm = document.createElement("a");
elm.id = 'download-mp3'
elm.setAttribute("href", audioRecorded.src);
elm.setAttribute("download", fileName);
//elm.click();
//elm.remove();
$('.download-link').html( elm );
$('#download-mp3').html( fileName ).addClass('text-4 text-primary font-weight-semi-bold');
$('.recording-link').show();
$('.recording-info').hide();
minutes = 0;
seconds = 0;
})
.catch(function (err) {
console.log("Rendering failed: " + err);
});
})
.catch(function (err) {
console.log("audioContext failed: " + err);
});
};
console.log("recorder stopped");
chunks = [];
p.innerHTML = "00:00";
if (recs == 0)
{
document.body.appendChild(audioRecorded);
}
recs += 1;
$('#btn-record, .btn-block-stop, .modal-btn-right').show();
$('#btn-record-stop, .recording-inprogress').hide();
$('.btn-block-stop').click();
};
mediaRecorder.start(1000);
$('.ajax-modal-btn-right').click();
$('#btn-record, .btn-block-stop, .modal-btn-right').hide();
$('#btn-record-stop, .recording-inprogress').show();
//console.log(mediaRecorder.state);
//console.log("recorder started");
})
.catch ( (error) =>
{
console.log ('error');
});
};
stopBtn.onclick = () =>
{
recBtn.disabled = false;
limRange.disabled = false;
stopBtn.disabled = true;
mediaRecorder.stop( 5000 );
console.log("recording stopped");
$('#btn-record, .btn-block-stop, .modal-btn-right').show();
$('#btn-record-stop, .recording-inprogress').hide();
$('.btn-block-stop').click();
};
The media permissions settings are not accessible from Javascript code. They just aren't, so it's no wonder you can't find them. Because cybercreeps could trick our users into revealing sensitive information.
It's a real pain in the neck, but it works the same for everybody from Google Meet on down.
Hi I'm just trying up setstate a component with interval.I put interval code in componentdidmount and clear it in componentWillUnmount.
It should stops intervalling when user navigates another screen but console logs says it continues.
Also i want to works this in every 1 second but when i put interval time as 1000 it works in 3 second
constructor(props) {
super(props);
this.state = {
text:'',
};
this._interval = null;
}
componentDidMount() {
if (!this._interval) {
console.log('this._interval',this._interval)
var endNew = new Date(this.props.end);
var distance = endNew.getTime() - newNow.getTime();
var hour = Math.floor(distance / 1000 / 60 / 60);
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
if (hour < 1 && minutes < 1 && seconds < 2) {
this.setState({isClosed: false});
} else {
this.setState({
textt: hour + ' h ' + minutes + ' m ' + seconds + 's',
});
}
}, 1000);
}
}
componentWillUnmount() {
clearInterval(this._interval);
clearTimeout(this._interval);
}
if (!this._interval) {
console.log('this._interval',this._interval)
and console log = this._interval null
In case you are using react-navigation stacknavigator won‘t callcomponentdidmount when pushing a new view on top.
As you can see in docs, you should rather subscribe to focus/blur.
I have data, timestamp, that comes from the server as a unix timestamp. I am trying to dynamically insert this in every second. I can get it to successfully console.log the time (console.log(x)) but it won't return it and insert the time in the DOM.
<template>
<div>
<span> {{ checkItemExpiry(timestamp) }}</span>
</div>
</template>
<script>
export default {
methods: {
convertTime: function(time) {
var sec_num = parseInt(time, 10);
var hours = Math.floor(sec_num / 3600);
var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
var seconds = sec_num - (hours * 3600) - (minutes * 60);
if (hours < 10) {
hours = "0" + hours;
}
if (minutes < 10) {
minutes = "0" + minutes;
}
if (seconds < 10) {
seconds = "0" + seconds;
}
let x = (hours + ":" + minutes + ":" + seconds);
console.log(x)
return x
},
checkItemExpiry: function(expireTimestamp) {
let startTime = expireTimestamp;
setInterval(() => {
let currentTime = (new Date()).getTime() / 1000;
this.convertTime((startTime-currentTime))
}, 1000);
}
}
}
</script>
I have a code with which i can fetch image through internet ... I have completed it. I have to add to button , one to increase and one to reduce the interval ... in action script 2.0
import mx.transitions.*;
import mx.transitions.easing.*;
my_pb.mode = "manual";
this.createEmptyMovieClip("img_mc", 999);
var my_mcl:MovieClipLoader = new MovieClipLoader();
var mclListenerbject = new Object();
mclListener.onLoadStart = function(target_mc:MovieClip) {
my_pb.label = "loading: "+target_mc._name;
};
mclListener.onLoadProgress = function(target_mc:MovieClip, numBytesLoaded:Number, numBytesTotal:Number) {
var pctLoaded:Number = Math.ceil(100*(numBytesLoaded/numBytesTotal));
my_pb.setProgress(numBytesLoaded, numBytesTotal);
};
var number:Number = 2000;
var myInterval = setInterval(testInterval, number); //
function testInterval() {
my_mcl.addListener(mclListener);
my_mcl.loadClip("http://google.com/l5", img_mc);
}
i can create 2 button but there are some error...
If you want change the interval of the setInterval function, you have to clear it and then use the function with the new interval value, like this :
var delay:Number = 2000;
var interval = setInterval(on_repeat, delay);
function on_repeat() {
// instructions
}
fast.onPress = function(){
clearInterval(interval);
interval = setInterval(on_repeat, delay - 1000);
}
slow.onPress = function(){
clearInterval(interval);
interval = setInterval(on_repeat, delay + 1000);
}
But, as #Raptor has said, I recommend you to use ActionScript 3 instead of the old ActionScript 2.
For example, the code above can simply be replaced by a Timer object like this :
var delay:int = 2000;
var timer:Timer = new Timer(delay);
timer.addEventListener(TimerEvent.TIMER, function(e:TimerEvent):void {
// instructions
})
timer.start();
fast.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void {
timer.delay = delay - 1000;
})
slow.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void {
timer.delay = delay + 1000;
})
Hope that can help.
var current_loader:Number = 1;
var current_img:Number = 0;
this.createEmptyMovieClip('img_01', 999);
this.createEmptyMovieClip('img_02', 998);
img_01._x = img_01._y=img_02._x=img_02._y=20;
var loader:MovieClipLoader = new MovieClipLoader();
var listener:Object = new Object();
listener.onLoadStart = function(target_mc:MovieClip) {
};
listener.onLoadProgress = function(target_mc:MovieClip, numBytesLoaded:Number, numBytesTotal:Number) {
};
listener.onLoadComplete = function(target_mc:MovieClip) {
if (target_mc._name == 'img_01') {
img_02._visible = false;
} else {
img_01._visible = false;
}
};
var delay:Number = 2000;
var interval = setInterval(load_image, delay);
function load_image() {
loader.addListener(listener);
loader.loadClip("http://google.com/latimage.php?", _root['img_0'+current_loader]);
current_loader = current_loader == 1 ? 2 : 1;
current_img = current_img == images.length-1 ? 0 : current_img+1;
}
slow.onRelease = function() {
interval = setInterval(load_image, delay+1000);
trace(interval);
};
fast.onRelease = function() {
clearInterval(interval);
interval = setInterval(load_image, delay-1000);
trace(interval);
};
image_load();