- You can play the whole sound before returning by switching to playblocking() instead of play(); OR
- You can add some code in the callback that arranges so that it does not return before the sound is finished, such as by adding pause() or appropriate waitfor(); OR
- You can store a reference to the audioplayer outside the workspace so that it does not get deleted when the function returns; see http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.3F; OR
- You can create the audioplayer before-hand and store it in an accessible location using the techniques in the above link, and then have your callback just play() it
Audio does not play
19 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
[y, Fs] = audioread(filename);
a = audioplayer(y, Fs);
play(a);
This is the code I currently have for playing an audio file given the filename. It works when I run it in command line, but does not work when I run it as a part of GUI code. I've checked that the program goes through these lines of codes, but the only thing is that it does not play the sound it does when run in command line. How do I fix this?
0 Kommentare
Antworten (1)
Walter Roberson
am 6 Mär. 2016
You are defining your audioplayer in the workspace of your callback function. As soon as that function returns, the audioplayer is deleted (along with all other variables in the workspace of the function.)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Audio and Video Data finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!