Wait for sound to finish and then execute
36 views (last 30 days)
Show older comments
Adham Elkhouly
on 27 Apr 2021
Commented: Adham Elkhouly
on 27 Apr 2021
I am trying to create a lamp that turns green while the audio is playing and red after the audio is played. I wrote the following function
function PlayxnButtonPushed(app, event)
if(app.wav_flag == 1 && app.yn_flag ==0)
app.playingxnLamp.Color = 'g';
app.player = audioplayer(app.x, app.fs);
play(app.player,app.fs);
while( strcmp(app.player.running,'on') )
app.xn_flag = 1; % Waiting for sound to finish here
end
end
app.xn_flag = 0;
app.playingxnLamp.Color = 'r';
end
But it creates huge lag that I have to terminate the program using task manager.
Any idea how to fix this?
Thank you
0 Comments
Accepted Answer
More Answers (1)
Walter Roberson
on 27 Apr 2021
Use a stopFcn callback https://www.mathworks.com/help/matlab/ref/audioplayer.html#mw_ce25e74d-6a00-44d6-9ae9-9a6e6335962c
See Also
Categories
Find more on Audio and Video Data 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!