Audioplayer object not passed into callback function
Afficher commentaires plus anciens
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?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Audio and Video Data dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!