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

3 ビュー (過去 30 日間)
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.
  2 件のコメント
Walter Roberson
Walter Roberson 2020 年 11 月 10 日
Which sound player are you using? Some of them have built-in timer properties.
Temirkhan Amanzhanov
Temirkhan Amanzhanov 2020 年 11 月 10 日
I use an 'audioplayer(fs,y)'.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2020 年 11 月 10 日
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 件のコメント
Walter Roberson
Walter Roberson 2020 年 11 月 10 日
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.
Temirkhan Amanzhanov
Temirkhan Amanzhanov 2020 年 11 月 10 日
Thanks a lot, sir Roberson :) I can finally set it up correctly.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeJust for fun についてさらに検索

製品


リリース

R2012b

Community Treasure Hunt

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

Start Hunting!

Translated by