Change CurrentSample in audioplayer

5 vues (au cours des 30 derniers jours)
Ryan Sinfield
Ryan Sinfield le 7 Nov 2016
Commenté : Walter Roberson le 15 Mar 2018
I want to be able to allow a user to select a point in a track and begin playing, so I have a ButtonDownFcn set on an axes to take the coordinates clicked and convert this to a sample number to resume playing a plotted audio clip.
% Get the x coordinate
c = get(hObject, 'CurrentPoint');
x = c(1,1);
% Multiply this by the sample rate (x axis represents seconds)
% to get the sample at which the track should resume
smpl = x * get(player, 'SampleRate');
set(player, 'CurrentSample', smpl);
The issue I'm having is that I then get an error message that says Error using audioplayer/set You cannot set the read-only property 'CurrentSample' of audioplayer.
So obviously this isn't the correct way to skip to a new point in a track. What is the correct way to do this?

Réponse acceptée

Walter Roberson
Walter Roberson le 7 Nov 2016
The correct way is to delete the audioplayer and create a new one whose samples start with the appropriate sample.
  5 commentaires
Ryan Sinfield
Ryan Sinfield le 9 Nov 2016
That works great, thanks

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Image Filtering and Enhancement dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by