Bleuzen / Blizcord

Discord Bot written in Java using JDA and lavaplayer
MIT License
21 stars 6 forks source link

Playing a local file #14

Closed Bobakanoosh closed 5 years ago

Bobakanoosh commented 5 years ago

Hey,

I'm trying play a local file but can't figure it out for the life of me. I'm running the code myself (not through the .exe), where do I put the .mp3 file?

Thanks

Bleuzen commented 5 years ago

Hi, sorry, I don't fully understand what you asked. Do you mean how to play a local file when running a self compiled version from command line.. Or did you make an own version of Blizcord and want to know which method to call to play a file?

Bobakanoosh commented 5 years ago

I'm trying to make my own bot that just plays a few local files based on commands, for example:

!countdown - bot joins channel and plays countdown.mp3

So I'm just trying to figure out how you play a local file.

Bleuzen commented 5 years ago

Ok well just have a look at the Play command: https://github.com/Bleuzen/Blizcord/blob/547d8a1851d09a8597d5a66a5f203654a5354c64/src/com/github/bleuzen/blizcord/bot/commands/Play.java

And call the same method: https://github.com/Bleuzen/Blizcord/blob/547d8a1851d09a8597d5a66a5f203654a5354c64/src/com/github/bleuzen/blizcord/bot/AudioPlayerThread.java#L188

Example code for your countdown.mp3: AudioPlayerThread.playDirect("countdown.mp3", true);

Bobakanoosh commented 5 years ago

I got that far already: image

I believe that it's a directory issue.

Bleuzen commented 5 years ago

Yes I guess "bell.mp3" is not in your working directory. You can get your working directory in Java with something like this:

System.out.println("Working Directory = " + System.getProperty("user.dir"));

Look how the relative path from this directory to your file is and change it in your code.

Btw., offtopic, but a little hint: You shouldn't use mp3 anymore if possible. It is a pretty old format and needs reencoding on Discord. These days there are Ogg Vorbis and Opus. Both open source and free. Discord itself uses Opus as audio codec, so Opus should be the best way to go for such sounds on Discord.

Bobakanoosh commented 5 years ago

Okay thanks for the tips. Do you have any code snippets of the bare-minimum to just play audio, without all the extra commands etc?

Bleuzen commented 5 years ago

There is a small example project made with JDA and lavaplayer. Maybe this helps you: https://github.com/sedmelluq/lavaplayer/tree/master/demo-jda/src/main/java/com/sedmelluq/discord/lavaplayer/demo/jda