Java仿千千静听音乐播放器源代码(9)

2019-09-02 13:17

private Core core = null;

private MediaListener listener = null;

public MediaAdapter(Core core) {this.core = core;}

public Core getCore() {return core;}

public void realizeComplete(RealizeCompleteEvent e){

core.getPlayer().getGainControl().setLevel(core.getVolume()); core.getPlayer().start(); core.setPlayed(true);

core.getFrame().getVideo().addVideo(core.getPlayer().getVisualComponent()); listener = new MediaListener(this); }

public void start(StartEvent e) {core.setPaused(false);} public void stop(StopEvent e) {core.setPaused(true);}

public void endOfMedia(EndOfMediaEvent e) {core.deallocate();}

public void audioDeviceUnavailable(AudioDeviceUnavailableEvent e) {core.deallocate();}

public void connectionError(ConnectionErrorEvent e) {core.deallocate();} public void internalError(InternalErrorEvent e) {core.deallocate();} public void dataLostError(DataLostErrorEvent e) {core.deallocate();} public void controllerError(ControllerErrorEvent e) {core.deallocate();} }

MediaListener.java

package player.core;

import javax.media.Player;

import java.util.GregorianCalendar; import java.util.*; import player.lyrics.*; import player.module.*; import java.io.*; import player.user.*;

public class MediaListener extends Thread implements LyricsDownLoedListener {

private Core core = null; private Player player = null;

private MediaAdapter adapter = null; private int maxTime;

- 41 -

private int currentSeconds; private String limitTime = \;

private GregorianCalendar calendar = new GregorianCalendar(); private LyricsContent lyrics = null; private HashMap map = null; private ListItem item = null;

public MediaListener(MediaAdapter adapter) { }

public Player getPlayer() { }

return player;

this.adapter = adapter; core = adapter.getCore(); player = core.getPlayer(); lyrics = core.getLyrics(); item = core.getItem();

if (core.getItem() != null && lyrics == null) { }

maxTime = Math.round((float) player.getDuration().getSeconds()); core.getFrame().getProgressBar().setMaxLimit(maxTime); calendar.setTimeInMillis(maxTime * 1000); limitTime = this.getTimeFormat(calendar); this.start();

File file = core.getItem().getFile().getParentFile(); String name = core.getItem().getFile().getName(); name = name.substring(0, name.lastIndexOf(\));

file = new File(file.getAbsolutePath() + \ + name + \); lyrics = Lyrics.read(file); if (lyrics == null) { }

LyricsHunter hunter = new LyricsHunter(core.getItem()

.getMuisc().getName());

hunter.addLyricsDownLoadListener(this); hunter.start();

if (player == core.getPlayer()) { }

core.getItem().getMuisc().setLyrics(lyrics); core.getFrame().getLyrics().setVisible(

lyrics != null && core.getFrame().isVisible()

&& core.getFrame().isShowLyrics());

} else {

- 42 -

private static String getTimeFormat(GregorianCalendar calendar) { }

protected void setMap(HashMap map) { }

public void run() {

try {

if (lyrics != null) { }

String time = null; Integer index = null;

while (core.isPlayed() && player == core.getPlayer()) {

currentSeconds = Math.round((float) player.getMediaTime()

.getSeconds()); currentSeconds);

core.getFrame().getProgressBar().setValueForChange( calendar.setTimeInMillis(currentSeconds * 1000);

time = this.getTimeFormat(calendar).replaceAll(\, \); if (map != null) { }

core.getFrame().setMediaTime(time + \ + limitTime);

index = (Integer) map.get(time); if (index != null) { }

core.getFrame().getLyrics().setSelectIndex(

index.intValue());

ArrayList list = lyrics.getContent(); map = lyrics.getMap();

for (int i = 0; i < list.size(); i++) { }

core.getFrame().getLyrics().addLyrics(

new LyricsItem((String) list.get(i)));

this.map = map; String text = \;

if (calendar.get(calendar.MINUTE) < 10)

text += \ + calendar.get(calendar.MINUTE); text += calendar.get(calendar.MINUTE);

text += \ + calendar.get(calendar.SECOND); text += \ + calendar.get(calendar.SECOND); else

if (calendar.get(calendar.SECOND) < 10) else

return text;

- 43 -

}

}

}

Thread.sleep(500);

} catch (Exception e) {

e.printStackTrace(); this.deallocate(); } finally {

protected void deallocate() { }

public void lyricsDowned(LyricsContents contents) {

if (adapter.getCore().getPlayer() == player) {

LyricsContent content = null; if (contents.getSize() == 1) { }

if (adapter.getCore().getPlayer() == player) {

adapter.getCore().getItem().getMuisc().setLyrics(content); ArrayList list = content.getContent(); HashMap map = content.getMap();

for (int i = 0; i < list.size(); i++) { content = contents.get(0);

adapter.getCore().getFrame().getLyricsList().addItem(

new LyricsSelecter(content.getName(), content

.getSinger()));

player.removeControllerListener(adapter); player.close();

if (adapter.getCore().getPlayer() == player)

core.deallocate();

} else {

if (contents.getSize() > 0) { }

CrystalLyricsList lyricsList = new CrystalLyricsList( }

int index = lyricsList.showSelectList(); if (index != -1) { }

content = contents.get(index);

adapter.getCore().getFrame());

for (int i = 0; i < contents.getSize(); i++) {

content = contents.get(i);

lyricsList.addItem(new LyricsSelecter(

content.getName(), content.getSinger()));

- 44 -

}

}

}

}

}

core.getFrame().getLyrics().addLyrics(

new LyricsItem((String) list.get(i)));

if (core.getFrame().isVisible()

&& core.getFrame().isShowLyrics())

core.getFrame().getLyrics().setVisible(true);

this.setMap(map);

LyricsWriter.wirte(item, content);

Lyrics.java

package player.lyrics;

import java.io.*; import java.util.*;

public class Lyrics {

public static LyricsContent read(File file) {

if (file == null)return null; LyricsContent content = null; FileInputStream in = null; BufferedReader reader = null;

StringBuffer buffer = new StringBuffer(\); try { }

in = new FileInputStream(file);

reader = new BufferedReader(new InputStreamReader(in)); String line = null; int i = 0;

while ((line = reader.readLine()) != null) { }

content = Lyrics.doFilter(buffer.toString());

if (i == 0)buffer.append(line);

else buffer.append(\ + line); i++;

- 45 -


Java仿千千静听音乐播放器源代码(9).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:FLUENT udf中文资料ch8

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: