www.gusucode.com > matlab GUI界面的播放器,用matlab环境控制播放、暂停、停止和回放源码程序 > code/testplay.m
function varargout = testplay(varargin) % TESTPLAY M-file for testplay.fig % TESTPLAY, by itself, creates a new TESTPLAY or raises the existing % singleton*. % % H = TESTPLAY returns the handle to a new TESTPLAY or the handle to % the existing singleton*. % % TESTPLAY('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in TESTPLAY.M with the given input arguments. % % TESTPLAY('Property','Value',...) creates a new TESTPLAY or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before testplay_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to testplay_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help testplay % Last Modified by GUIDE v2.5 31-Jan-2010 17:36:17 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @testplay_OpeningFcn, ... 'gui_OutputFcn', @testplay_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 testplay is made visible. function testplay_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 testplay (see VARARGIN) % Choose default command line output for testplay handles.output = hObject; handles.status=0; handles.stat=0; % Update handles structure guidata(hObject, handles); % UIWAIT makes testplay wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = testplay_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 pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global file_name; if(~ischar(file_name)) errordlg('Please Open a .Wav File'); else if handles.status==0 handles.status=1; [x,Fs]=wavread(file_name); handles.r=audioplayer(x,Fs); play(handles.r); else warndlg({'Warning: Play Is Already In Progress.';' To Begin A New Play You Must First Stop The Current Session.'}) end end guidata(hObject,handles); % --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) if handles.status==1 handles.status=0; stop(handles.r); else errordlg('Warning: To Stop, Play Must Be In Progress.') end guidata(hObject,handles); % --- Executes during object creation, after setting all properties. function axes1_CreateFcn(hObject, eventdata, handles) % hObject handle to axes1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: place code in OpeningFcn to populate axes1 axes(hObject) imshow('flow.jpg'); % --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global file_name; file_name=uigetfile('*.wav','Select the Wave File'); % --- Executes on button press in pushbutton4. function pushbutton4_Callback(hObject, eventdata, handles) % hObject handle to pushbutton4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) if (handles.status==1)&&(handles.stat==0) pause(handles.r); handles.stat=1; else if handles.stat==1 errordlg('Play Is Already Paused') else errordlg('Warning: Play Must Be In Progress To Pause') end end guidata(hObject,handles); % --- Executes on button press in pushbutton5. function pushbutton5_Callback(hObject, eventdata, handles) % hObject handle to pushbutton5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) if (handles.status==1)&&(handles.stat==1) resume(handles.r); handles.stat=0; else errordlg('Warning: Play Must Be Paused To Resume.') end guidata(hObject,handles); % --- Executes during object creation, after setting all properties. function figure1_CreateFcn(hObject, eventdata, handles) % hObject handle to figure1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes when user attempts to close figure1. function figure1_CloseRequestFcn(hObject, eventdata, handles) % hObject handle to figure1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: delete(hObject) closes the figure clear global; delete(hObject);