MATLAB app designer not playing sounds

54 views (last 30 days)
I am trying to excute the following lines with MATLAB app designer
[x, fs] = audioread('wave.wav');
app.freq = 2 * fs;
player = audioplayer(x, app.freq);
play(player);
but no sound is produced. However, when I copy the above lines along with those lines,
restoredefaultpath
rehash toolboxcache
savepath
it sounds in the command window but not in the app designer.
How can I fix this issue? - TIA

Accepted Answer

Subhadeep Koley
Subhadeep Koley on 27 Apr 2021
I have attached one demo minimum working example.
Have a look. It might help you fix the issue.
Also, if possible provide the full path of the sound file when reading it with audioread()
  5 Comments
Subhadeep Koley
Subhadeep Koley on 27 Apr 2021
Define a public property player and store the audioplayer object inside app.player.
Then invoke play(app.player)
[filename, pathname]=uigetfile({'*.wav'},'File Selector');
fullpathname = fullfile(pathname, filename);
try
[app.x,app.fs] = audioread(fullpathname);
catch
return
end
app.wavFolderAvailableLamp.Color = 'g';
app.freq = 2 * app.fs;
app.player = audioplayer(app.x, app.freq); % Here app.player is a public property variable
play(app.player);

Sign in to comment.

More Answers (1)

Adham Elkhouly
Adham Elkhouly on 27 Apr 2021
For anyone facing a similar issue, I used
sound(app.x,app.freq);
instead of
player = audioplayer(app.x, app.freq);
play(player);
  2 Comments
Adham Elkhouly
Adham Elkhouly on 27 Apr 2021
Yes, the sound keeps on with
sound()
and what you said works fine after I defined
player
as a public property - thank you very much

Sign in to comment.

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by