appdesigner: use a slider to play a video
18 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!