mirror of
https://github.com/Coloryr/AllMusic.git
synced 2026-11-25 02:54:22 +00:00
造轮子
This commit is contained in:
1 parent
520cd6ea98
commit
f133671d52
3 files changed
+106
-25
No files matched your search
@@ -76,7 +76,6 @@ public class ALLmusic_BC extends Plugin {
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
log.info("§d[ALLmusic_BC]§e已停止,感谢使用");
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package Color_yr.ALLmusic;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.HashMap;
|
||||
@@ -10,40 +11,84 @@ import java.io.IOException;
|
||||
import javazoom.jl.decoder.Bitstream;
|
||||
import javazoom.jl.decoder.BitstreamException;
|
||||
import javazoom.jl.decoder.Header;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class PlayMusic {
|
||||
static Map<String, String> playlist = new HashMap<String, String>();
|
||||
static Runnable playgo = new playgo();
|
||||
public static void PlayMusic_Start()
|
||||
{
|
||||
playgo.run();
|
||||
static Thread playgo = new playgo();
|
||||
private static Integer warningTimes;
|
||||
public static int Mode = 0;
|
||||
public static int All_music = 0;
|
||||
public static String Music_name;
|
||||
|
||||
public static void PlayMusic_Start() {
|
||||
playgo.start();
|
||||
}
|
||||
public static int Music_Time(String music) {
|
||||
|
||||
public static int Music_Time(String music){
|
||||
try {
|
||||
URL urlfile = new URL(music);
|
||||
URLConnection con = null;
|
||||
|
||||
con = urlfile.openConnection();
|
||||
|
||||
int b = con.getContentLength();//
|
||||
URLConnection con = urlfile.openConnection();
|
||||
int b = con.getContentLength();// 得到音乐文件的总长度
|
||||
BufferedInputStream bis = new BufferedInputStream(con.getInputStream());
|
||||
Bitstream bt = new Bitstream(bis);
|
||||
Header h = bt.readFrame();
|
||||
int time = (int) h.total_ms(b);
|
||||
System.out.println(time / 1000);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (BitstreamException e)
|
||||
return time / 1000;
|
||||
}catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
e.getMessage();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static String realURL(String path) {
|
||||
HttpURLConnection connection = null;
|
||||
|
||||
try {
|
||||
URL realUrl = new URL(path);
|
||||
connection = (HttpURLConnection) realUrl.openConnection();
|
||||
connection.setRequestProperty("accept", "*/*");
|
||||
connection.setRequestProperty("connection", "Keep-Alive");
|
||||
connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
||||
connection.connect();
|
||||
connection.getContent();
|
||||
return connection.getURL().toString();
|
||||
} catch (IOException var5) {
|
||||
if (connection == null) {
|
||||
var5.printStackTrace();
|
||||
return null;
|
||||
} else {
|
||||
if (warningTimes > 0) {
|
||||
Integer var3 = warningTimes;
|
||||
warningTimes = warningTimes - 1;
|
||||
ALLmusic_BC.log.warning("> 警告: 网页请求反馈出错.");
|
||||
}
|
||||
|
||||
return connection.getURL().toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class playgo implements Runnable {
|
||||
class playgo extends Thread {
|
||||
public static void music_list() {
|
||||
if (PlayMusic.playlist.size() != 0) {
|
||||
int i = 0;
|
||||
for (; PlayMusic.playlist.size() - 1 > i; i++) {
|
||||
String a = PlayMusic.playlist.get("" + (i + 1));
|
||||
ALLmusic_BC.log.info("处理队列" + "[" + (i + 1) + "]" + a);
|
||||
PlayMusic.playlist.put("" + i, a);
|
||||
ALLmusic_BC.log.info("到队列" + "[" + i + "]" + a);
|
||||
}
|
||||
PlayMusic.playlist.remove("" + (PlayMusic.playlist.size()));
|
||||
ALLmusic_BC.log.info("删除队列" + (PlayMusic.playlist.size()));
|
||||
}
|
||||
PlayMusic.All_music = PlayMusic.playlist.size();
|
||||
}
|
||||
public synchronized void run() {
|
||||
while (true) {
|
||||
if (PlayMusic.playlist.size() == 0) {
|
||||
@@ -53,12 +98,35 @@ class playgo implements Runnable {
|
||||
e.getMessage();
|
||||
}
|
||||
} else {
|
||||
Iterator<String> iterator = PlayMusic.playlist.keySet().iterator();
|
||||
String key = iterator.next();
|
||||
String playsong = PlayMusic.playlist.get(key);
|
||||
String playsong = PlayMusic.playlist.get("0");
|
||||
String song = PlayMusic.realURL("http://music.163.com/song/media/outer/url?id=" + playsong);
|
||||
int Music_time = PlayMusic.Music_Time(song);
|
||||
ALLmusic_BC.log.info("音乐时长"+Music_time);
|
||||
ChannelListener.sendToBukkit("play", playsong);
|
||||
PlayMusic.playlist.remove(key);
|
||||
ALLmusic_BC.log.info("音乐时长"+PlayMusic.Music_Time(playsong));
|
||||
ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic_BC]§2"+"正在播放歌曲"+playsong));
|
||||
PlayMusic.playlist.remove("0");
|
||||
ALLmusic_BC.log.info("删除队列" + "[0]");
|
||||
music_list();
|
||||
try {
|
||||
while(Music_time>0)
|
||||
{
|
||||
Thread.sleep(1000);
|
||||
Music_time -- ;
|
||||
if(PlayMusic.Mode==1)
|
||||
{
|
||||
ChannelListener.sendToBukkit("stopALL", "");
|
||||
music_list();
|
||||
Music_time=0;
|
||||
if(PlayMusic.All_music==0)
|
||||
{
|
||||
ProxyServer.getInstance().broadcast(new TextComponent("§d[ALLmusic_BC]§2"+"队列中无歌曲"));
|
||||
}
|
||||
PlayMusic.Mode=0;
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class command extends Command {
|
||||
@@ -37,7 +38,8 @@ public class command extends Command {
|
||||
}
|
||||
else {
|
||||
if (isInteger(args[1])==true) {
|
||||
ChannelListener.sendToBukkit("play", args[1]);
|
||||
PlayMusic.playlist.put(String.valueOf(PlayMusic.All_music),args[1]);
|
||||
PlayMusic.All_music ++;
|
||||
sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2已发送" + args[1]));
|
||||
} else
|
||||
sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§c错误,请输入歌曲数字ID"));
|
||||
@@ -45,7 +47,19 @@ public class command extends Command {
|
||||
}
|
||||
}
|
||||
else if(args[0].equalsIgnoreCase("stop")) {
|
||||
ChannelListener.sendToBukkit("stpo", sender.getName());
|
||||
ChannelListener.sendToBukkit("stop", sender.getName());
|
||||
sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2已停止" + sender.getName()+"的音乐播放"));
|
||||
}else if(args[0].equalsIgnoreCase("now"))
|
||||
{
|
||||
Iterator<String> iterator = PlayMusic.playlist.keySet().iterator();
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
String key = iterator.next();
|
||||
sender.sendMessage(new TextComponent("§d[ALLmusic_BC]§2当前队列"+key+"->"+PlayMusic.playlist.get(key)));
|
||||
}
|
||||
}else if(args[0].equalsIgnoreCase("next"))
|
||||
{
|
||||
PlayMusic.Mode=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user