How to play audio files one by one by pushing the same button in GUI
Mostrar comentarios más antiguos
Hi there! I am new to Matlab and gui especially, please help me! I need to play wav files one by one by pushing a button in gui. My files are in a folder, but I need to play them in a random way. I did permutations to shuffle them (this is because I need to know how exactly they shuffled, to make a statistics). In my opening function I wrote:
% --- Executes just before MYGUI is made visible.
function MYGUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to MYGUI (see VARARGIN)
% Choose default command line output for MYGUI
handles.output = hObject;
handles.status=0;
%inizialize global variable
global r
FoldData = dir('New Folder'); %Put metadata for folder in variable
FoldIndex = [FoldData.isdir]; %Gets list of files in folder
FileList = {FoldData(~FoldIndex).name};
FileList = FileList'; %Transpose resultant row vector into column vector
v = FileList';
P = perms(v); %make permutation of verctor v
r = P(9,:) %select 10th row (random choice)
r =
'comb3.wav' 'comb2.wav' 'comb4.wav' 'comb1.wav'
In my pushbutton callback (PLAYAUDIObutton) I have:
% --- Executes on button press in PLAYAUDIObutton.
function PLAYAUDIObutton_Callback(hObject, eventdata, handles)
% hObject handle to PLAYAUDIObutton(see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global r
if handles.status==0
handles.status=1;
k = r{1, 1}; %select 1st wav file from 10th row
[y,Fs]=wavread(k); %Import and play file
handles.audio = audioplayer(y,Fs);
play(handles.audio);
else
msgbox ('Test is finished. Thank you for your participation!');
end
guidata(hObject,handles);
But, this code is only for playing the very first audio file from my list (comb3.wav). Now I need to figure out how to play all 4 files one by one by pushing PLAYAUDIOpushbutton: I need to press button and hear comb3.wav, by pushing the same button second time to hear comb2.wav and etc. What function should I choose to play them sequentially? There could be not only 4 files, but around 20... Thank you in advance!!
4 comentarios
Daniel Shub
el 10 de Jun. de 2013
Please edit the question to include what have you tried so far and where you are stuck.
Daniel Shub
el 10 de Jun. de 2013
Creating a GUI is very different from creating a function that plays wav files one after the other. You need to focus your question so we can help you solve your problems. You need to edit the question to show where are you stuck. In other words, provide simplified code and a description of what happens when you run the code (e.g., the output or error message) and what you expect to happen and what you would like to happen.
Lucky
el 10 de Jun. de 2013
John
el 21 de Ag. de 2015
hallo everyone can anyone explain to me whats the meaning of handles.status==0??? in what help us????im new to this! thanks???
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Get Started with MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!