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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使用 try and catch 時(shí)播放聲音

使用 try and catch 時(shí)播放聲音

慕慕森 2022-06-30 10:47:17
無法編譯。我正在嘗試在使用 try and catch 時(shí)播放聲音。wav 文件位于我的桌面上。我收到錯(cuò)誤消息,例如:AudioStream 無法解析為類型 AudioStream 無法解析為類型 AudioPlayer 無法解析。我不確定如何解決這個(gè)問題,我知道它很簡(jiǎn)單,import java.io.FileInputStream;import java.io.InputStream;public class PlayMySoundApplication{public static void main(String[] args)  throws Exception{// open the sound file as a Java input streamString applause2x = "/Users/pc/Desktop/applause2x.wav";InputStream in = new FileInputStream(applause2x);// create an audiostream from the inputstreamAudioStream audioStream = new AudioStream(in);// play the audio clip with the audioplayer classAudioPlayer.player.start(audioStream);
查看完整描述

2 回答

?
幕布斯7119047

TA貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超8個(gè)贊

為音頻添加導(dǎo)入,


import java.io.*;

import sun.audio.*;



public class PlayMySoundApplication

{

  public static void main(String[] args) 

  throws Exception

  {

    // open the sound file as a Java input stream

    String applause2x = "/Users/pc/Desktop/applause2x.wav";

InputStream in = new FileInputStream(applause2x);



    // create an audiostream from the inputstream

    AudioStream audioStream = new AudioStream(in);


    // play the audio clip with the audioplayer class

    AudioPlayer.player.start(audioStream);

  }

}


查看完整回答
反對(duì) 回復(fù) 2022-06-30
?
寶慕林4294392

TA貢獻(xiàn)2021條經(jīng)驗(yàn) 獲得超8個(gè)贊

我不知道您要使用什么聲音庫。


如果您使用的是不錯(cuò)的 JDK 版本,那應(yīng)該可以解決問題:


import java.io.File;

import java.io.IOException;


import javax.sound.sampled.AudioFormat;

import javax.sound.sampled.AudioInputStream;

import javax.sound.sampled.AudioSystem;

import javax.sound.sampled.DataLine;

import javax.sound.sampled.LineUnavailableException;

import javax.sound.sampled.SourceDataLine;

import javax.sound.sampled.UnsupportedAudioFileException;


public class MakeSound {


    public static void main(String[] args) throws LineUnavailableException, UnsupportedAudioFileException, IOException {

        playSound("test.wav");

    }


    public static void playSound(String strFilename)

            throws LineUnavailableException, UnsupportedAudioFileException, IOException {


        File soundFile = new File(strFilename);


        AudioInputStream audioStream = AudioSystem.getAudioInputStream(soundFile);


        AudioFormat audioFormat = audioStream.getFormat();


        DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);

        try (SourceDataLine sourceLine = (SourceDataLine) AudioSystem.getLine(info);) {

            sourceLine.open(audioFormat);

            sourceLine.start();


            int nBytesRead = 0;

            byte[] abData = new byte[128000];

            while (nBytesRead != -1) {

                nBytesRead = audioStream.read(abData, 0, abData.length);

                if (nBytesRead > 0) {

                    sourceLine.write(abData, 0, nBytesRead);

                }

            }


            sourceLine.drain();

        }

    }

}

!


查看完整回答
反對(duì) 回復(fù) 2022-06-30
  • 2 回答
  • 0 關(guān)注
  • 150 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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