@srk_97 | ||
little curious to know...what logic is used to play songs when the shuffle is kept on in a media player? |
||
11
Replies
928
Views
0 Favourites
|
Page #: 1/2 |
@edit.or | 17 August 11 | |
random logic. i never actually programmed it but i'd say the program first gets the total number of the songs,say 6043. then it setups the random function to pick one number from 1 to total songs number. the random function isn't actually random but is using current time for the seed and scence time changes offten,it is more random that way. now there are players that simply pick a random number
|
||
@edit.or | 17 August 11 | |
without any rules,completely random. as a result,same number maybe picked twice or more and same song could be played multiple times. i find this extremely annoying as i usually can't get to the good songs in my player and those that i'm tired of keep repeating. with each song played,chances for repeat are higher cause there is less and less numbers that we haven't picked yet and the program still
|
||
@edit.or | 17 August 11 | |
still picks using the entire range. a little more sofisticated way but still primitive would be to create a new integer variable array playcount and allocate size according to total songs,all places initialised to zero.then each time a song is played,playcount with the song index number place in array would get a value one. a random program would on each selection search this variable on song inde
|
||
@edit.or | 17 August 11 | |
on song index to see if it was played,if it was played,it could repeat the random number select.
|
||
@edit.or | 17 August 11 | |
but this would not work in practice of course as the more and more songs are played,it would be hard to find the actual non played numbers when randomly picking and user would experience an unpleasent loop,probably hanging the player for indefinite time unless a song is manualy chosen. a better way is that when the random selection fails due to playcount set to 1 for specific song selected,the
|
||
@edit.or | 17 August 11 | |
the random index would be increased by 1 on every failiure,a more brute force aproach that would minimise the wait time. depending on the hardware and the number of songs,this may not be that noticable. but the best way would probably be making two arrays,one for played songs and one for yet none played,then use the non played array index to choose music and determine the played songs by play
|
||
@edit.or | 17 August 11 | |
by their playcount value or better,moving their index to the played array so they don't get selected through shuffle untill there is no more indexes left in none played array,meaning all songs are played once,than it resets the play count. while not shuffling,this system will be avoided and the song you pick will play regardless whether its played before
|
||
@edit.or | 17 August 11 | |
so the naive beta code would be logicaly like this: get total number of songs,store it in a variable totalsongs. make two array integers,played and..unplayed with the total index equal to totalsongs int. write song indexes to nonplayed. set random to choose from 1 to total songs pick from nonplayed. play it. defined time before the song end,which could be stored in variable as user preference,
|
||
@edit.or | 17 August 11 | |
swap? the value of just played song in array played to the highest index of array and move the highest index to the place of just played song. this is pretty easy to do and i think i just realised the nonplayed array is not even required to be made with this system. decrease rand max value by one,so not to pick the top song. choose a random index again. play the song. no delays and playcount is
|
||
@edit.or | 17 August 11 | |
determined accuretly,very simple and fast code but unfortunantly,i can't write the source here,no equal sine support,no newline,lack of most characters lol but i think you get the picture
|
||