问题描述
我想用java来编写媒体播放器,可是一直没有思路,想请教各位不知应该怎么来写。目前我就知道要用jmf来编写,不知道可不可以不用jmf呢,如果可以要怎么做呢,希望能给出做法。谢谢各位了
解决方案
解决方案二:
importjava.io.FileInputStream;importjava.util.Calendar;importjava.util.Date;importjava.util.GregorianCalendar;importjava.util.TimerTask;importsun.audio.AudioPlayer;importsun.audio.AudioStream;publicclassMyMemoextendsTimerTask{privateFileInputStreamnowClockwav=null;privateAudioStreamwavNow=null;privateFileInputStreamHourClockwav=null;privateAudioStreamwavHour=null;privateFileInputStreamMinuteClockwav=null;privateAudioStreamwavMinute=null;privateFileInputStream[]filewav=newFileInputStream[11];AudioStream[]wavStream=null;Calendarcal=newGregorianCalendar();Datedate=null;publicMyMemo(){try{nowClockwav=newFileInputStream("E:\java\workspace\test\bin\audio\now.wav");wavNow=newAudioStream(nowClockwav);HourClockwav=newFileInputStream("E:\java\workspace\test\bin\audio\clock.wav");wavHour=newAudioStream(HourClockwav);MinuteClockwav=newFileInputStream("E:\java\workspace\test\bin\audio\minute.wav");wavMinute=newAudioStream(MinuteClockwav);wavStream=newAudioStream[11];for(inti=0;i<11;i++){filewav[i]=newFileInputStream("E:\java\workspace\test\bin\audio\"+i+".wav");wavStream[i]=newAudioStream(filewav[i]);}}catch(Exceptione){}}publicvoidrun(){try{date=newDate();cal.setTime(date);if(cal.get(Calendar.MINUTE)==20&&cal.get(Calendar.SECOND)<5){inthour=cal.get(Calendar.HOUR_OF_DAY);System.out.print(hour);AudioPlayer.player.start(wavNow);if(hour<11){AudioPlayer.player.start(wavStream[hour]);}elseif(hour<20){System.out.print(hour);AudioPlayer.player.start(wavStream[10]);AudioPlayer.player.start(wavStream[hour-10]);}elseif(hour<21){AudioPlayer.player.start(wavStream[2]);AudioPlayer.player.start(wavStream[10]);}else{AudioPlayer.player.start(wavStream[2]);AudioPlayer.player.start(wavStream[10]);AudioPlayer.player.start(wavStream[hour-20]);}AudioPlayer.player.start(wavHour);AudioPlayer.player.start(wavStream[0]);AudioPlayer.player.start(wavMinute);}}catch(Exceptione){e.printStackTrace();this.cancel();}}}