Azzera filtri
Azzera filtri

appdesigner: use a slider to play a video

3 visualizzazioni (ultimi 30 giorni)
Good morning, I am making a program in appdesigner that needs to play a video and through a slider you can configure the second of video in which it is located. That is to say if the video lasts 30 seconds, the slider will have a length of 30 and if I put the arrow of the slider in 10 seconds the video will show what appears in the second 10. I have achieved that in an axes I see the video but it plays from beginning to end without stopping. I would appreciate if someone could help me.
this is the capture of the code that I have generated in the callback of a button in which you can choose the video that will be played in the axes when you press it.

Risposta accettata

Antoni Garcia-Herreros
Antoni Garcia-Herreros il 28 Mar 2023
Hello Marina,
You could start by creating a startup Function where you create an array with all frames. Something like this:
function seleccionVideoButtonPushed(app, event)
%Select the video same way you are doing right now
video=VideoReader(foldervideo);
numFrames=video.NumberofFrames;
app.AllFrames=zeros(video.Height,video.Width,3,numFrames);
% This array will contain all the video frames
for a=1:numFrames
frame=read(video,a);
app.AllFrames(:,:,:,a)=frame;
end
end
Then you'll have to add a callback function when the slider is moved:
function SliderValueChanging(app, event)
changingValue = event.Value;
idx=floor(changingValue); % You may want to adjust this value based on the temporal resolution of your video
% The other option is to change the length of the slider to be
% the same as the number of frames.
imshow(app.AllFrames(:,:,:,idx),'Parent',app.UIAxes)
end
Hope this helps!

Più risposte (0)

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by