您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 项目/工程管理 > matlab-mp3播放器源代码
functionvarargout=MP3player(varargin)%MP3playerMATLABcodeforMP3player.fig%MP3player,byitself,createsanewMP3playerorraisestheexisting%singleton*.%%H=MP3playerreturnsthehandletoanewMP3playerorthehandleto%theexistingsingleton*.%%MP3player('CALLBACK',hObject,eventData,handles,...)callsthelocal%functionnamedCALLBACKinMP3player.Mwiththegiveninputarguments.%%MP3player('Property','Value',...)createsanewMP3playerorraisesthe%existingsingleton*.Startingfromtheleft,propertyvaluepairsare%appliedtotheGUIbeforeMP3player_OpeningFcngetscalled.An%unrecognizedpropertynameorinvalidvaluemakespropertyapplication%stop.AllinputsarepassedtoMP3player_OpeningFcnviavarargin.%%*SeeGUIOptionsonGUIDE'sToolsmenu.ChooseGUIallowsonlyone%instancetorun(singleton).%%Seealso:GUIDE,GUIDATA,GUIHANDLES%EdittheabovetexttomodifytheresponsetohelpMP3player%LastModifiedbyGUIDEv2.501-Nov-201421:41:05%Begininitializationcode-DONOTEDITgui_Singleton=1;gui_State=struct('gui_Name',mfilename,...'gui_Singleton',gui_Singleton,...'gui_OpeningFcn',@MP3player_OpeningFcn,...'gui_OutputFcn',@MP3player_OutputFcn,...'gui_LayoutFcn',[],...'gui_Callback',[]);ifnargin&&ischar(varargin{1})gui_State.gui_Callback=str2func(varargin{1});endifnargout[varargout{1:nargout}]=gui_mainfcn(gui_State,varargin{:});elsegui_mainfcn(gui_State,varargin{:});end%Endinitializationcode-DONOTEDIT%---ExecutesjustbeforeMP3playerismadevisible.functionMP3player_OpeningFcn(hObject,eventdata,handles,varargin)%Thisfunctionhasnooutputargs,seeOutputFcn.%hObjecthandletofigure%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%varargincommandlineargumentstoMP3player(seeVARARGIN)%ChoosedefaultcommandlineoutputforMP3playerhandles.output=hObject;%Updatehandlesstructureguidata(hObject,handles);%UIWAITmakesMP3playerwaitforuserresponse(seeUIRESUME)%uiwait(handles.figure1);%---Outputsfromthisfunctionarereturnedtothecommandline.functionvarargout=MP3player_OutputFcn(hObject,eventdata,handles)%varargoutcellarrayforreturningoutputargs(seeVARARGOUT);%hObjecthandletofigure%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Getdefaultcommandlineoutputfromhandlesstructurevarargout{1}=handles.output;functionPath_Callback(hObject,eventdata,handles)%hObjecthandletoPath(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hints:get(hObject,'String')returnscontentsofPathastext%str2double(get(hObject,'String'))returnscontentsofPathasadouble%---Executesduringobjectcreation,aftersettingallproperties.functionPath_CreateFcn(hObject,eventdata,handles)%hObjecthandletoPath(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled%Hint:editcontrolsusuallyhaveawhitebackgroundonWindows.%SeeISPCandCOMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');end%---Executesonbuttonpressinbrowse.functionbrowse_Callback(hObject,eventdata,handles)globalaudioYFS[FileName,FilePath]=uigetfile('*.MP3','SelecttheM-File');PathName=sprintf('%s\%s',FilePath,FileName);set(handles.Path,'string',PathName);mp3PathName=get(handles.Path,'string');[Y,FS]=audioread(mp3PathName);audio=audioplayer(Y,FS);%hObjecthandletobrowse(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%---Executesonbuttonpressinplay.functionplay_Callback(~,eventdata,handles)globalaudioFSYaxes(handles.axes1);holdon;plot(Y,'b');%plotaudiodatatitle('AudioData');xlabel(strcat('SampleNumber(fs=',num2str(FS),')'));ylabel('Amplitude');ylimits=get(gca,'YLim');%getthey-axislimitsplotdata=[ylimits(1):0.1:ylimits(2)];hline=plot(repmat(0,size(plotdata)),plotdata,'r');%plotthemarker%instantiatetheaudioplayerobjectaudio=audioplayer(Y,FS);%setupthetimerfortheaudioplayerobjectaudio.TimerFcn={@plotMarker,audio,gcf,plotdata};%timercallbackfunction(definedbelow)audio.TimerPeriod=0.01;%periodofthetimerinseconds%startplayingtheaudio%thiswillmovethemarkerovertheaudioplotatintervalsof0.01splay(audio);%play(audio);%axes(handles.axes1);%plot(Y,'b');%plotaudiodata%title('AudioData');%xlabel(strcat('SampleNumber(fs=',num2str(Fs),')'));%ylabel('Amplitude');%hObjecthandletoplay(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%---Executesduringobjectcreation,aftersettingallproperties.functionaxes1_CreateFcn(hObject,eventdata,handles)%hObjecthandletoaxes1(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled%Hint:placecodeinOpeningFcntopopulateaxes1%---Executesonbuttonpressinpause.functionpause_Callback(hObject,eventdata,handles)globalaudiopause(audio);%hObjecthandletopause(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%---Executesonbuttonpressinstop.f
本文标题:matlab-mp3播放器源代码
链接地址:https://www.777doc.com/doc-6932617 .html