Main Content

playblocking

Play audio from audioplayer object, hold control until playback completes

Syntax

playblocking(playerObj)
playblocking(playerObj,start)
playblocking(playerObj,[start,stop])

Description

playblocking(playerObj) plays the audio associated with audioplayer object playerObj from beginning to end. playblocking does not return control until playback completes.

playblocking(playerObj,start) plays audio from the sample indicated by start to the end.

playblocking(playerObj,[start,stop]) plays audio from the sample indicated by start to the sample indicated by stop.

Examples

expand all

Play two audio samples with and without blocking using the play and playblocking methods.

Load data from example files chirp.mat and gong.mat.

chirpData = load('chirp.mat');
chirpObj = audioplayer(chirpData.y,chirpData.Fs);

gongData = load('gong.mat');
gongObj = audioplayer(gongData.y,gongData.Fs);

Play the samples with blocking, one after the other.

playblocking(chirpObj);
playblocking(gongObj);

Play without blocking. The audio can overlap.

play(chirpObj);
play(gongObj);

Play audio from the example file handel.mat starting 4 seconds from the beginning.

load handel.mat;
playerObj = audioplayer(y,Fs);
start = playerObj.SampleRate * 4;

play(playerObj,start);

Play the first 3 seconds of audio from the example file handel.mat.

load handel.mat;
playerObj = audioplayer(y,Fs);
start = 1;
stop = playerObj.SampleRate * 3;

play(playerObj,[start,stop]);

See Also

|