PDA

View Full Version : Streaming from MP3 URL with command


KingyKings
07/12/2013, 07:11 PM
Hello,

Instead of using a preset Stream.
How can i make it so anyone can type

/play [URL]

and it streams the URL if its a working Mp3 one?

Im not sure where to start on this so any help would be appreciated

Jstylezzz
07/12/2013, 07:22 PM
This code would do when using ZCMD and sscanf:

CMD:play(playerid,params[])
{
new url[128]; //Create a string variable for the URL
if(sscanf(params,"s[128]",url)) return SendClientMessage(playerid,-1,"Usage: /play <url>"); //If the player didn't type an url, send this message
PlayAudioStreamForPlayer(playerid,url); //Play the audio stream
return 1; //Sending a signal to the server that the command was successfull
}

^ I think that should work.

KingyKings
07/12/2013, 07:32 PM
What about if im not using sscanf and zcmd?

Jstylezzz
07/12/2013, 07:35 PM
I think it would be like this:


CMD:play(playerid,params[])
{
if(isnull(params[0]) return SendClientMessage(playerid,-1,"Usage: /play <url>"); //If the player didn't type an url, send this message
PlayAudioStreamForPlayer(playerid,params[0]); //Play the audio stream
return 1; //Sending a signal to the server that the command was successfull
}


Not sure though, as I've always used sscanf. I recommend you to start using it if you're learning anyways.

KingyKings
07/12/2013, 07:42 PM
Ah okay well i get these errors
2793) : error 017: undefined symbol "isnull"
: error 001: expected token: ")", but found "return"

They are both on this line
if(isnull(params[0]) return SendClientMessage(playerid,-1,"Usage: /play <url>");

Mattakil
07/12/2013, 08:00 PM
CMD:play(playerid,params[])
{
if(isnull(params)) return SendClientMessage(playerid,-1,"Usage: /play <url>"); //If the player didn't type an url, send this message
PlayAudioStreamForPlayer(playerid,params); //Play the audio stream
return 1; //Sending a signal to the server that the command was successfull
}

He was missing a bracket, try that.

KingyKings
07/12/2013, 08:13 PM
Thanks man But it still says Undefined isnull.
I placed this at the top of my script
#if !defined isnull
#define isnull(%1) \
((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif

It compiled but In game /stream does nothing at all :/

Mattakil
07/12/2013, 08:15 PM
what command processor are you using in your script?

Emmet_
07/12/2013, 08:15 PM
Make sure that you have the radio volume turned up in options - then try this code:


#include <zcmd>

CMD:stream(playerid, params[])
{
if (!isnull(params))
return SendClientMessage(playerid, -1, "Usage: /stream <url>");

return PlayAudioStreamForPlayer(playerid, params);
}

KingyKings
07/12/2013, 08:24 PM
Make sure that you have the radio volume turned up in options - then try this code:


#include <zcmd>

CMD:stream(playerid, params[])
{
if (!isnull(params))
return SendClientMessage(playerid, -1, "Usage: /stream <url>");

return PlayAudioStreamForPlayer(playerid, params);
}


It works mate!

Thankyou so much all who helped and tried! +rep all:)