Play music from user input

3 views (last 30 days)
Haley Kelly
Haley Kelly on 17 Nov 2021
Commented: Haley Kelly on 17 Nov 2021
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 Comments
Haley Kelly
Haley Kelly on 17 Nov 2021
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

Sign in to comment.

Answers (1)

KSSV
KSSV on 17 Nov 2021
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 Comment
Haley Kelly
Haley Kelly on 17 Nov 2021
How do i get it to not through the error

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!