Jump to content

plz help play music


swethin

Recommended Posts

To play a sound to all players on the server, when you type the command /sound:

META:

<meta> 
    <file src="mysound.mp3" /> <!--Your MP3 File--> 
    <script src="client.lua" type="client" /> <!--REMEMBER to add this client side --> 
</meta> 

function playSound ()  
    playSound("mysound.mp3") --plays the sound 
end 
addCommandHandler("sound", playSound) --adds the command 

And if you want to disable the music, you can do it with this code by using the command /stopsound

function stopsound() 
    stopSound( mysound ) 
end 
addCommandHandler ( "stopsound", stopsound ) --using the command 'stopsound' will stop the sound 

EDIT: I just discovered you CANT have a function name on the commandhandler.

Edited by Guest
Link to comment
EDIT: I just discovered you CANT have a function name on the commandhandler.

Of course you can. Your issue is that you made an infinite loop. Look at your own code again, use the syntax highlighting on these forums and it'll be even easier to spot.

function playSound () 
    playSound("mysound.mp3") --plays the sound 
end 
addCommandHandler("sound", playSound) --adds the command 

Never name your functions the same as the native MTA functions unless your intention is to overwrite them with your own.

Your command runs the function playSound, playSound then runs itself. Infinite loop has begun and Skynet will take over.

Link to comment
You can only play songs that are music files, you can't just simply put in a youtube link. I hope you understand that.

playSound

Required Arguments

soundPath: the filepath or URL of the sound file you want to play. (Sound specified by filepath has to be predefined in the meta.xml file with tag.)

I know it's not like youtube but you can use URL's to play music.

I usually listen to german radio and I think their stream works because it's a .mp3 URL.

http://stream01.iloveradio.de/iloveradio1.mp3

Link to comment

(srry bad eng)thx for the help.the problem is sloved. i just typed in /sound in mtasa and a window poped up .its saying type url and i pasted a music url and its playing and othhers can hear it.i didnt edit meta.xml or not even a single file in mtasa. lol/ (srry bad eng)

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...