MATLAB Answers

How can I interrupt the playback of an audio file that has been initiated using WAVPLAY in MATLAB 7.9 (R2009b)?

84 views (last 30 days)
I have created a GUI application which starts the playback of an audio file using WAVPLAY. I would like to insert a new button in the GUI that allows the user to pause or stop the audio playback.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 11 Nov 2009
There is no function in MATLAB that can pause or stop audio playback once initiated by WAVPLAY. Instead of using WAVPLAY, an alternative is to create an AUDIOPLAYER object. This type of object has methods which allow pausing, resuming and stopping the audio playback. For example:
player = audioplayer(Y, Fs)
% start the playback
play(player);
% pause the playback
pause(player);
% resume the playback
resume(player)
% stop the playback
stop(player)
For further details refer to the AUDIOPLAYER documentation.
doc audioplayer

  1 Comment

Sign in to comment.

More Answers (1)

Li Kang
Li Kang on 6 Dec 2016
clear sound

  2 Comments

Walter Roberson
Walter Roberson on 6 Dec 2016
Li Kang, what does "sound" refer to in your command?
The sound() function was not used for wavplay.
If you are referring to the data, then wavplay() takes a copy of it so clearing the data will not affect playback.
wavplay used the Windows-only functions playsnd and playsndb
Joe V
Joe V on 27 Jun 2019
Looks like "sound" is an undocumented flag to the clear command that terminates playback of queued audio data. Try this:
sound(0.1*sin(2*pi*440*(0:1/8192:30)), 8192);
clear sound;
+1 to Li Kang!

Sign in to comment.

Sign in to answer this question.