Audio player won't work with structure error when running callback
Mostrar comentarios más antiguos
Ok, so I have looked at other problems concerning this error and none of them apply to mine. I am trying to include a simple music player into my program in MATLAB, but every time I try to run it I get the error:
Attempt to reference field of non-structure array.
Error in Beam_Deflection_GUI_3_Music>Play_Music_Call (line 388)
n = get(S.listMusic,'Value');
Error while evaluating uicontrol Callback
I have now figured out that somehow I am turning the S structure into a double, but I do not know how I am doing that, or even how one would go about doing that. If it would help here is the code:
MusicChoice = {'Message in A Bottle','Roxanne'};
S.Pa4 = uipanel('title','Music',...
'FontSize',12,...
'BackgroundColor','white',...
'Units','pixels',...
'Position',[25 80 280 425],...
'Parent',S.fh,...
'fontweight','b',...
'FontAngle','italic',...
'visible','off');
S.listMusic = uicontrol('parent',S.Pa4,...
'style','popupmenu',...
'String',MusicChoice);
S.Play = uicontrol('parent',S.Pa4,...
'style','push',...
'string','Play',...
'units','pix',...
'pos',[100 100 20 20],...
'callback',@Play_Music_Call);
function [] = Play_Music_Call(varargin)
S = varargin{1};
n = get(S.listMusic,'Value');
MusicChoice = {'Message in A Bottle','Roxanne'};
mChoice = MusicChoice(n,1);
[y, Fs, nbits] = wavread(mChoice);
S.player = audioplayer(y, Fs, nbits);
play(S.player)
end
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre App Building en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!