MATLAB: How to use the PLAY function to play a sound wave without using the handle of an AUDIOPLAYER object

MATLAB

The command
play(audioplayer(rand(1,44100),44100));
does not play anything but
playblocking(audioplayer(rand(1,44100),44100));
works fine.

Best Answer

The ability to use the PLAY function with an AUDIOPLAYER object without using the handle to that object is not available in MATLAB.
The proper way to use the PLAY function and AUDIOPLAYER objects is, as stated in the documentation, by using the handle to the AUDIOPLAYER object. For example:
load handel;
player = audioplayer(y, Fs);
play(player,[1 (get(player, 'SampleRate')*3)]);
% To stop the playback, use
stop(player); % Equivalent to player.stop
Related Question