필터 지우기
필터 지우기

Play music from user input

조회 수: 5 (최근 30일)
Haley Kelly
Haley Kelly 2021년 11월 17일
댓글: Haley Kelly 2021년 11월 17일
I was just wondering if there was a way i could ask a user for a .mp3 link or somthing similar to their favorite song and have it play... ive been getting a error were it will read the URL i try to answer and say // in the url is 'Invalid use of operator.' Thanks!
This is what I have
song = input('Enter link to you favorite song : ');
fullname = 'song'; %change as required
try
[y, Fs] = audioread(fullname);
PO=audioplayer(y,Fs);
% Play audio
playblocking(PO)
catch ME
uiwait(msgbox('Could not open that file with audioread'));
end
  댓글 수: 2
Benjamin Kraus
Benjamin Kraus 2021년 11월 17일
I'm not sure if this as a typo or not, but song shouldn't be in quotes. It would help to use code formatting tools to format your code.
It would also help if you gave a specific example of the input the user provided that wasn't working. Perhaps if you tried this:
song = input('Enter link to you favorite song : ');
disp(song) % What output does this line provide? A specific example would help others help you.
fullname = song; % song should not be in quotes on this line.
try
[y, Fs] = audioread(fullname);
PO=audioplayer(y,Fs);
% Play audio
playblocking(PO)
catch ME
uiwait(msgbox('Could not open that file with audioread'));
end
What does the display look like?
Haley Kelly
Haley Kelly 2021년 11월 17일
So it still gives me the error on the input which is Invalid use of operator on https://downloads.khinsider.com/game-soundtracks/album/speed-racer-original-game-rip/02%2520Speed%2520Racer%2520Theme.mp3 or any thing that end with .mp3

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

답변 (1개)

KSSV
KSSV 2021년 11월 17일
song = input('Enter link to you favorite song : ','s'); % <---- changed here
fullname = 'song'; %change as required
try
[y, Fs] = audioread(fullname);
PO=audioplayer(y,Fs);
% Play audio
playblocking(PO)
catch ME
uiwait(msgbox('Could not open that file with audioread'));
end
Now you can run your code. But still it will through error at audioread.
  댓글 수: 1
Haley Kelly
Haley Kelly 2021년 11월 17일
How do i get it to not through the error

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

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by