How to make updating music-scroller and timer-string while is playing music in matlab R2012?
3 ビュー (過去 30 日間)
古いコメントを表示
Temirkhan Amanzhanov
2020 年 11 月 10 日
コメント済み: Temirkhan Amanzhanov
2020 年 11 月 10 日
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
2020 年 11 月 10 日
Which sound player are you using? Some of them have built-in timer properties.
採用された回答
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
2020 年 11 月 10 日
Using global variables and using "app" is not recommended for GUIDE. "app" is for App Designer.
See
http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
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.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!