正如我们的朋友所说。您必须使用播放阻止而不是播放。循环时无需。考虑一下:
我正在尝试创建一个在播放音频时变为绿色,在播放音频后变为红色的灯。我写了这些行
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') )
% Waiting for sound to finish
end
app.xn_flag = 1;
end
app.xn_flag = 0;
app.playingxnLamp.Color = 'r';
end
但它们造成了滞后,我最终不得不打开任务管理器来终止程序。你知道我应该做什么吗?-TIA-
使用playblocking
而不是play
。playblocking
功能保持控制,直到播放完成。
function PlayxnButtonPushed(app, event)
if(app.wav_flag == 1 && app.yn_flag ==0)
app.player = audioplayer(app.x, app.fs);
app.playingxnLamp.Color = 'g';
playblocking(app.player,app.fs); %replaced play with playblocking
app.xn_flag = 1;
end
app.xn_flag = 0;
app.playingxnLamp.Color = 'r';
end
app.Lamp.Color = 'g';
player = audioplayer(y,Fs);
playblocking(player)
app.Lamp.Color = 'r';