# Math Help - Help with my MATLAB DJ program?

1. ## Help with my MATLAB DJ program?

I am making a MATLAB DJ program in which I can load in a song, have it display on a listbox, stop, pause, and play it, as well as determine it's BPM. I am trying to use audioplayer for my push buttons (stop, play, etc.) but for some reason, it is not working properly. I used GUIDE to make my GUI, but I will show my m.file

function varargout = MatlabMedia(varargin)
% MATLABMEDIA M-file for MatlabMedia.fig
% MATLABMEDIA, by itself, creates a new MATLABMEDIA or raises the existing
% singleton*.
%
% H = MATLABMEDIA returns the handle to a new MATLABMEDIA or the handle to
% the existing singleton*.
%
% MATLABMEDIA('CALLBACK',hObject,eventData,handles,. ..) calls the local
% function named CALLBACK in MATLABMEDIA.M with the given input arguments.
%
% MATLABMEDIA('Property','Value',...) creates a new MATLABMEDIA or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before MatlabMedia_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to MatlabMedia_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%

% Edit the above text to modify the response to help MatlabMedia

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @MatlabMedia_OpeningFcn, ...
'gui_OutputFcn', @MatlabMedia_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before MatlabMedia is made visible.
function MatlabMedia_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 MatlabMedia (see VARARGIN)
axis off
% Choose default command line output for MatlabMedia
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes MatlabMedia wait for user response (see UIRESUME)
% uiwait(handles.figure1);
global p
p=audioplayer();

% --- Outputs from this function are returned to the command line.
function varargout = MatlabMedia_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;

% --- Executes on button press in stop.
function stop_Callback(hObject, eventdata, handles)
% hObject handle to stop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clear playsnd

% --- Executes on button press in play.
function play_Callback(hObject, eventdata, handles)
% hObject handle to play (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global p
p=audioplayer(y,f);
play(y)

%wavplay(y,f,'async')

% --- Executes on button press in pause.
function pause_Callback(hObject, eventdata, handles)
% hObject handle to pause (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global p
p=audioplayer(y);
pause(y)

% --- Executes on button press in load.
% hObject handle to load (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global p
[file path] = uigetfile('*.wav*','Select your song')
song=[path file];
%p=audioplayer(file);
%song = fullfile(y,file);
set(handles.list,'String',song);

Whenever I try to run my program, I get these errors

??? Error using ==> audioplayer.audioplayer at 44
Not enough input arguments.

Error in ==> MatlabMedia>MatlabMedia_OpeningFcn at 64
p=audioplayer();

Error in ==> gui_mainfcn at 221
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure),
varargin{:});

Error in ==> MatlabMedia at 42
gui_mainfcn(gui_State, varargin{:});

I could play the wav files using wavplay, but then i cannot use stop and pause features that audioplayer has...

2. I am unfamiliar with the audioplayer function but it looks like it requires at least 2 inputs. You seem to call it with no inputs at one stage?

Create object for playing audio - MATLAB

3. I was trying to set a global variable at the beginning an was told that was how to go about it.

4. Code:
global p
should be all you need although I haven't run your code as it wont work without your fig file.

Generally I try to avoid global variables.
Here is a short tutorial I started trying to put together on making GUI's with matlab. You can place variables inside the handle structure to avoid using globals. It might be something you want to consider, although using globals will work too of course).

http://www.mathhelpforum.com/math-he...-tutorial.html

Elbarto

5. Thanks for the responses. I went to my TA's recitation and he helped me out. I can now load a wav file in, play, pause, and stop it.

I was wondering if anyone has ideas on how to simultaneously play songs?

6. Originally Posted by nottheface
Thanks for the responses. I went to my TA's recitation and he helped me out. I can now load a wav file in, play, pause, and stop it.

I was wondering if anyone has ideas on how to simultaneously play songs?

Just interested: How did you end up stopping it while playing?