I already asked this question to no avail. I couldn't solve the problem. I am trying again maybe someone can help!
I have 2 buttons, Play and Stop. I would have the path of an audio track at hand and want the audio to play when the user clicks on play and stop when the user clicks on stop. The only problem is that once the callback function of play exits, the variable holding the info about the player is emptied, and hence the track does not play. I needed some method to share data between callback functions..
I tried using global variables to no avail..
then I looked at this and I tried more or less each and every mentioned method: http://www.mathworks.com/help/matlab/creating_guis/share-data-among-callbacks.html#bt9p4qp
Let's take for instance this method:
In the play callback button:
[Y, Fs] = audioread(path);
player = audioplayer(Y,Fs);
hObject.UserData = player;
play(player);
In the stop callback button:
h = findobj('Tag','Play');
player = h.UserData;
stop(player);
On hObject.UserData = player; I am getting this warning when clicking on the play button:
Warning: Struct field assignment overwrites a value with class "double". See MATLAB R14SP2 Release Notes, Assigning Nonstructure Variables As Structures Displays Warning, for details.
The solution I need would let me keep using the rest of the program while the music is playing, stop the audio whenever I want, and the program must obviously keep working well after that.
Any ideas guys? any help would be truly appreciated!
Thanks in advance!