第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

通過將給定路徑名字符串轉(zhuǎn)換為抽象路徑名來創(chuàng)建一個新 File 實例。怎么他有報錯了?

通過將給定路徑名字符串轉(zhuǎn)換為抽象路徑名來創(chuàng)建一個新 File 實例。怎么他有報錯了?

System.out.println(Thread.currentThread().getName()+"啟動。。。");BufferedInputStream bis=null;RandomAccessFile ras=null;byte[] buf=new byte[BUFFER_SIZE];URLConnection con=null;try{con=srcURL.openConnection();con.setRequestProperty("Range", "byte="+start+"-"+end);bis=new BufferedInputStream(con.getInputStream());ras=new RandomAccessFile(destFile, "rw");其中一段代碼,最后一句,在Eclipse中一直報錯:The constructor RandomAccessFile(File, String) is undefined;其中destFile的聲明:private final File destFile;構(gòu)造函數(shù)public DownloadRunnable(int start,int end,URL srcURL,File destFile);我再去看RandomAccessFile的源碼,明明有RandomAccessFile(File file,String mode)這個構(gòu)造函數(shù)啊,而且在Eclipse中alt+/也能看到這個構(gòu)造函數(shù),可是寫出來就是報這個錯,怎么回事?還有啊,上面主程序有這句代碼:File destFile=new File("d:\\java\\test\\國歌.map3");Eclipse也報錯:The constructor File(String) is undefined;A源代碼明明也有這個構(gòu)造函數(shù):File(String pathname)
查看完整描述

1 回答

?
一只甜甜圈

TA貢獻(xiàn)1836條經(jīng)驗 獲得超5個贊

你是要播放音源檔??
播放音樂的話最好是相關(guān)設(shè)定都要設(shè)定會比較好
以前也有播放音樂有時正常有時不正常,所以最好是可以建立一個完整的音源檔使用!!

package wav;
import javax.sound.sampled.*;

import java.io.*;
import java.net.*;

/**
* 播放音樂(支援WAV, AIFF, AU) 2011/10/09
*
* 2012/12/08
* 1.增加播放結(jié)束時callback
* 2.修正bug: 無限次播放時,無法stop()
*
* @version 2
* @author Ray(吉他手)
*/
public class AudioPlayer{
private AudioInputStream currentSound;

private Clip clip;

private float gain;
private FloatControl gainControl;

//控制聲道,-1.0f:只有左聲道, 0.0f:雙聲道,1.0f右聲道
private float pan;
private FloatControl panControl;

//控制靜音 開/關(guān)
private boolean mute;
private BooleanControl muteControl;

//播放次數(shù),小於等於0:無限次播放,大於0:播放次數(shù)
private int playCount;

private DataLine.Info dlInfo;
private Object loadReference;
private AudioFormat format;

//音樂播放完畢時,若有設(shè)定回call的對象,則會通知此對象
private AudioPlayerCallback callbackTartet;
private Object callbackObj ;
private boolean isPause;

public AudioPlayer(){
AudioPlayerInit();
}

public void AudioPlayerInit(){
currentSound = null;
clip = null;
gain = 0.5f;
gainControl = null;
pan = 0.0f;
panControl = null;
mute = false;
muteControl = null;
playCount = 0;
dlInfo = null;
isPause = false;
}

/**
* 設(shè)定要接收音樂播放完時事件的對象
* @param cb 接收callback的對象
* @param obj callback回來的物件
*/
public void setCallbackTartet(AudioPlayerCallback cb, Object obj){
callbackTartet = cb;
callbackObj = obj;
}

/**
* 設(shè)定播放次數(shù),播放次數(shù),小於等於0:無限次播放,大於0:播放次數(shù)
* @param c
*/
public void setPlayCount(int c){
if(c < -1){
c = -1;
}
playCount = c - 1;
}

/**
* 指定路徑讀取音檔,回傳true:播放成功,false:播放失敗
* @param filePath
* @param obj 目前物件放置的package路徑
*/
public boolean loadAudio(String filePath){
try {
loadAudio(new File(filePath));
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}

/**
* 指定路徑讀取音檔,使用目前物件放置的package當(dāng)相對路徑root,null時不使用物件路徑為root
* @param filePath
* @param obj 目前物件放置的package路徑
* @return 回傳true:播放成功,false:播放失敗
*/
public boolean loadAudio(String filePath, Object obj){
try {
if(obj != null){
loadAudio(obj.getClass().getResourceAsStream(filePath));
}else{
loadAudio(new File(filePath));
}
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}

/**
* 從遠(yuǎn)端讀取音檔
*/
public void loadAudio(URL url) throws Exception{
loadReference = url;
currentSound = AudioSystem.getAudioInputStream(url);
finishLoadingAudio();
}

/**
* 讀取本地端音檔
* @param file
* @throws Exception
*/
public void loadAudio(File file) throws Exception{
loadReference = file;
currentSound = AudioSystem.getAudioInputStream(file);
finishLoadingAudio();
}

/**
* 從串流讀取音檔
* @param iStream
* @throws Exception
*/
public void loadAudio(InputStream iStream) throws Exception{
loadReference = iStream;

if (iStream instanceof AudioInputStream){
currentSound = (AudioInputStream)iStream;
} else {
currentSound = AudioSystem.getAudioInputStream(iStream);
}
finishLoadingAudio();
}

/**
* load完音檔後,進(jìn)行播放設(shè)定
*/
protected void finishLoadingAudio() throws Exception {
format = currentSound.getFormat();
dlInfo = new DataLine.Info(Clip.class, format, ((int) currentSound.getFrameLength() * format.getFrameSize()));
clip = (Clip) AudioSystem.getLine(dlInfo);
clip.open(currentSound);
clip.addLineListener(
new LineListener() {
public void update(LineEvent event) {
if (event.getType().equals(LineEvent.Type.STOP)){
if(!isPause){
if(callbackTartet != null){
callbackTartet.audioPlayEnd(callbackObj);
}
close();
}
}
}
}
);
}

/**
* 播放音檔
*/
public void play(){
if(clip != null){
clip.setFramePosition(0);
clip.loop(playCount);
}
}

/**
* 恢復(fù)播放音檔
*
*/
public void resume(){
isPause = false;

if(clip != null){
clip.setFramePosition(clip.getFramePosition());
clip.loop(playCount);
}

}

/**
* 暫停播放音檔
*/
public void pause(){
isPause = true;
if(clip != null){
clip.stop();
}
}

/**
* 停止播放音檔,且將音檔播放位置移回開始處
*/
public void stop(){
if(clip != null){
clip.stop();
}
}

/**
* 設(shè)定音量
* @param dB 0~1,預(yù)設(shè)為0.5
*/
public void setVolume(float dB){
float tempB = floor_pow(dB,1);
//System.out.println("目前音量+"+tempB);
gain = tempB;
resetVolume();

}

/**
* @param min 要無條件舍去的數(shù)字
* @param Num 要舍去的位數(shù)
*
*/
private float floor_pow(float min, int Num){
float n = (float)Math.pow(10, Num);
float tmp_Num = ((int)(min*n))/n;
return tmp_Num ;
}

/**
* 重設(shè)音量
*/
protected void resetVolume(){
gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
//double gain = .5D; // number between 0 and 1 (loudest)
float dB = (float) (Math.log(gain) / Math.log(10.0) * 20.0);
gainControl.setValue(dB);
}

/**
* 設(shè)定聲道,-1.0f:只有左聲道, 0.0f:雙聲道,1.0f右聲道
* @param p
*/
public void setPan(float p){
pan = p;
resetPan();
}

/**
* 重設(shè)單雙道、雙聲道
*/
protected void resetPan(){
panControl = (FloatControl) clip.getControl(FloatControl.Type.PAN);
panControl.setValue(this.pan);
}

/**
* 設(shè)定靜音狀態(tài),true:靜音,false:不靜音
* @param m
*/
public void setMute(boolean m){
mute = m;
resetMute();
}

/**
* 重設(shè)靜音狀態(tài)
*
*/
protected void resetMute(){
muteControl = (BooleanControl) clip.getControl(BooleanControl.Type.MUTE);
muteControl.setValue(mute);
}

/**
*
* @return
*/
public int getFramePosition(){
try {
return clip.getFramePosition();
} catch (Exception e) {
return -1;
}
}

/**
* 取得音檔格式
* @return
*/
public AudioFormat getCurrentFormat(){
return format;
}

/**
* 取得音檔的串流
* @return
*/
public AudioInputStream getAudioInputStream(){
try {
AudioInputStream aiStream;

if (loadReference == null){
return null;
} else if (loadReference instanceof URL) {
URL url = (URL)loadReference;
aiStream = AudioSystem.getAudioInputStream(url);
} else if (loadReference instanceof File) {
File file = (File)loadReference;
aiStream = AudioSystem.getAudioInputStream(file);
} else if (loadReference instanceof AudioInputStream){
AudioInputStream stream = (AudioInputStream)loadReference;
aiStream = AudioSystem.getAudioInputStream(stream.getFormat(), stream);
stream.reset();
} else {

InputStream inputStream = (InputStream)loadReference;
aiStream = AudioSystem.getAudioInputStream(inputStream);
}

return aiStream;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

/**
* 目前音檔是否已存在
* @return
*/
public boolean isAudioLoaded(){
return loadReference!= null;
}

/**
* 取得剪輯音檔
* @return
*/
public Clip getClip() {
return clip;
}

/**
* 關(guān)閉音檔
*/
public void close(){
try {
if (clip != null)
clip.close();
if (currentSound != null)
currentSound.close();
loadReference = null;
} catch (Exception e){
//System.out.println("unloadAudio: " + e);
e.printStackTrace();
}

currentSound = null;
clip = null;
gainControl = null;
panControl = null;
dlInfo = null;
loadReference = null;
muteControl = null;
callbackTartet = null;
callbackObj = null;
}

}


查看完整回答
反對 回復(fù) 2022-08-08
  • 1 回答
  • 0 關(guān)注
  • 128 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號