フィルターのクリア

Repeat audio button in GUI

1 回表示 (過去 30 日間)
Lucky
Lucky 2013 年 6 月 18 日
Hi all! I need to perform a listening test, there are 2 buttons in my GUI: 1. PLAY AUDIO: user listens to 20 wav files one by one. 2nd button: REPEAT AUDIO user should be able to repeat audio max 3 times, no more. I have a problem with programming 2nd button. This is the code for PLAY AUDIO button:
% --- 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 playList FiletoPlay fileCounter
if fileCounter < 21 %total number of audio files
FiletoPlay = playList{1, fileCounter}; %select 1st wav file from playList
[FiletoPlay, Fs]=wavread(FiletoPlay); %Import and play file
handles.audio = audioplayer(FiletoPlay,Fs);
play(handles.audio);
end
if fileCounter == 21
msgbox('Test is finished. Thank you for your participation!');
end
fileCounter = fileCounter + 1;
guidata(hObject,handles);
This is the code for REPEAT AUDIO button, here I used counter, but it valid only for 1 audio file (after listening to the 1st audio, user able to repeat it max 3 times):
global times_pushed
times_pushed = times_pushed + 1;
play(handles.audio);
if times_pushed == 4
errordlg('Warning: You exceeded number of repetitions.');
end
guidata(hObject,handles);
So, the question is, how to make the limitation on repeating for 20 audio files ??? Thank you in advance!!

採用された回答

David Sanchez
David Sanchez 2013 年 6 月 18 日
In your PLAYAUDIO function, add times_pushed as global:
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 playList FiletoPlay fileCounter times_pushed
....
....
And reset it for each new audio file
times_pushed = 0;
Keep the code if it works
  1 件のコメント
Lucky
Lucky 2013 年 6 月 18 日
Thank you so much, it works!!

サインインしてコメントする。

その他の回答 (1 件)

David Sanchez
David Sanchez 2013 年 6 月 18 日
Try to reset times_pushed with every new wav file. Insert times_pushed as global in the PLAY AUDIO function.
  1 件のコメント
Lucky
Lucky 2013 年 6 月 18 日
Sorry, how to do this? I inserted times_pushed to global list, but which code to write within the function?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAudio and Video Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by