Callback functions for displaying videos
2 views (last 30 days)
Show older comments
I am making a GUI in Matlab using AppDesigner. It displays a video after pressing the push button. This video is already stored in a folder and I am reading it first and then playing it. But the problem is "The video is displayed in a different window". How can I display the video in the same window where push button was pressed. I am attaching here the piece of code used as callback function for dispalying window.
function ButtonPushed(app, event)
app1.VFR= vision.VideoFileReader('newfile.avi');
app1.VPR = vision.VideoPlayer;
% Play video. Every call to the step method reads another frame.
while ~isDone(app1.VFR)
frame = step(app1.VFR);
step(app1.VPR,frame);
end
end
Please suggest a way for this. In case anyone need details regarding the problem please leave a comment.
2 Comments
Mohammad Sami
on 6 Jan 2020
If you have the latest version of Matlab and your videos are mp4 standard, you can use the uihtml element to embed your video as an html.
The html tags for embedding a video can be seen here.
Accepted Answer
Max Murphy
on 6 Jan 2020
% In app constructor
...
% Initialize image
app.Figure = figure('Name','Main Video GUI');
app.VidAx = axes(app1.Figure,'XColor','none','YColor','none',...
'XLim',[0 1],'YLim',[0 1]);
% Can't remember, but here if your video is upside down:
% app1.VidAx.YDir = 'reverse';
app.VFR= vision.VideoFileReader('newfile.avi');
[h,w] = app.VFR.VideoSize;
app.VideoImage = imagesc(app.VidAx,linspace(0,1,w),linspace(0,1,h),zeros(h,w));
...
% Rest of app constructor
function ButtonPushed(app, event)
% Reset the video first
reset(app.VFR);
% Play video. Every call to the step method reads another frame.
while ~isDone(app.VFR)
% Update image frame
app.VideoImage.CData = step(app.VFR);
drawnow limitrate; % Limits to 20 fps
end
end
Rough outline to get you started.
2 Comments
Max Murphy
on 6 Jan 2020
In my code, this line
app.Figure = figure('Name','Main Video GUI');
Should correspond to whatever the intrinsic property of app that corresponds with the current window figure handle. If you don't know what that property is, you could just replace that line with this and I think it would still work (unless the app figure is created later on in the code):
app.Figure = gcf;
More Answers (0)
See Also
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!