필터 지우기
필터 지우기

appdesigner: use a slider to play a video

조회 수: 3 (최근 30일)
Marina Llopis Segura
Marina Llopis Segura 2023년 3월 28일
답변: Antoni Garcia-Herreros 2023년 3월 28일
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.

채택된 답변

Antoni Garcia-Herreros
Antoni Garcia-Herreros 2023년 3월 28일
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!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by