I'm trying to create Random Music Player and could use help!
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ian Mason
le 24 Mar 2019
Modifié(e) : Ian Mason
le 28 Mar 2019
TLDR: I stream music in my dorm room 24/7 and the stations I listen to loop every 19 hours and 41 minutes, and it gets old. So I want to make a random music player with matlab.
I am using the randi function to generate a random number so that it chooses one. Now, I need it to realize that is the name of a song, grab it, and then play it.
Here is the code I have so far! Any help would be greatly appreicated as I am a beginer. (I know that I only have 12 songs so far, this is just a proof of concept for now).
r = randi(12);
%use the random number generated to select a song (all named 1.m4a or
%12.m4a or whatever)
%plug the song into the folling code that plays the song
[a, Fs] = audioread('__________.m4a');
plot(a(:,1))
p = audioplayer(a,Fs);
play(p)
%repeat process. I will eventually turn this into a fucntion that can
%smartly choose between playing another song or letting us hear from a DJ
%in the Fallout Video games, but right now I just want to get the random
%generation perfected.
0 commentaires
Réponse acceptée
Kodavati Mahendra
le 24 Mar 2019
Modifié(e) : Kodavati Mahendra
le 24 Mar 2019
% clear all; close all; clc
MusicList = dir('*.m4a');
while(1)
r = randi(length(MusicList),1,1)
[a, Fs] = audioread(MusicList(r).name);
plot(a(:,1))
p = audioplayer(a,Fs);
play(p);
pause(length(a)/Fs);
end
I am not sure if I understand your question completely. Does this help?
This gets the list of .m4a files in the current directory and plays them randomly indefinitely.
6 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Audio and Video Data 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!