Playing random audio from pushbutton

I want to play using gui some .wav files randomly from a certain directory without any repeatition. can anyone help me in this regard?

답변 (1개)

Walter Roberson
Walter Roberson 2015년 12월 3일

0 개 추천

projectdir = '/Users/Snorky/music';
dirinfo = dir( fullfile(projectdir, '*.wav') );
numfiles = length(dirinfo);
order_to_play = randperm(numfiles);
for K = 1 : numfiles
thisfile = fullfile(projectdir, dirinfo(order_to_play(K)).name );
play this file
end

댓글 수: 2

hani ab
hani ab 2015년 12월 3일
do i have to put this code in the callback function? because when i did so, this error came out when i click on the gui button.
Undefined function 'play' for input arguments of type 'char'.
Error in untitled1>play_Callback (line 180) play this file
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in untitled1 (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)untitled1('play_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Walter Roberson
Walter Roberson 2015년 12월 3일
I solved the random order part for you. You need to figure out how to play the file. There are multiple ways described in the MATLAB documentation.

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

카테고리

태그

질문:

2015년 12월 3일

댓글:

2015년 12월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by