Adding Dell button

This commit is contained in:
BrokenFire 2018-01-13 19:12:02 +01:00
parent 1cf8f16bdb
commit 41e58f7c46
4 changed files with 65 additions and 1 deletions

View File

@ -0,0 +1,29 @@
package net.Broken.RestApi.Commands;
import net.Broken.Commands.Music;
import net.Broken.RestApi.CommandInterface;
import net.Broken.RestApi.Data.CommandPostData;
import net.Broken.RestApi.Data.CommandResponseData;
import net.Broken.audio.NotConectedException;
import net.Broken.audio.NullMusicManager;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
public class Dell implements CommandInterface {
@Override
public ResponseEntity<CommandResponseData> action(Music musicCommande, CommandPostData data) {
if(data.url != null) {
try {
if(musicCommande.getAudioManager().getMusicManager().scheduler.remove(data.url)){
return new ResponseEntity<>(new CommandResponseData(data.command, "Accepted"), HttpStatus.OK);
}
else
return new ResponseEntity<>(new CommandResponseData(data.command,"URL not found"), HttpStatus.NOT_FOUND);
} catch (NullMusicManager | NotConectedException nullMusicManager) {
return new ResponseEntity<>(new CommandResponseData(data.command, "Not connected to vocal!"), HttpStatus.NOT_ACCEPTABLE);
}
}
return new ResponseEntity<>(new CommandResponseData(data.command, "Missing URL"), HttpStatus.NOT_ACCEPTABLE);
}
}

View File

@ -5,6 +5,8 @@ import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.ArrayList;
import java.util.List;
@ -19,6 +21,7 @@ import java.util.concurrent.LinkedBlockingQueue;
public class TrackScheduler extends AudioEventAdapter {
private final AudioPlayer player;
private final BlockingDeque<AudioTrack> queue;
Logger logger = LogManager.getLogger();
/**
* @param player The audio player this scheduler uses
@ -85,6 +88,22 @@ public class TrackScheduler extends AudioEventAdapter {
return player.getPlayingTrack().getInfo();
}
public boolean remove(String uri){
for(AudioTrack track : queue){
if(track.getInfo().uri.equals(uri)){
if(!queue.remove(track)) {
logger.info("Delete failure!");
return false;
} else {
logger.info("Delete succeful");
return true;
}
}
}
logger.info("Delete failure! Not found.");
return false;
}
/**
* Start the next track, stopping the current one if it is playing.
*/

View File

@ -35,6 +35,8 @@ $(document).ready(function() {
});
$('#btn_next').click(function () {
sendCommand(JSON.stringify({ command: "NEXT"}));
});
@ -270,6 +272,15 @@ function getPlayList() {
$('#playlist_list').append(template);
});
$(".btn_dell_playlist").click(function () {
var command = {
command: "DELL",
url: $(this).attr("data_url")
};
sendCommand(JSON.stringify(command));
});
}
}
@ -349,7 +360,7 @@ function updateControl(data){
}
$('#music_img').attr("src","https://img.youtube.com/vi/"+data.info.identifier+"/hqdefault.jpg");
console.log(data);
// console.log(data);
$('#total_time').text(msToTime(data.info.length));
$('#current_time').text(msToTime(data.currentPos));
updateModal(data);

View File

@ -177,6 +177,11 @@
<li class="collection-item">Author: @author</li>
<li class="collection-item">Duration: @lenght</li>
<li class="collection-item">URL: <a target="_blank" href="@url">@url</a></li>
<li class="collection-item center">
<a class="btn red darken-4 z-depth-3 waves-effect waves-light btn_dell_playlist" data_url="@url">
<i class="material-icons medium">delete</i>
</a>
</li>
</ul>
</div>
</li>