Audioplayer object not passed into callback function
显示 更早的评论
I am playing around with audioplayers and wanted to have a simple callback function that would print the time of the audio file when the audio player is played. Here is the script and associated callback function:
clc;clear all;close all
[audio, fs] = audioread("mute.mp3");
player = audioplayer(audio,fs)
player.StartFcn = 'audiocallbacktest'
play(player)
function audiocallbacktest(obj,event)
cur = obj.CurrentSample;
tot = obj.TotalSamples;
fs = obj.SampleRate;
timeTot = tot/fs;
timeCur = cur/fs;
strTot = secToTime(timeTot);
strCur = secToTime(timeCur);
disp("Play from "+strCur+" of "+strTot+".")
disp(secToTime(6531653));
end
The callback function is begin called, in fact as long as I don't try to use the variable obj in the function is works just fine. For example, this:
function audiocallbacktest(obj,event)
disp("Working?")
end
works just fine (displays "working?" to the terminal). Using the debugger to pause during the middle of the callback function revealed that in the audiocallbacktest function environment, there were no saved variables, no handles to the audioplayer object. I haven't seen anyone else with this problem, any ideas?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!