MATLAB: How to make updating music-scroller and timer-string while is playing music in matlab R2012

guideMATLABolddocs

Hi everyone. I wanna make it by using timer function. I dunno what I need to set up into 'timer' function as 'TimerFcn', 'StartTimerFcn' etc. And also the function 'drawnow' doesn't make any sence. Thanks for your responds.

Best Answer

audioplayer has a TimerFcn property, and a TimerPeriod property to set the interval. For example,
t = (0:size(y,1)-1)./Fs;
ax = gca;
plot(ax, t, y);
xlim([0 5]);
obj = audioplayer(y, Fs);
obj.TimerFcn = @(hObject, event) ScrollTo(ax, hObject.CurrentSample./hObject.SampleRate);
obj.TimerPeriod = 0.5;
play(obj)
function ScrollTo(ax, SampleTime)
set(ax, 'XLim', SampleTime + [0 5]);
drawnow()
end