- 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
조회 수: 13 (최근 30일)
이전 댓글 표시
[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
답변 (1개)
Walter Roberson
2016년 3월 6일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Audio and Video Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!