SA-MP Forums Archive
Possible to Loop "AudioStreamForPlayer" ? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Possible to Loop "AudioStreamForPlayer" ? (/showthread.php?tid=385930)



Possible to Loop "AudioStreamForPlayer" ? - denNorske - 18.10.2012

Hi all!

I am currently making a "playlist" in my GameMode, and i was wondering if it was possible to loop the songs you are playing?

i am using "AudioStreamForPlayer" to play music, and yes, i am using 0.3d.

So, what i am asking, is it possible, and what type of coding does it require?
'I could maybe get a few examples to learn from

And yes, i used the "Search button" Alot.


Re: Possible to Loop "AudioStreamForPlayer" ? - Roel - 18.10.2012

pawn Code:
// top of script
new RandomMusic[][] =
{
    "URL1",
    "URL2",
    "URL3"
};
// ongamemodeinit
SetTimer("SwitchNewSound", 60000*3, true); // 3 minutes
// somewhere in your script
forward SwitchNewSound();
public SwitchNewSound()
{
    new randURL = random(sizeof(RandomMusic));
    for(new playerid = 0; playerid < MAX_PLAYERS; playerid++)
    {
        if(IsPlayerConnected(playerid))
        {
            StopAudioStreamForPlayer(playerid);
            PlayAudioStreamForPlayer(playerid, RandomMusic[randURL]);
        }
    }
    return 1;
}
I set the timer to 3 minutes, but if you wan't to start a new sound only if the old sound is done, I have no idea


Re: Possible to Loop "AudioStreamForPlayer" ? - denNorske - 18.10.2012

Hmm, okay, that should possibly work for me.

Thanks for your help!
Uhm, one thing, how do i prevent playing the same song again, as it is "random" ?

if i add:
Code:
new Randommusic [][] =
{
	"Metallica"
	"Ramstein"
	"Spicegirls"
};
How can i be able to play metallica, and then prevent the next song to be metallica again?

Only an example though ^^


Re: Possible to Loop "AudioStreamForPlayer" ? - Roel - 18.10.2012

in that case replace it with this:
pawn Code:
// top of script
new MusicURLs[][] =
{
    "URL1",
    "URL2",
    "URL3"
};
new URLNumber;
// ongamemodeinit
SetTimer("SwitchNewSound", 60000*3, true); // 3 minutes
// somewhere in your script
forward SwitchNewSound();
public SwitchNewSound()
{
    for(new playerid = 0; playerid < MAX_PLAYERS; playerid++)
    {
        if(IsPlayerConnected(playerid))
        {
            StopAudioStreamForPlayer(playerid);
            PlayAudioStreamForPlayer(playerid, MusicURLs[URLNumber]);
            URLNumber++;
            if(URLNumber == sizeof(MusicURLs)) URLNumber = 0;
        }
    }
    return 1;
}



Re: Possible to Loop "AudioStreamForPlayer" ? - denNorske - 18.10.2012

Quote:
Originally Posted by ******
View Post
You just need to save what the last song was somewhere - the simplest way may just be to pass that as a parameter in your timer. I'd also recommend storing the exact song lengths in seconds in your array and using that as the timer time (maybe +2 seconds or so to account for gaps between tracks and lag starting the songs).
Okay, thanks ******, i will try that too.

@Roel:

Code:
if(URLNumber == sizeof(MusicURLs)) URLNumber = 0;
What does that line do? i didn't understand it 100%


Re: Possible to Loop "AudioStreamForPlayer" ? - Roel - 18.10.2012

it check if you played all sounds, if you did it resets the URLnumber to 0 so it will play the first song again.
This scirpt will just loop all the URL's inside the MusicURLs after each other.