[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
#2

Oh God, Good job !
Reply
#3

And this is supposed to be a tutorial?
Reply
#4

Quote:
Originally Posted by alpha500delta
View Post
And this is supposed to be a tutorial?
Well for one thing I show how to add it, then I explain what each line does.
Reply
#5

I did everything but i cant hear anything
It shows "Connected to [Name of the Radio station goes here]".
Reply
#6

Nice tut but i don't understand something...
Euhm, what do you mean with 'A Shoutcast server' ? It's like a radio on internet ? :S
Reply
#7

One day, SA-MP will be just like Ventrilo, I have big feelings about it.
Reply
#8

Ironboy - PM me how you put in the code and I will see what is wrong and if there is nothing wrong with the code then it could either be that you didn't install the audio client plugin or that you might have a slow connection.

Michael@Belgium - Yeah like a shoutcast radio station.

Pz - you have a very good point .
Reply
#9

help 15 error:S
Reply
#10

Quote:
Originally Posted by Csaba1996
View Post
help 15 error:S
paste the line, preferably with [pawn] tags
Reply
#11

At the "Code Part" you say this
pawn Code:
// Transfer the audio pack when the player connects
Audio_TransferPack(playerid);
But this is missing from "Explaination". Is it really needed? Because what your code do is just to play the IP you placed at /startradio and not something that is from server at audio.ini
Reply
#12

I just included that since if you have something in audio.ini that it would transfer the pack as well. In all honesty it has nothing to do with this at all but its just there so players won\'t end up screwing up something they set up in audio.ini
Reply
#13

D:\Documents and Settings\Csaba\Asztal\pawno\include\audio.inc(72) : warning 235: public function lacks forward declaration (symbol "OnFilterScriptInit")

D:\Documents and Settings\Csaba\Asztal\pawno\include\audio.inc(77) : error 017: undefined symbol "funcidx"

D:\Documents and Settings\Csaba\Asztal\pawno\include\audio.inc(7 : error 017: undefined symbol "funcidx"

D:\Documents and Settings\Csaba\Asztal\pawno\include\audio.inc(79) : error 017: undefined symbol "GetServerVarAsInt"

D:\Documents and Settings\Csaba\Asztal\pawno\include\audio.inc(81) : error 017: undefined symbol "funcidx"

D:\Documents and Settings\Csaba\Asztal\pawno\include\audio.inc(83) : error 017: undefined symbol "CallLocalFunction"

D:\Documents and Settings\Csaba\Asztal\pawno\include\audio.inc(99) : warning 235: public function lacks forward declaration (symbol "OnGameModeInit")

D:\Documents and Settings\Csaba\Asztal\pawno\include\audio.inc(104) : error 017: undefined symbol "funcidx"

D:\Documents and Settings\Csaba\Asztal\pawno\include\audio.inc(105) : error 017: undefined symbol "funcidx"

D:\Documents and Settings\Csaba\Asztal\pawno\include\audio.inc(106) : error 017: undefined symbol "GetServerVarAsInt"

D:\Documents and Settings\Csaba\Asztal\pawno\include\audio.inc(10 : error 017: undefined symbol "funcidx"

D:\Documents and Settings\Csaba\Asztal\pawno\include\audio.inc(110) : error 017: undefined symbol "CallLocalFunction"

D:\Documents and Settings\Csaba\Asztal\pawno\include\audio.inc(126) : warning 235: public function lacks forward declaration (symbol "OnPlayerConnect")

D:\Documents and Settings\Csaba\Asztal\pawno\include\audio.inc(12 : error 017: undefined symbol "IsPlayerNPC"

D:\Documents and Settings\Csaba\Asztal\pawno\include\audio.inc(132) : error 017: undefined symbol "MAX_PLAYER_NAME"

D:\Documents and Settings\Csaba\Asztal\pawno\include\audio.inc(132) : error 009: invalid array size (negative, zero or out of bounds)

D:\Documents and Settings\Csaba\Asztal\pawno\include\audio.inc(132) : warning 217: loose indentation

D:\Documents and Settings\Csaba\Asztal\pawno\include\audio.inc(132) : error 036: empty statement

D:\Documents and Settings\Csaba\Asztal\pawno\include\audio.inc(132) : fatal error 107: too many error messages on one line


Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase



15 Errors.
Reply
#14

do you have the newest 0.3c server includes?
Reply
#15

Aint got no audio.inc folder...
Reply
#16

Hey i get and error with the filterscript when the server loads is says that it unable to load audio.amx so i opened the file with pawno and saved as an amx and when i load the server it crashes, what shall i do to get this working?
Reply
#17

Updated to more current standards.
Reply
#18

You could use a variable to check if the player is already listening to the radio or not and display a message accordingly. Otherwise someone could easily abuse the radio command by sending too many requests to the ShoutCast server.

pawn Code:
new Radio[MAX_PLAYERS];

CMD:radio(playerid, params[])
{
    if(Radio[playerid] == 1) return SendClientMessage(playerid, -1, "You are already listening to the radio.");
    PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls");
    SendClientMessage(playerid, -1, "You are now listening to the Radio. Use /radiooff to turn off the radio.");
    Radio[playerid] = 1;
    return 1;
}

CMD:radiooff(playerid, params[])
{
    if(Radio[playerid] == 0) return SendClientMessage(playerid, -1, "You did not turn on the radio.");
    StopAudioStreamForPlayer(playerid);
    SendClientMessage(playerid, -1, "Radio turned off! Use /radio to turn on the radio.");
    Radio[playerid] = 0;
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)