How to stop one pushbutton_Callback when another pushbutton_Callback is pressed?
2 views (last 30 days)
Show older comments
Peter
on 28 Jul 2015
Commented: Walter Roberson
on 29 Jul 2015
I have multiple pushbuttons in my GUI and a single video file in each pushbutton_callback. Is there any line I can write at the start of each function to stop the currently running function so the video doesn't need to play all the way through?
If i click a pushbutton while the video is playing, the GUI will play the new video and when it finishes it will play the remaining of the video that was interrupted.
I can provide more info if the question is not clear enough. Thank you
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
obj = VideoReader('supernewtable.mp4');
video = obj.read();
axes(handles.axes1);
fps=120;
for i=1:max(video(1,1,1,:))
imshow(video(:,:,:,i));
pause(0.5/fps);
end
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
obj = VideoReader('contgantry.mp4');
video = obj.read();
axes(handles.axes1);
fps=120;
for i=1:max(video(1,1,1,:))
imshow(video(:,:,:,i));
pause(0.5/fps);
end
0 Comments
Accepted Answer
Walter Roberson
on 29 Jul 2015
In the below, I really think you should be replacing max(video(1,1,1,:)) with size(video,4) as the number of frames to play depends on the data size not on the content of the pixels.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ~isfield('handles', 'active_player')
handles.active_player = 0;
end
%go ahead and bash the active player: the other routines will detect the change
%and will quit running
handles.active_player = 1;
guidata(hObject, handles);
obj = VideoReader('supernewtable.mp4');
video = obj.read();
axes(handles.axes1);
fps=120;
for i=1:max(video(1,1,1,:))
handles = guidata(hObject);
if handles.active_player ~= 1; break; end
imshow(video(:,:,:,i));
pause(0.5/fps);
end
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ~isfield('handles', 'active_player')
handles.active_player = 0;
end
%go ahead and bash the active player: the other routines will detect the change
%and will quit running
handles.active_player = 2;
guidata(hObject, handles);
obj = VideoReader('contgantry.mp4');
video = obj.read();
axes(handles.axes1);
fps=120;
for i=1:max(video(1,1,1,:))
handles = guidata(hObject);
if handles.active_player ~= 2; break; end
imshow(video(:,:,:,i));
pause(0.5/fps);
end
2 Comments
Walter Roberson
on 29 Jul 2015
Looking again, I see you can omit the lines
if ~isfield('handles', 'active_player')
handles.active_player = 0;
end
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!