03.07.2014, 01:13
hi all...
how to repeat PlayAudioStreamForPlayer automatically?
how to repeat PlayAudioStreamForPlayer automatically?
forward MusicTimer(playerid);
public MusicTimer(playerid)
{
//code to play music
return 1;
}
It isn't possible to perfectly time it because clients with slower Internet connections load the initial stream more slowly.
|
enum SongEnum
{
LongSong,
Seconds,
UrlSong[128],
};
new SongInfo[MAX_PLAYERS][SongEnum];
stock StopMusicEx(playerid)
{
SongInfo[playerid][LongSong] = -1;
StopAudioStreamForPlayer(playerid);
return 0;
}
stock PlayMusicEx(playerid, str[], longsong)
{
strmid(SongInfo[playerid][UrlSong], str, 0, 128, 128);
PlayAudioStreamForPlayer(playerid, SongInfo[playerid][UrlSong]);
SongInfo[playerid][Seconds] = longsong;
SongInfo[playerid][LongSong] = gettime()+SongInfo[playerid][Seconds];
return 1;
}
forward RepeatSong(); public RepeatSong()
{
for(new x = 0; x < MAX_PLAYERS; x++)
{
if(IsPlayerConnected(x))
{
if(SongInfo[x][LongSong] > 0)
{
if(SongInfo[x][LongSong] < gettime())
{
SongInfo[x][LongSong] = gettime()+SongInfo[x][Seconds];
PlayMusicEx(x, SongInfo[x][UrlSong], SongInfo[x][LongSong]);
}
}
}
}
return 1;
}
public OnGameModeInit()
{
SetTimer("RepeatSong", 1000, true);
return 1;
}
/* Example
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/playsound", cmdtext, true, 10) == 0)
{
PlayMusicEx(playerid, "Url", Duration of the song);
return 1;
}
return 0;
}
*/