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?

 채택된 답변

Walter Roberson
Walter Roberson 2016년 11월 7일

0 개 추천

The correct way is to delete the audioplayer and create a new one whose samples start with the appropriate sample.

댓글 수: 5

Ryan Sinfield
Ryan Sinfield 2016년 11월 7일
Ok - is there a way to get the audio data from the audioplayer object. Similar to using getaudiodata() from an audiorecorder?
player_struct = struct(YourAudioPlayerObject);
player_struct.AudioData
Though I just realized another way:
You can
stop(YourAudioPlayerObject)
play(YourAUdioPlayerObject, NewStartingSampleNumber)
Ryan Sinfield
Ryan Sinfield 2016년 11월 8일
Cool I'll give that a try a little later on. Thanks!
Ryan Sinfield
Ryan Sinfield 2016년 11월 9일
That works great, thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Image Filtering and Enhancement에 대해 자세히 알아보기

태그

질문:

2016년 11월 7일

댓글:

2018년 3월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by