【Java开源代码栏目提醒】:以下是网学会员为您推荐的Java开源代码-BasePlaylist.java,希望本篇文章对您学习有所帮助。
package javazoom.jlGui.playlist;
import java.util.Collection;
import java.util.Vector;
import java.io.*;
import javazoom.Util.*;
/**
* 类BasePlaylist利用Vector执行Playlist接口
*/
public class BasePlaylist implements Playlist
{
protected Vector _playlist = null;
protected int _cursorPos = -1;
// 构造方法 public BasePlaylist()
{
_playlist = new Vector();
}
// 加载播放列表
public void load(String filename)
{
BufferedReader br = null;
try
{
br = new BufferedReader(new FileReader(filename));
String line = null;
String songName = null;
String songFile = null;
String songLenght = null;
while ((line = br.readLine())!=null)
{
if (line.startsWith("#"))
{
int indA = line.indexOf(",",0);
if (indA != -1) songName = line.substring(indA+1,line.length());
}
else
{
boolean isFile = true;
songFile = line;
if (songFile.startsWith("http://"))
{
isFile = false;
if (songName == null) songName = songFile;
}
if (songName == null)
{
songName = songFile;
songName = songName.substring((songName.lastIndexOf(System.getProperty("file.separator")))+1,songName.length());
}
PlaylistItem pli = new PlaylistItem(songName, songFile, -1, isFile);
this.appendItem(pli);
songFile = null;
songName = null;
songLenght = null;
}
}
} catch (Exception e)
{
trace(1,getClass().getName(),"Can't load playlist : "+e.getMessage());
}
finally
{
try
{
if (br != null) br.close();
} catch (Exception ioe)
{
trace(1,getClass().getName(),"Can't close playlist : "+ioe.getMessage());
}
}
}
//保存播放列表
public void save(String filename)
{
}
//添加曲目到播放列表中指定位置
public void addItemAt(PlaylistItem pli, int pos)
{
_playlist.insertElementAt(pli,pos);
}
//查找、移走播放列表中曲目
public void removeItem(PlaylistItem pli)
{
_playlist.remove(pli);
}
//删除播放列表中指定曲目
public void removeItemAt(int pos)
{
_playlist.removeElementAt(pos);
}
//播放
列表追加
public void appendItem(PlaylistItem pli)
{
_playlist.addElement(pli);
}
//播放列表排序
public void sortItems(int sortmode)
{
}
//随机拖放
public void shuffle()
{
}
//播放列表指定曲目
public PlaylistItem getItemAt(int pos)
{
PlaylistItem pli = null;
pli = (PlaylistItem) _playlist.elementAt(pos);
return pli;
}
//播放列表选择
public Collection getAllItems()
{
return null;
}
//返回播放列表中的数目
public int getPlaylistSize()
{
return _playlist.size();
}
// Player调用下一方法
//返回光标位置
public PlaylistItem getCursor()
{
if((_cursorPos < 0) || (_cursorPos >= _playlist.size())) return null;
return getItemAt(_cursorPos);
}
//计算进度条位置(后)
public void nextCursor()
{
_cursorPos++;
if (_cursorPos >= _playlist.size()) _cursorPos = _playlist.size();
}
//计算进度条位置(前)
public void previousCursor()
{
_cursorPos--;
if(_cursorPos < 0) _cursorPos = -1;
}
//轨道
private void trace(int level, String msg1, String msg2)
{
Debug dbg = Debug.getInstance();
dbg.log(level,msg1+":"+msg2);
}
}