[Tutorial] How to stream Shoutcast to your server
#1

How to Stream Shoutcast to your Server
By Sc0pe
I have heard some players wanted to know how to add Shoutcast streaming to their server so I made this little tutorial.

What Will You Need
  • AT LEAST SA-MP 0.3d (Current version is 0.3e)
  • A Shoutcast Server (Don't fret if you don't have one, you can use just about any internet radio station)
The Code
So here is the code we will be looking at:
pawn Code:
#include <a_samp>
#include <zcmd>

CMD:radio(playerid, params[])
{
    PlayAudioStreamForPlayer(playerid, "http://www.internetradio.com/listen.pls");
    SendClientMessage(playerid, 0x33CCFFAA, "(SERVER) {FFFFFF}Connecting to [NAME OF STATION]");
    return 1;
}
CMD:stopradio(playerid, params[])
{
    StopAudioStreamForPlayer(playerid);
    SendClientMessage(playerid, 0x33CCFFAA, "(SERVER) {FFFFFF}Audio stream playback has been stopped");
    return 1;
}
Explanation
Now I will explain what each little piece of code does.

PlayAudioStreamForPlayer
pawn Code:
PlayAudioStreamForPlayer(playerid, url[], Float:posX = 0.0, Float:posY = 0.0, Float:posZ = 0.0, Float:distance = 50.0, usepos = 0);
This starts the audio stream that is typed in the place of url[].
Stream URLs can look like the following: Below is a proper example of this code:
pawn Code:
PlayAudioStreamForPlayer(playerid, "http://www.internetradio.com/listen.pls");
StopAudioStreamForPlayer
pawn Code:
StopAudioStreamForPlayer(playerid);
This stops the audio stream that was playing (if one was playing).

Command Explanations
/startradio Explanation
pawn Code:
CMD:radio(playerid, params[])
This is the command that we are going to use to start the audio stream.

pawn Code:
PlayAudioStreamForPlayer(playerid, "http://www.internetradio.com/listen.pls");
This is the audio stream which we are going to use as our radio. You need to change the example URL to the URL of the stream to your preferred radio station.

pawn Code:
SendClientMessage(playerid, 0x33CCFFAA, "(SERVER) {FFFFFF}Connecting to [NAME OF STATION]");
This notifies the player that they are connecting to the stream and the audio should start playing shortly. You need to replace [NAME OF STATION with the name of the radio station that you will be using.

/stopradio Explanation
pawn Code:
CMD:stopradio(playerid, params[])
This is the command that we are going to use to stop streaming the radio.

pawn Code:
StopAudioStreamForPlayer(playerid);
This will stop the streaming of audio.

pawn Code:
SendClientMessage(playerid, 0x33CCFFAA, "(SERVER) {FFFFFF}Audio stream playback has been stopped");
This will let the player know that the audio stream has stopped.

Final Notes
NOTE: If you want to make a Shoutcast Server for free, use one of the following:NOTE: For those wondering where they can find zcmd, look no further.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)