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!