MATLAB GUI Help needed for playing consecutive media files without timer

1 view (last 30 days)
I am working on a project that when there is a serial input 'A' then a series of videos will play in GUI and as soon as there is serial input 'B' another set of videos will play.
The problem is if I use delay(duration of current video) for playing one video after another then i dont get continuous serial input. and if dont use delay, i am unable play videos one after another.
please help
Following is the code and explanation
I set of videos - p1, p2, p3, p4 (variables have address of videos in string form)
II set of videos - n1, n2, n3, n4 (variables have address of videos in string form)
In the following code, I will not get continuous input because, delay will no allow the loop to complete once until all the videos are played only for one signal, this is what should not be there.
the required system is when there is signal A, p series should start playing and loop should complete everytime so that signal can receive different values and as soon as signal receives B it should start n series videos.
global p1 p2 p3 p4 n1 n2 n3 n4 ;
p11=VideoReader(p1);
p22=VideoReader(p2);
pd1=p11.Duration;
pd2=p22.Duration;
p33=VideoReader(p3);
p44=VideoReader(p4);
pd3=p33.Duration;
pd4=p44.Duration;
n11=VideoReader(n1);
n22=VideoReader(n2);
nd1=n11.Duration;
nd2=n22.Duration;
n33=VideoReader(n3);
n44=VideoReader(n4);
nd3=n33.Duration;
nd4=n44.Duration;
s=serial('COM17','BaudRate',9600,'DataBits',8);% setting object file for serial port
s.InputBufferSize = 1;
fopen(s);%opening the serial port
s.ReadAsyncMode='manual';
while (1)
pause(1);
readasync(s);
signal=fscanf(s)
stopasync(s);
%structure
signalf=compareinput(signal);% this is a designed func to get one signal for a set of common/same signals
while (signalf=='A')
set(handles.activex1,'URL',p1);
delay(pd1);
set(handles.activex1,'URL',p2);
delay(pd2);
set(handles.activex1,'URL',p3);
delay(pd3);
set(handles.activex1,'URL',p4);
delay(pd4);
break
end
while (signalf=='B')
%
set(handles.activex1,'URL',n1);
delay(nd1);
set(handles.activex1,'URL',n2);
delay(nd2);
set(handles.activex1,'URL',n3);
delay(nd3);
set(handles.activex1,'URL',n4);
delay(nd4);
break
end
end
end
fclose(s);
delete(s);
  2 Comments
Walter Roberson
Walter Roberson on 25 Dec 2015
What is all that about activex and URL? And what delay() routine are you calling? I do not find a delay() in any of the toolboxes.
Anshu Pandey
Anshu Pandey on 25 Dec 2015
In GUIDE, I have used activex controlling of Windows media player, so to set which media is to play, I need to change its URL.
delay()=pause();

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 25 Dec 2015
You do not need to pause until the Windows media has played. Leave the serial object active instead of starting and stopping async every check. You can enter a loop of checking the serial object BytesAvailable to see if anything has arrived, and checking the media status. Have a cell array of the names and the current index and loop instead of handling the four of them one by one. Give it another index layer and you get the A/B handling for pretty much free.
And remember you can set a serial port BytesAvailableFcn callback so you don't even need to keep checking the serial port status (just have to make sure you reload the current version of the shared variable that tells you which set you are playing.)

More Answers (0)

Community Treasure Hunt

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

Start Hunting!