Play/Stop Music in GUI with dropdown (separate buttons)
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi there,
I'm trying to create a GUI that has a dropdown menu to select between different audio files that will then use an audioplayer object to play/stop these files using play/pause/stop pushbuttons. This worked using sound(), but I want to pause/stop. I know that audioplayer disappears if it's empty.
Here's the relevant GUI code:
fighandl=figure; % create a figure and a "handle" to it
set(fighandl,'Name','QuickSIN'); % access handle, give fig a name
set(fighandl,'UserData','start');
set(fighandl, 'units', 'normalized', 'position', [0.15 0.15 0.7 0.7])
handles = guihandles(fighandl);
%dropdown menu (only working on getting 'Practice 1' working now)
handles.quickSIN = uicontrol(fighandl,'Style','popupmenu',...
'Units','Normalized',...
'Position',[0.05 0.65 0.2 0.3],...
'FontSize',15,...
'String',{'Practice 1','Practice 2','Practice 3','List 1','List 2','List 3','List 4','List 5','List 6'});
handles.push2=uicontrol('Style','pushbutton',...
'String','4',...
'FontSize',140,...
'FontName','Marlett',...
'FontWeight','bold',...
'Units','Normalized',...
'Position',[0.75 0.65 0.2 0.3],...
'BackgroundColor',[0.62352941176, 0.3725490196, 0.62352941176],...
'ForegroundColor','white',...
'Callback',@play_Callback);
Here's the relevant parts of the callback function:
function play_Callback(play, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = guidata(gcf);
persistent AP;
%note for this - create audioplayer object
if handles.quickSIN.Value == 1
[y,Fs] = audioread('audiofile1.wma');
AP = audioplayer(y,Fs);
play(AP);
elseif handles.quickSIN.Value == 2 %and so on with other values
[y,Fs] = audioread('audiofile2.wma');
AP = audioplayer(y,Fs);
play(AP);
end
I've tried to create an audioplayer function that the if statement calls, but that didn't work well for me either.
Maybe I'm thinking about this the wrong way?
Andrew
댓글 수: 0
답변 (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!