Why 'play' doesn't work within a function?
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi,
When I create an audioplayer object inside a function it doesn't play the sound. for example- this code doesn't work:
noise=wgn(8192, 1,0);
runaudio(noise)
function runaudio(noise)
pl=audioplayer(noise,8192);
play(pl);
end
But if i pass the player object it does work.
for example - this code works:
noise=wgn(8192, 1,0);
pl=audioplayer(noise,8192);
runaudioP(pl)
function runaudioP(pl)
play(pl);
end
What am I missing here?
Thanks,
Urit
댓글 수: 0
답변 (1개)
Daniel Shub
2013년 2월 21일
This question has been asked and answered here before a number of times. The simple answer is that when the function exits, the audio player object gets deleted. If you pass the object. To the function, then the object still exits in the base workspace.
참고 항목
카테고리
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!