How can I stop the graph , and how can it stip when the song stops?

1 次查看(过去 30 天)
function MusicPlay(InfoSongName)
PlayPlaySong = InfoSongName +".mp3";
[VariableSong, Variable] = audioread(PlayPlaySong);
Song = audioplayer(VariableSong, Variable);
PlaySong = input(' Will you like to play the song Yes or No ','s');
while strcmpi(PlaySong, 'Yes') ~= 1 && strcmpi(PlaySong, 'No') ~=1
fprintf(' Selected Yes or No!!! \n')
PlaySong = input(' Will you like to play the song Yes or No ','s');
end
%%
if strcmpi(PlaySong, "Yes")
% NewVariable = audioread(PlayPlaySong);
% plot(NewVariable)
% soundsc(VariableSong, Variable);
filename = PlayPlaySong;
[Y,Fs] = audioread(filename);
TotalTime = length(Y) ./Fs;
t = 0:TotalTime/(length(Y)):TotalTime-TotalTime/length(Y);
sound(Y,Fs)
Y = Y';
var = 50000;
figure
a = 1;
for i = var:1000:length(Y(1, :))
subplot(2,1,1);
plot(t(a:i), Y(1,a:i));
title("Left")
subplot(2,1,2);
plot(t(a:i), Y(2,a:i));
title("Right")
a = i;
% fprintf("%f \n",a);
pause(.75);
end
StopSong = input(' Would you like to stop the song? (Type Yes to stop or anything else to continue) ','s');
while isempty(StopSong) || strcmpi(StopSong, 'Yes') ~= 1
pause(12)
StopSong = input(' Would you like to stop the song? (Type Yes to stop or anything else to continue) ','s');
end
if strcmpi(StopSong ,'Yes')
clear sound
end
elseif strcmpi(PlaySong, "No")
fprintf("\t \n");
fprintf('\t\t "Thank you for using MusicLive". \n');
fprintf('\t \n');
end
% It plays the song and the plots the grpah but it will not stop the
% plotting (graph) when the song ends.
% Also the following code is not printing in the command window!
%{
StopSong = input(' Would you like to stop the song? (Type Yes to stop or anything else to continue) ','s');
while isempty(StopSong) || strcmpi(StopSong, 'Yes') ~= 1
pause(12)
StopSong = input(' Would you like to stop the song? (Type Yes to stop or anything else to continue) ','s');
end
if strcmpi(StopSong ,'Yes')
clear sound
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by