Jump to content

Streaming Radio in Cars ?


msprod

Recommended Posts

when i try this i can't hear anything, can you help me ?

function startMySound() 
 local vehicle = getPedOccupiedVehicle( getLocalPlayer() ) 
 local id = getVehicleID(vehicle) 
 if (id== 513 ) then 
 setRadioChannel(0) 
 sound = playSound( "http://d.liveatc.net/kjfk_twr", true ) 
end 
  
if (id== 429 ) then 
 setRadioChannel(0) 
 sound = playSound( "http://212.45.104.34:8042/listen.pls", true ) 
end 
end 
addEventHandler("onClientPlayerVehicleEnter",getRootElement(),startMySound) 
  
function stopMySound() 
    stopSound( sound ) 
end 
addCommandHandler ( "stopsound", stopMySound ) 
addEventHandler("onClientVehicleExplode",getRootElement(),stopMySound) 

Link to comment

Try this:

local sounds = { 
['S1'] = "http://d.liveatc.net/kjfk_twr", 
['S2'] = "http://212.45.104.34:8042/listen.pls", 
} 
  
function startMySound() 
 local vehicle = getPedOccupiedVehicle( localPlayer ) 
 local id = getVehicleID(vehicle) 
    if (id == 513 ) then 
        setRadioChannel(0) 
        playSound( sounds['S1'] ) 
    elseif (id == 429 ) then 
        setRadioChannel(0) 
        sound = playSound( sounds['S2'] ) 
    end 
end 
addEventHandler("onClientPlayerVehicleEnter",getRootElement(),startMySound) 
  
function stopMySound() 
    stopSound( sounds ) 
end 
addCommandHandler ( "stopsound", stopMySound ) 
addEventHandler("onClientVehicleExplode",getRootElement(),stopMySound) 

Link to comment

Sorry for intruding on this thread but I have a similar problem.

When I get in a vehicle it starts playing the sound but when I get out of the vehicle or issue the 'stopsound' command the sound won't stop.

function startGarageMusic() 
 local vehicle = getPedOccupiedVehicle( getLocalPlayer() ) 
 local sound = playSound("saints_row_garage.mp3", true) 
 setRadioChannel(0) 
 setSoundVolume( sound, 0.8 ) 
end 
addEventHandler("onClientVehicleEnter",getRootElement(),startGarageMusic) 
  
function stopGarageMusic() 
    stopSound( sound ) 
    end 
addCommandHandler ( "stopsound", stopGarageMusic ) 
addEventHandler("onClientVehicleExit",getRootElement(),stopGarageMusic) 

Can someone point me in the right direction?

Thanks

Link to comment

@Hutchpe try this:

  
local sound --make the sound available for the whole script 
function startGarageMusic() 
    sound = playSound("saints_row_garage.mp3", true) 
    setRadioChannel(0) 
    setSoundVolume( sound, 0.8 ) 
end 
addEventHandler("onClientVehicleEnter",getRootElement(),startGarageMusic) 
  
function stopGarageMusic() 
    if isElement(sound) then 
        stopSound( sound ) 
    end 
end 
addCommandHandler ( "stopsound", stopGarageMusic ) 
addEventHandler("onClientVehicleExit",getRootElement(),stopGarageMusic) 

@dazzlepoint Try this:

  
local sounds = { 
    ['S1'] = "http://d.liveatc.net/kjfk_twr", 
    ['S2'] = "http://212.45.104.34:8042/listen.pls", 
} 
  
function startMySound() 
    local vehicle = getPedOccupiedVehicle( localPlayer ) 
    local id = getVehicleID(vehicle) or getElementModel(vehicle) 
    if (id == 513 ) then 
        setRadioChannel(0) 
        sound = playSound( sounds['S1'] ) 
    elseif (id == 429 ) then 
        setRadioChannel(0) 
        sound = playSound( sounds['S2'] ) 
    end 
end 
addEventHandler("onClientPlayerVehicleEnter",getRootElement(),startMySound) 
  
function stopMySound() 
    stopSound( sounds ) 
end 
addCommandHandler ( "stopsound", stopMySound ) 
addEventHandler("onClientVehicleExplode",getRootElement(),stopMySound) 

Yes it does have to be client-side, and no you don't need to add the sound to the [[meta.xml]] .

Edited by Guest
Link to comment
@Hutchpe try this:
  
local sound --make the sound available for the whole script 
function startGarageMusic() 
    sound = playSound("saints_row_garage.mp3", true) 
    setRadioChannel(0) 
    setSoundVolume( sound, 0.8 ) 
end 
addEventHandler("onClientVehicleEnter",getRootElement(),startGarageMusic) 
  
function stopGarageMusic() 
    if isElement(sound) then 
        stopSound( sound ) 
    end 
end 
addCommandHandler ( "stopsound", stopGarageMusic ) 
addEventHandler("onClientVehicleExit",getRootElement(),stopGarageMusic) 

@dazzlepoint Try this:

  
local sounds = { 
    ['S1'] = "http://d.liveatc.net/kjfk_twr", 
    ['S2'] = "http://212.45.104.34:8042/listen.pls", 
} 
  
function startMySound() 
    local vehicle = getPedOccupiedVehicle( localPlayer ) 
    local id = getVehicleID(vehicle) or getElementModel(vehicle) 
    if (id == 513 ) then 
        setRadioChannel(0) 
        sound = playSound( sounds['S1'] ) 
    elseif (id == 429 ) then 
        setRadioChannel(0) 
        sound = playSound( sounds['S2'] ) 
    end 
end 
addEventHandler("onClientPlayerVehicleEnter",getRootElement(),startMySound) 
  
function stopMySound() 
    stopSound( sounds ) 
end 
addCommandHandler ( "stopsound", stopMySound ) 
addEventHandler("onClientVehicleExplode",getRootElement(),stopMySound) 

Yes it does have to be client-side, and no you don't need to add the sound to the [[meta.xml]] .

Is that my code?

That code for @dazzlepoint.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...