Push button audio for GUI

조회 수: 17 (최근 30일)
Caitlin Hoying
Caitlin Hoying 2017년 11월 21일
댓글: Deepu S S 2021년 7월 9일
Hello,
I have a class which I need to create a GUI. I am new to MATLAB and could really use some help.
What I'm planning to do is when a push button is pressed, the audio file plays then stops. I pasted the part of the script below with the audio in it.
% --- Executes on button press in pushbutton3. Reset Button
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.listbox1,'Value',1)
set(handles.popupmenu1,'Value',1)
listbox1_Callback(hObject, eventdata, handles)
load handel;
player = audioplayer(y, Fs);
play(player);
popupmenu1_Callback(hObject, eventdata, handles)
_____________
Thanks!!
  댓글 수: 1
Deepu S S
Deepu S S 2021년 7월 9일
bro can share the final code. i'm also new to matlab i need these kind of code please help me

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

채택된 답변

Walter Roberson
Walter Roberson 2017년 11월 21일
Change
play(player)
to
playblocking(player)
Otherwise the function will return after it starts playing, and when it returned it would destroy the local variables including the variable that stores the audio player; that would stop the playing.

추가 답변 (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