⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 baseplaylist.java

📁 java媒体播放器源代码
💻 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);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -