MATLAB: How to make the slider move while the audio file is playing

MATLABslidr

How to make the slider move while the audio file is playing, I'm using audioplayer()?
thank you in advance.
Slider_value=get(hObject,'Value');
% to get the slider value
Slider_value
% to move the slider
global sound_to_play1;
c=get(sound_to_play1,'CurrentSample');
t=get(sound_to_play1,'TotalSamples');
c
t;
h=guidata(sound_to_play1);
set(h.slider1,'Value',c/t);

Best Answer

I would suggest
slider_handle = uicontrol('Style','slider', 'Min', 0, 'Max', player.TotalSamples, 'Value', 0);
set(player,'TimerFcn', {@ejecutar, slider_handle})
function ejecutar(player, ~, slider_handle)
c = get(player, 'CurrentSample');
set(slider_handle, 'Value', c)
end