필터 지우기
필터 지우기

Wait for sound to finish and then execute

조회 수: 17 (최근 30일)
Adham Elkhouly
Adham Elkhouly 2021년 4월 27일
댓글: Adham Elkhouly 2021년 4월 27일
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

채택된 답변

Steven Lord
Steven Lord 2021년 4월 27일
Instead of calling play on your audioplayer object you should call playblocking.
  댓글 수: 2
Adham Elkhouly
Adham Elkhouly 2021년 4월 27일
Thank you
Adham Elkhouly
Adham Elkhouly 2021년 4월 27일
it intially worked but now I get an error that says Invalid or deleted object.
if(app.wav_flag == 1 && app.yn_flag ==0)
app.playingxnLamp.Color = 'g';
app.player = audioplayer(app.x, app.fs);
app.xn_flag = 1;
playblocking(app.player,app.fs);
app.playingxnLamp.Color = 'r'; %<-- here
end

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2021년 4월 27일
Use a stopFcn callback https://www.mathworks.com/help/matlab/ref/audioplayer.html#mw_ce25e74d-6a00-44d6-9ae9-9a6e6335962c

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by