You are defining your audioplayer in the workspace of your callback function. As soon as that function returns, the audioplayer is deleted (along with all other variables in the workspace of the function.)
- You can play the whole sound before returning by switching to playblocking() instead of play(); OR
- You can add some code in the callback that arranges so that it does not return before the sound is finished, such as by adding pause() or appropriate waitfor(); OR
- You can store a reference to the audioplayer outside the workspace so that it does not get deleted when the function returns; see http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.3F; OR
- You can create the audioplayer before-hand and store it in an accessible location using the techniques in the above link, and then have your callback just play() it
