Two questions about PlayAudioStreamForPlayer
#1

Okay, so I want to know how I can stream music that a driver is playing to all of the passengers in the same car.

Also I want to know how I can make it so that once a player leaves their car and then returns, that same stream is still playing.

I am using multiple streams using a dialog menu.
Reply
#2

Yes.
Reply
#3

Quote:
Originally Posted by EAsT-OAK_510
Посмотреть сообщение
Okay, so I want to know how I can stream music that a driver is playing to all of the passengers in the same car.

Also I want to know how I can make it so that once a player leaves their car and then returns, that same stream is still playing.

I am using multiple streams using a dialog menu.
Anyone?
Reply
#4

You need a live radio stream, so no matter when they tune in, they will all hear the sound that is being sent out by that radio station, much like a radio station in real life... which is basically what it is anyway...
Reply
#5

Quote:
Originally Posted by BenzoAMG
Посмотреть сообщение
You need a live radio stream, so no matter when they tune in, they will all hear the sound that is being sent out by that radio station, much like a radio station in real life... which is basically what it is anyway...
That's what I want to do. I already have links, but only the driver is able to hear the stream when it is playing.
Reply
#6

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
    {
        if(oldstate == PLAYER_STATE_ONFOOT)
        {
            PlayAudioStreamForPlayer(playerid, "place url here");
        }
    }
    if(newstate == PLAYER_STATE_ONFOOT)
    {
        if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
        {
            StopAudioStreamForPlayer(playerid);
        }
    }
    return 1;
}
Try something like this. Make sure to replace "place url here" with the link to your radio station.
Reply
#7

Quote:
Originally Posted by BenzoAMG
Посмотреть сообщение
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
    {
        if(oldstate == PLAYER_STATE_ONFOOT)
        {
            PlayAudioStreamForPlayer(playerid, "place url here");
        }
    }
    if(newstate == PLAYER_STATE_ONFOOT)
    {
        if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
        {
            StopAudioStreamForPlayer(playerid);
        }
    }
    return 1;
}
Try something like this. Make sure to replace "place url here" with the link to your radio station.
Alright, now about the other question I had, how do I play the last radio station link they were listening to when re-entering their car?
Reply
#8

Can you send me the dialog menu and I might be able to do it for you, it's a little tricky to explain and I doubt you would understand it on the first try.

You need to set a variable to the player, for example:
pawn Код:
new Radio[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    Radio[playerid] = 0;
    return 1;
}

//In your dialog...

if(listitem == 1)
{
    Radio[playerid] = 1;
}
else if(listitem == 2)
{
    Radio[playerid] = 2;
}
//Or alternatively...
//Radio[playerid] = listitem;

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
    {
        if(oldstate == PLAYER_STATE_ONFOOT)
        {
            if(Radio[playerid] == 1)
            {
                PlayAudioStreamForPlayer(playerid, "place url here");
            }
            else if(Radio[playerid] == 2)
            {
                PlayAudioStreamForPlayer(playerid, "place url here");
            }
            //etc...
        }
    }
    if(newstate == PLAYER_STATE_ONFOOT)
    {
        if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
        {
            StopAudioStreamForPlayer(playerid);
        }
    }
    return 1;
}
Reply
#9

I will PM it.
Reply
#10

Give this a shot:
pawn Код:
new Radio[MAX_PLAYERS]; //At the top of your script

public OnPlayerConnect(playerid)
{
    Radio[playerid] = 0;
    return 1;
}

CMD:xmradio(playerid, params[])
{
    if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, COLOR_GREY, "You are not driving a vehicle.");
    ShowPlayerDialog(playerid,90,DIALOG_STYLE_LIST,"XM Radio menu - Page 1","{FF0000}Category: Hip-Hop(Rap) & RnB:\r\n{FFFFFF}1. Hot 108\r\n2. Flow 103\r\n3. DefJay (RnB)\r\n4. West Coast Radio\r\n5. Hot 97 New York\r\n6. G'd Up Radio\r\n{FF0000}Category: Dubstep:\r\n{FFFFFF}1. Dubstep FM\r\n2. Filth FM\r\n3. Musik Drumstep\r\n{FF0000}Category: Classic Rock:\r\n1. Canada Classic Rock Radio\r\n2. 181.FM- The Eagle","Select", "Cancel");
    return 1;
}

