if ((line.startsWith("#")) && (line.isEmpty()))
if (!(line.startsWith("#")) && !(line.isEmpty() ) )
if (!(line.startsWith("#")) && !(line.isEmpty() ) ) {
line = pathname;
File m3u1 = new File(pathname);
// line = pathname;
File m3u1 = new File(line);
import java.io.File;
import java.io.FileWriter;
import java.util.Scanner;
import java.util.Random;
public class PlayList extends LinkedList<AudioFile> {
public boolean add(AudioFile o) {
if (o == null) {
return false;
} else {
return super.add(o);
}
}
private int current;
private boolean randomOrder;
public int getCurrent() {
return current;
}
public void setCurrent(int current) {
this.current = current;
}
public AudioFile getCurrentAudioFile() {
if (this.isEmpty())
return null;
else
return this.get(current);
}
public void setRandomOrder(boolean randomOrder) {
this.randomOrder = randomOrder;
}
private Random randomValue = new Random();
public void changeCurrent() {
if (randomOrder) {
int oldCurrent = this.getCurrent();
int newCurrent = 0;
do {
newCurrent = randomValue.nextInt(this.size());
} while (oldCurrent == newCurrent);
setCurrent(newCurrent);
}
randomOrder = false;
{
if (current == this.size() - 1)
current = 0;
else
current++;
}
}
public void saveAsM3U(String pathname) {
File m3u = new File(pathname);
FileWriter fw = null;
try {
fw = new FileWriter(m3u, true);
for (int i = 0; i < this.size(); i++) {
fw.write(this.get(i).getPathname()
+ System.getProperty("line.separator"));
}
fw.close();
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
public void loadFromM3U(String pathname) {
try {
Scanner s = new Scanner(new File(pathname));
while (s.hasNext()) {
String line = s.nextLine();
if ((line.startsWith("#")) && (line.isEmpty())) {
line = pathname;
File m3u1 = new File(pathname);
if (m3u1.canExecute()) {
add(AudioFileFactory.getInstance(pathname));
}
}
}
s.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public PlayList() {
}
public PlayList(String pathname) {
this.loadFromM3U(pathname);
}
public String toString() {
int tmpSize = 0;
int i;
tmpSize = this.size();
String tmpStr = "";
for (i = 0; i < tmpSize - 1; i++)
tmpStr = tmpStr + this.get(i).toString();
return tmpStr;
}
public static void main(String[] args) {
PlayList pl1 = new PlayList();
pl1.add(AudioFileFactory.getInstance("C:\\Rock 812.mp3"));
pl1
.add(AudioFileFactory
.getInstance("C:\\wellenmeister_awakening.mp3"));
pl1.add(AudioFileFactory
.getInstance("C:\\wellenmeister - tranquility.wav"));
pl1.add(AudioFileFactory.getInstance("C:\\kein.wav.sondern.ogg"));
pl1.add(AudioFileFactory.getInstance("C:\\kein.ogg.sondern.wav"));
pl1.saveAsM3U("PlList.m3u");
PlayList pl2 = new PlayList("PlList.m3u");
System.out.println(pl2.toString());
pl2.setRandomOrder(true);
while (true) {
System.out.println("pl2:" + pl2.getCurrent() + "- Title:"
+ pl2.get(pl2.getCurrent()));
pl2.changeCurrent();
}
}
}