Uses 34242K of libraries. Click here for Pure Java version (10710L/57K).
1 | !7 |
2 | |
3 | //set flag DifferentJDA. |
4 | //lib 1400185 // discord with opus/JNA (hopefully not a problem) |
5 | |
6 | import net.dv8tion.jda.core.managers.AudioManager; // Note: moved from core to api in JDA 4.0 |
7 | import net.dv8tion.jda.core.audio.*; |
8 | |
9 | import java.nio.ByteBuffer; |
10 | import com.sedmelluq.discord.lavaplayer.player.*; |
11 | import com.sedmelluq.discord.lavaplayer.player.event.*; |
12 | import com.sedmelluq.discord.lavaplayer.demo.jda.TrackScheduler; |
13 | import com.sedmelluq.discord.lavaplayer.track.*; |
14 | import com.sedmelluq.discord.lavaplayer.track.playback.*; |
15 | import com.sedmelluq.discord.lavaplayer.source.*; |
16 | import com.sedmelluq.discord.lavaplayer.tools.*; |
17 | |
18 | //lib 1400286 // lavaplayer 1.3.22 |
19 | lib 1400288 // lavaplayer fat |
20 | lib 1400289 // httpclient |
21 | lib 1400290 // httpcore |
22 | lib 1400291 // commons-io |
23 | lib 1400298 // lavaplayer libconnector.so |
24 | lib 1400295 lib 1400296 // logback |
25 | lib 1002510 // jsoup |
26 | lib 1400299 // apache-commons-logging |
27 | |
28 | static AudioPlayerManager playerManager; |
29 | svoid cleanMeUp { dispose playerManager; } |
30 | |
31 | cmodule DiscordAudioSpike > DynTalkBot2 { |
32 | S myName = "Discord Audio Spike"; |
33 | |
34 | start { |
35 | setLoggingLevel(ch.qos.logback.classic.Level.DEBUG); |
36 | if (isLinux()) { |
37 | //loadNativeLibraryInX30(loadLibrary(#1400293)); |
38 | loadNativeLibrarySnippet/*InX30*/(#1400293); // libopus |
39 | //loadNativeLibrarySnippet/*InX30*/(#1400294); // libconnector |
40 | } |
41 | makeByServer = () -> new ByServer; |
42 | useAGIBlueForDropPunctuation = false; |
43 | preprocessAtSelfToMyName = false; |
44 | |
45 | if (playerManager == null) { |
46 | playerManager = new DefaultAudioPlayerManager; |
47 | AudioSourceManagers.registerLocalSource(playerManager); |
48 | AudioSourceManagers.registerRemoteSources(playerManager); |
49 | } |
50 | } |
51 | |
52 | class ByServer extends DynTalkBot2.ByServer { |
53 | synchronized S processSimplifiedLine(S s, O... _) { |
54 | try answer super.processSimplifiedLine(s, _); // adding authorized users etc. |
55 | new Matches m; |
56 | if null (s = dropMyPrefixOrNull(s)) null; |
57 | optPar Message msg; |
58 | Guild guild = msg == null ? null : msg.getGuild(); |
59 | |
60 | if "voice channels" |
61 | ret str(guild.getVoiceChannels()); |
62 | |
63 | if "join voice channel" |
64 | ret joinVoiceChannel(first(guild.getVoiceChannels()); |
65 | |
66 | if (eqic(s, "help")) |
67 | ret ltrim([[ |
68 | I'm a Discord Audio Test |
69 | |
70 | [Bot made by https://BotCompany.de] |
71 | ]]).replace("@me", atSelf()); |
72 | |
73 | null; |
74 | } |
75 | |
76 | S joinVoiceChannel(VoiceChannel vc) { |
77 | if (vc == null) ret "No channel"; |
78 | |
79 | Guild guild = vc.getGuild(); |
80 | AudioManager am = guild.getAudioManager(); |
81 | |
82 | AudioPlayer player = playerManager.createPlayer(); |
83 | TrackScheduler trackScheduler = new(player); |
84 | player.addListener(trackScheduler); |
85 | player.addListener(e -> { |
86 | temp enter(); |
87 | print("Audio event: " + e); |
88 | if (e cast TrackExceptionEvent) |
89 | printStackTrace(e.exception); |
90 | }); |
91 | |
92 | am.setSendingHandler(new AudioPlayerSendHandler(player)); |
93 | am.openAudioConnection(vc); |
94 | |
95 | /*S trackID = f2s( |
96 | //loadLibrary(#1400292) // opus |
97 | mp3ToWAVUnlessExists(loadLibrary(#1001093), javaxCachesDir("1001093.wav")) // mp3 -> wav |
98 | );*/ |
99 | S trackID = "http://s3.free-shoutcast.com:18162/;?type=http&nocache=" + randomInt(); |
100 | |
101 | playerManager.loadItem(print("Loading: ", trackID), new AudioLoadResultHandler { |
102 | public void trackLoaded(AudioTrack track) enter { |
103 | //print("Scheduling track " + track); |
104 | //trackScheduler.queue(track); |
105 | //player.playTrack(track); |
106 | print(player.startTrack(track, false)); |
107 | print("Started track " + track); |
108 | print("isPaused: " + player.isPaused()); |
109 | print("Active track: " + player.getPlayingTrack()); |
110 | } |
111 | |
112 | public void playlistLoaded(AudioPlaylist playlist) enter { |
113 | for (AudioTrack track : playlist.getTracks()) |
114 | trackScheduler.queue(track); |
115 | } |
116 | |
117 | public void noMatches() enter { print("noMatches"); } |
118 | public void loadFailed(FriendlyException e) enter { |
119 | print("loadFailed: " + e); |
120 | printStackTrace(e); |
121 | } |
122 | }); |
123 | |
124 | ret "Audio connection to " + vc.getName() + " opened"; |
125 | } |
126 | } |
127 | |
128 | } |
129 | |
130 | sclass AudioPlayerSendHandler implements AudioSendHandler { |
131 | AudioPlayer audioPlayer; |
132 | AudioFrame lastFrame; |
133 | NotTooOften nto = notTooOften_everySecond(); |
134 | |
135 | *(AudioPlayer *audioPlayer) {} |
136 | |
137 | public bool canProvide() { |
138 | lastFrame = audioPlayer.provide(); |
139 | if (nto.yo()) print("canProvide: " + (lastFrame != null)); |
140 | ret lastFrame != null; |
141 | } |
142 | |
143 | public byte[] provide20MsAudio() { |
144 | return lastFrame.getData(); |
145 | } |
146 | |
147 | public bool isOpus() { true; } |
148 | } |
149 | |
150 | svoid setLoggingLevel(ch.qos.logback.classic.Level level) { |
151 | ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) org.slf4j.LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME); |
152 | root.setLevel(level); |
153 | } |
Began life as a copy of #1024145
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1025322 |
Snippet name: | Discord Audio Spike [dev., warning: loads native libraries] |
Eternal ID of this version: | #1025322/63 |
Text MD5: | f859bba836396c8aab51f161f480f470 |
Transpilation MD5: | 3ec11903695d63dcf6e5307951c56e93 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-09-22 19:50:46 |
Source code size: | 5102 bytes / 153 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 453 / 1093 |
Version history: | 62 change(s) |
Referenced in: | [show references] |