Added songs, new libraries and more code

This commit is contained in:
2015-05-29 12:47:25 +02:00
parent 4f4b10fd89
commit 7b21aa1e09
67 changed files with 388 additions and 75 deletions
+69 -8
View File
@@ -1,11 +1,12 @@
package model;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javazoom.jl.player.Player;
import main.Window;
import audio.AudioPlayer;
import audio.Song;
import audio.io.DirScanner;
@@ -17,13 +18,17 @@ public class SongHandler {
private int currentIndex;
private File dir;
private AudioPlayer p;
public SongHandler()
{
songs = new ArrayList<Song>();
currentSong = null;
currentIndex = 0;
currentIndex = -1;
p = new AudioPlayer();
if(Window.ON_RASP)
dir = new File(System.getProperty( "user.home" ) + "/ColorStrike/Songs");
@@ -31,27 +36,83 @@ public class SongHandler {
dir = new File("Songs");
songs = DirScanner.scanDirectories(dir);
currentSong = songs.get(currentIndex);
}
public void next()
{
currentIndex++;
currentIndex%=songs.size();
currentSong = songs.get(currentIndex);
updatePlayer();
}
public void previous()
{
currentIndex--;
currentIndex%=songs.size();
currentSong = songs.get(currentIndex);
updatePlayer();
}
public void set(int i)
{
if(currentIndex != i)
{
currentIndex = i;
updatePlayer();
}
}
private void updatePlayer()
{
if(currentIndex < 0)
currentIndex = songs.size() + currentIndex;
currentIndex%=songs.size();
currentSong = songs.get(currentIndex);
p.stop();
p.setClip(currentSong);
}
public long getProgress()
{
return p.getProgress();
}
public List<Song> getSongs()
{
return songs;
}
public Song getCurrentSong()
{
return currentSong;
}
public void close()
{
p.close();
for(Song s : songs)
{
s.close();
}
}
public void play()
{
p.play();
}
public void play(boolean b)
{
if(b)
{
p.play((int)currentSong.getSampleStart()*10000);
}
}
public void pause()
{
p.pause();
}
public void stop()
{
p.stop();
}
}