How to play audio files one by one by pushing the same button in GUI

2 visualizaciones (últimos 30 días)
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
Lucky
Lucky el 10 de Jun. de 2013
Thank you, Daniel, now I hope the question is clear?
John
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???

Iniciar sesión para comentar.

Respuesta aceptada

Daniel Shub
Daniel Shub el 10 de Jun. de 2013
If I understand your code correctly, every time you push the button the first file is played, but you want it to step through the list. Assuming you do not need the list for anything else you can chop the first item off the list by adding r = r{2:end}; (obviously with a check to make sure there are at least 2 items) at the end of your PLAYAUDIObutton_Callback function. If you need the list, you could set a new global (or persistent) counter in PLAYAUDIObutton_Callback

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by