An AudioPlayer Function in the App Designer

Hi, I'm attempting to implement a "play" and "stop" button in MATLAB's app designer. So far, I've attempted a try-catch method explained here and I can play the audio file. However, I'm attempting to get the stop button to work. Please help if possible.
% Button pushed function: PlayMusicButton
function PlayMusicButtonPushed(app, event)
try
[y, Fs] = audioread('reach2.mp3');
player=audioplayer(y,Fs);
playblocking(player)
catch ME
uiwait(msgbox('Could not open that file with audioread'));
end
app.player = player;
end
% Button pushed function: StopMusicButton
function StopMusicButtonPushed(app, event)
stop(app.player);
end
end

1 件のコメント

Geoff Hayes
Geoff Hayes 2020 年 3 月 19 日
What happens when the stop button is pressed? Does the StopMusicButtonPushed get called?

サインインしてコメントする。

回答 (1 件)

Ido
Ido 2022 年 12 月 19 日

0 投票

try
play(player);
and not
playblocking(player)

タグ

質問済み:

2020 年 3 月 9 日

回答済み:

Ido
2022 年 12 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by