Matlab - PEDIR AL USUARIO MUSICA

 
Vista:
sin imagen de perfil

PEDIR AL USUARIO MUSICA

Publicado por deivy (11 intervenciones) el 24/05/2018 20:04:07
Buen dia, queria preguntar de que manera puedo pedirle al usuario las canciones que quiera ingresar a la guide, es un reproductor mp3.Ademas como hago para que las canciones se pasen por si solas ya que trate de hacerlo con un while pero no se como emplearlo.Y pues mostrar la lista en la ventana de que es lo que esta escuchando de esta manera:
1.cancion tal
2. cancion 2
3. cancion 3
en el comant window me funciona, no se porque en la guide no lo hace me aparece desordenado este es mi codigo:

function ejemplo_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 ejemplo (see VARARGIN)

% Choose default command line output for ejemplo
handles.k=1;%se definio esta variable para pasar las canciones
handles.volumen=1;% se definio esta variable para subir y bajar el volumen
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes ejemplo wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = ejemplo_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
%global n M
%a=dir('*mp3');
%nombres={a.name};%obtener lista automáticamente

%M=rand(nombres)
%n=1;
varargout{1} = handles.output;

% --- Executes on button press in pushbutton2.
%------------------------------------BOTON PARA REPRODUCIR CODIGO-----------------------------
function pushbutton2_Callback(hObject, eventdata, handles)
% -------------------------Lista de canciones--------------------------------------------------------------------

nombre1='Hearts Grow - Yura Yura.mp3';
nombre2='Kalimba.mp3';
nombre3='Sleep Away.mp3';
names=[ nombre1, nombre2, nombre3];

%nname=[];------
%names=[names nname]-----
% Se almacena las direcciones de las canciones dentro de un vector tipo array
% todas quedan concatendas. Aunque no se ve la comilla, es tenida en cuenta

dim=[1
length(nombre1)
length(nombre1)+length(nombre2)
length(nombre1)+length(nombre2)+length(nombre3)];


% Se calcula el tamaño de cada direccion, desde que posicion del vector inicia
% hasta que posicion del vector ocupa. Esto con el fin de utilizar el vector nombre dentro de la funcion audio


% -------------------------Control del reproductor--------------------------------------------------------------------

actual=1; %Cancion actual que se reproduce
%estado=0; %Se inicializa sin reprodcuir ninguna cancion
%pausa=0;
%volumen=5;
%conta=1;
set(handles.togglebutton2,'String','Pausar');
set(handles.togglebutton2,'Value',0);
set(handles.togglebutton3,'String','Parar');
set(handles.togglebutton3,'Value',0);


in_play=names(dim(actual):dim(actual+1));
[y,Fs]=audioread(in_play);

handles.player=audioplayer(y,Fs);
play(handles.player)
guidata(hObject, handles);
i=get(handles.pushbutton2,'Value');
conta=0;

for i=2:length(dim)
vis=names(conta+1:dim(i)-4);%Se resta 4, para que no se visualice el ".mp3"
%sprintf('%i. %s \n',i-1,vis)
%tex=sprintf('%s %s',vis);
set(handles.text2,'String', sprintf('%i. %s \n',names))%en proceso el display

conta=dim(i); %ciclo infinito para tener control continuo del programa
end

set(handles.text3,'String','Lista de canciones: ');
set(handles.text4,'String','Usted esta escuchando: ');
set(handles.text5,'String',in_play)
axes(handles.axes1)
%subplot(2,1,1) % se utiliza el comando subplot para hacer graficos con mas de un sector
%plot(y); % graficanado la señal en el dominio de los samples de tiempo

%subplot(2,1,2)
%a=abs(fft(y)); % calculamos la FFT
%plot(a(1:end)); % graficando la señal en el dominio de los samples de la frecuencia

% 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)


% --- Executes on button press in togglebutton2.
%------------------------------------BOTON PARA PAUSAR Ó CONTINUAR CODIGO-----------------------------
function togglebutton2_Callback(hObject, eventdata, handles)
if get(hObject,'Value')==1

set(hObject,'String','Continuar');
pause(handles.player)
else
set(hObject,'String','Pausar');
resume(handles.player)
end
% hObject handle to togglebutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of togglebutton2


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

% Hint: get(hObject,'Value') returns toggle state of togglebutton3
if get(hObject,'Value')==1
set(hObject,'String','parar');
stop(handles.player)
end


% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1


% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end


% --- 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)



% --- Executes on button press in togglebutton4.
%------------------------------------BOTON PARA ADELANTAR CODIGO-----------------------------
function togglebutton4_Callback(hObject, eventdata, handles)
% hObject handle to togglebutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of togglebutton4
a=dir('*mp3');
nombres={a.name};%obtener lista automáticamente
handles.k=handles.k+1;
if handles.k==4
handles.k=1;
end
in_play=nombres{handles.k};
set(handles.text5,'String',in_play)
[y,Fs]=audioread(in_play);
handles.player=audioplayer(y,Fs);
play(handles.player);
guidata(hObject, handles);
set(handles.text4,'String','Usted esta escuchando: ');
axes(handles.axes1)
%subplot(2,1,2)
%a=abs(fft(y)); % calculamos la FFT
%plot(a(1:end)); % graficando la señal en el dominio de los samples de la frecuencia




% --- Executes on button press in togglebutton5.
%------------------------------------BOTON PARA ATRASAR CODIGO-----------------------------
function togglebutton5_Callback(hObject, eventdata, handles)
% hObject handle to togglebutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of togglebutton5
a=dir('*mp3');
nombres={a.name};%obtener lista automáticamente
handles.k=handles.k-1;
if handles.k==0
handles.k=3;
end
in_play=nombres{handles.k};
set(handles.text5,'String',in_play)
[y,Fs]=audioread(in_play);
handles.player=audioplayer(y,Fs);
play(handles.player);
guidata(hObject, handles);
set(handles.text4,'String','Usted esta escuchando: ');
axes(handles.axes1)
%subplot(2,1,2)
%a=abs(fft(y)); % calculamos la FFT
%plot(a(1:end)); % graficando la señal en el dominio de los samples de la frecuencia

% --- Executes on button press in togglebutton6.
%------------------------------------BOTON PARA REPRODUCIR RAMDON CODIGO-----------------------------
function togglebutton6_Callback(hObject, eventdata, handles)
% hObject handle to togglebutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of togglebutton6
k=dir('*mp3');
nombres={k.name};
n=randi(3,1);
M=nombres{n};
in_play=M;
set(handles.text5,'String',in_play)
[y,Fs]=audioread(in_play);
handles.player=audioplayer(y,Fs);
play(handles.player);
guidata(hObject, handles);
set(handles.text4,'String','Usted esta escuchando: ');


% --- Executes on slider movement.
function slider2_Callback(hObject, eventdata, handles)
% hObject handle to slider2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(handles.text7,'String',num2str(get(hObject,'Value'),'%d%%'))
%get(handles.slider2,'Value');
if get(hObject,'Value')>=1

if(handles.volumen>0) %Se comprueba si el voluemen esta al maximo
handles.volumen=handles.volumen+1;
end
SoundVolume(handles.volumen/10); %La funcion de volumen recibe valores entre 0 y 1
end
if (handles.volumen<10)
handles.volumen=handles.volumen-1;
end
SoundVolume(handles.volumen/10); %La funcion de volumen recibe valores entre 0 y 1




% --- Executes during object creation, after setting all properties.
function slider2_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end

Muchas gracias por todo.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder