audioplayer/isplaying won't exit tight loop
Show older comments
When trying to determine when an audioplayer object has finished playing a sound, the following code enters an infinite loop:
aobj = audioplayer(rand(10000,1), 48000, 16, 2);
play(aobj);
while isplaying(aobj)
end
while this code doesn't:
aobj = audioplayer(rand(10000,1), 48000, 16, 2);
play(aobj);
while isplaying(aobj)
pause(0.00001);
end
Can somebody explain what's happening? I'm running Matlab 7.13.0.564 (R2011b) on a Mac, OS 10.7.4. Thank you!
Accepted Answer
More Answers (2)
pause and drawnow allow pending events to be processed. This triggers the update of windows, gui elements and even the audioplayer object. See doc pause and doc drawnow .
playblocking(aobj);
I have the same problem, but I kind of solved it using:
isempty(aobj)
Return true if the object is empty, which mean, you have not yet load the objet. So, doesn't make sense,at least, stop,pause or resume. I hope that helps.
(Sorry my english).
Categories
Find more on Startup and Shutdown 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!