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

3 views (last 30 days)
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.

Accepted Answer

Walter Roberson
Walter Roberson on 10 Nov 2020
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
  6 Comments
Walter Roberson
Walter Roberson on 10 Nov 2020
Using global variables and using "app" is not recommended for GUIDE. "app" is for App Designer.
See
Also I suggest
player.TimerFcn = @(hObject, event) ScrollTo(ax, hObject)
with
function ScrollTo(ax, hObject)
handles = guidata(ax);
SampleTime = hObject.CurrentSample./hObject.SampleRate;
set(ax, 'XLim', SampleTime + [0 5]);
handles.audioslider.Value = SampleTime;
drawnow()
and remove the lines
while (isplaying(player) == true)
CurrSam = get(player, 'CurrentSample');
set(handles.audioslider, 'Value', CurrSam);
drawnow()
end
as those are better done by the ScrollTo
Ah, though you should decide whether you want the audioslider to be by sample number or by seconds.

Sign in to comment.

More Answers (0)

Categories

Find more on Just for fun in Help Center and File Exchange

Products


Release

R2012b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!