CMD:stopradio(playerid, params[])
{
    if(Radio[playerid] == 0) return SendClientMessage(playerid, 0xFF0000FF, "You do not have your radio turned on.");
    SendClientMessage(playerid, 0x42F3F198, "You have switched off your radio.");
    StopAudioStreamForPlayer(playerid);
    Radio[playerid] = 0;
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case 90:
        {
            if(!response) return SendClientMessage(playerid, 0x42F3F198, "You've closed the XM Radio menu.");//
            switch(listitem)//
            {
                case 0: //
                {
                    ShowPlayerDialog(playerid,91,DIALOG_STYLE_LIST,"Category: Hip-Hop(Rap) & RnB","1. Hot 108\r\n2. Flow 103\r\n3. DefJay (RnB)\r\n4. West Coast Radio\r\n5. Hot 97 New York\r\n6. G'd Up Radio","Select", "Cancel");
                }
                case 1: //
                {
                    PlayAudioStreamForPlayer(playerid, "http://www.hot108.com/hot108.pls");
                    Radio[playerid] = 1;
                }
                case 2: //
                {
                    PlayAudioStreamForPlayer(playerid, "http://173.245.71.186:80");
                    Radio[playerid] = 2;
                }
                case 3: //
                {
                    PlayAudioStreamForPlayer(playerid, "http://he-srv1.defjay.com:80");
                    Radio[playerid] = 3;
                }
                case 4: //
                {
                    PlayAudioStreamForPlayer(playerid, "http://212.117.39.164:8000");
                    Radio[playerid] = 4;
                }
                case 5: //
                {
                    PlayAudioStreamForPlayer(playerid, "http://6093.live.streamtheworld.com:80/WQHTFM_SC");
                    Radio[playerid] = 5;
                }
                case 6: //
                {
                    PlayAudioStreamForPlayer(playerid, "http://174.36.206.217:8577");
                    Radio[playerid] = 6;
                }
                case 7: //
                {
                     ShowPlayerDialog(playerid,92,DIALOG_STYLE_LIST,"Category: Dubstep","1. Dubstep FM\r\n2. Filth FM\r\n3. Musik Drumstep","Select", "Cancel");
                }
                case 8: //
                {
                    PlayAudioStreamForPlayer(playerid, "http://72.13.91.147:80");
                    Radio[playerid] = 7;
                }
                case 9: //
                {
                    PlayAudioStreamForPlayer(playerid, "http://75.125.130.122:8062");
                    Radio[playerid] = 8;
                }
                case 10: //
                {
                    PlayAudioStreamForPlayer(playerid, "http://178.77.93.190:21000");
                    Radio[playerid] = 9;
                }
                case 11: //
                {
                     ShowPlayerDialog(playerid,93,DIALOG_STYLE_LIST,"Category: Classic Rock","1. Canada Classic Rock Radio\r\n2. 181.FM- The Eagle","Select", "Cancel");
                }
                case 12: //
                {
                    PlayAudioStreamForPlayer(playerid, "http://173.192.224.123:8651");
                    Radio[playerid] = 10;
                }
                case 13: //
                {
                    PlayAudioStreamForPlayer(playerid, "http://66.197.229.245:8082");
                    Radio[playerid] = 11;
                }
            }
        }
        case 91:
        {
            switch(listitem)
            {
                case 0: //
                {
                    PlayAudioStreamForPlayer(playerid, "http://www.hot108.com/hot108.pls");
                    Radio[playerid] = 1;
                }
                case 1: //
                {
                    PlayAudioStreamForPlayer(playerid, "http://173.245.71.186:80");
                    Radio[playerid] = 2;
                }
                case 2: //
                {
                    PlayAudioStreamForPlayer(playerid, "http://he-srv1.defjay.com:80");
                    Radio[playerid] = 3;
                }
                case 3: //
                {
                    PlayAudioStreamForPlayer(playerid, "http://212.117.39.164:8000");
                    Radio[playerid] = 4;
                }
                case 4: //
                {
                    PlayAudioStreamForPlayer(playerid, "http://6093.live.streamtheworld.com:80/WQHTFM_SC");
                    Radio[playerid] = 5;
                }
                case 5: //
                {
                    PlayAudioStreamForPlayer(playerid, "http://174.36.206.217:8577");
                    Radio[playerid] = 6;
                }
            }
        }
        case 92:
        {
            switch(listitem)
            {      
                case 0: //
                {
                    PlayAudioStreamForPlayer(playerid, "http://72.13.91.147:80");
                    Radio[playerid] = 7;
                }
                case 1: //
                {
                    PlayAudioStreamForPlayer(playerid, "http://75.125.130.122:8062");
                    Radio[playerid] = 8;
                }
                case 2: //
                {
                    PlayAudioStreamForPlayer(playerid, "http://178.77.93.190:21000");
                    Radio[playerid] = 9;
                }
            }
        }
        case 93:
        {
            switch(listitem)
            {
                case 0: //
                {
                    PlayAudioStreamForPlayer(playerid, "http://173.192.224.123:8651");
                    Radio[playerid] = 10;
                }
                case 1: //
                {
                    PlayAudioStreamForPlayer(playerid, "http://66.197.229.245:8082");
                    Radio[playerid] = 11;
                }
            }
        }    
    }
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
    {
        if(oldstate == PLAYER_STATE_ONFOOT)
        {
            PlayRadioStationForPlayer(playerid);
        }
    }
    if(newstate == PLAYER_STATE_ONFOOT)
    {
        if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
        {
            StopAudioStreamForPlayer(playerid);
        }
    }
    return 1;
}

stock PlayRadioStationForPlayer(playerid)
{
    switch(Radio[playerid])
    {
        case 0: return 0;
        case 1: return PlayAudioStreamForPlayer(playerid, "http://www.hot108.com/hot108.pls");
        case 2: return PlayAudioStreamForPlayer(playerid, "http://173.245.71.186:80");
        case 3: return PlayAudioStreamForPlayer(playerid, "http://he-srv1.defjay.com:80");
        case 4: return PlayAudioStreamForPlayer(playerid, "http://212.117.39.164:8000");
        case 5: return PlayAudioStreamForPlayer(playerid, "http://6093.live.streamtheworld.com:80/WQHTFM_SC");
        case 6: return PlayAudioStreamForPlayer(playerid, "http://174.36.206.217:8577");
        case 7: return PlayAudioStreamForPlayer(playerid, "http://72.13.91.147:80");
        case 8: return PlayAudioStreamForPlayer(playerid, "http://75.125.130.122:8062");
        case 9: return PlayAudioStreamForPlayer(playerid, "http://178.77.93.190:21000");
        case 10: return PlayAudioStreamForPlayer(playerid, "http://173.192.224.123:8651");
        case 11: return PlayAudioStreamForPlayer(playerid, "http://66.197.229.245:8082");
    }
    return 1;
}
Sorry if it has errors, I made this in notepad.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)