Main Content

play

Play audio from audioplayer object

Syntax

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

Description

play(playerObj) plays the audio associated with audioplayer object playerObj from beginning to end.

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

play(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]);