Getting sound to play and stop

조회 수: 2 (최근 30일)
Rooy
Rooy 2012년 4월 13일
I am trying to start and stop playing music in GUI matlab
% --- Executes on button press in Start.
function Start_Callback(hObject, eventdata, handles)
% hObject handle to Start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
playersound
% --- Executes on button press in Stop.
function Stop_Callback(hObject, eventdata, handles)
% hObject handle to Stop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
stop(player)
I call my function playersound but I do not hear any sound.
function player=playersound
%My Function
[y,Fs]=wavread('Phone_01.wav');
player=audioplayer(y,Fs);
play(player)
It works if I run the function or use it in the command window but in the GUI it does not. Please bare with me as I am new with GUI but I think it is not calling back properly.
Thank you
  댓글 수: 2
Rooy
Rooy 2012년 4월 14일
It shows that it is playing but I do not hear anything.
Daniel Shub
Daniel Shub 2012년 4월 15일
This is basically identical to:
http://www.mathworks.com/matlabcentral/answers/18530-audioplayer

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2012년 4월 14일
Your audioplayer object is going out of scope when playersound() exits. When it goes out of scope, the object is deleted.
You need to save the player object and you need to be able to get to that player object in your stop callback.
  댓글 수: 2
Rooy
Rooy 2012년 4월 14일
Would this affect my ability to hear the music when I press the button because even that is not working.
Thank you
Walter Roberson
Walter Roberson 2012년 4월 14일
Yes it would.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by