下記のコードでフルパスを指定すれば、エラーが起きないのですが、ファイルネームだけだと
エラーになります。
音声ファイルは、クラスファイルと同一の場所に入れています。
何卒、ご教示お願い申し上げます。
import
1import java.io.FileNotFoundException; 2import java.io.InputStreamReader; 3 4import javazoom.jl.decoder.JavaLayerException; 5 6public class GameMain implements Runnable { 7 // Super_saiyajin goku = new Super_saiyajin("孫悟空"); 8 // Super_saiyajin veji = new Super_saiyajin("ベジータ"); 9 // Namekku pikkoro = new Namekku("ピッコロ"); 10 public static void main(String[] args) { 11 GameMain gameMain = new GameMain(); 12 Thread thread = new Thread(gameMain); 13 thread.start(); 14 Sound gThread = new Sound(); 15 gThread.start(); 16 Arasuji arasuji = new Arasuji(); 17 arasuji.start(); 18 } 19 20 public void run() { 21 Sound onsei = new Sound(); 22 try { 23 onsei.play("Op_Dragonball_onnsei.mp3"); 24 } catch (FileNotFoundException | JavaLayerException e) { 25 e.printStackTrace(); 26 } 27 28 Sound hSound = new Sound(); 29 hSound.dokidoki(); 30 31 System.out.println("ようこそ"); 32 try{ 33 BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); 34 35 String line = reader.readLine(); 36 System.out.println(line + "ですね"); 37 }catch 38 (Exception e){ 39 40 } 41 } 42} 43 44コード
import
1import java.io.FileInputStream; 2import java.io.FileNotFoundException; 3import java.io.IOException; 4 5import javazoom.jl.decoder.JavaLayerException; 6import javazoom.jl.player.Player; 7 8public class Sound extends Thread { 9 10 private Player player; 11 12 private BufferedInputStream stream; 13 14 @Override 15 public void run() { 16 try { 17 play("Op_Dragonball_2.mp3"); 18 } catch (FileNotFoundException | JavaLayerException e1) { 19 e1.printStackTrace(); 20 } 21 } 22 23 public void play(String file) 24 throws JavaLayerException, FileNotFoundException { 25 stream = new BufferedInputStream((new FileInputStream(file))); 26 player = new Player(stream); 27 player.play(); 28 } 29 30 public void close() throws IOException, JavaLayerException { 31 if (player != null) { 32 player.close(); 33 } 34 if (stream != null) { 35 stream.close(); 36 } 37 } 38 39 public void dokidoki() { 40 try { 41 play("heart1.mp3"); 42 play("game_princess-faint1.mp3"); 43 play("game_princess-start2.mp3"); 44 45 } catch (Exception e) { 46 } 47 } 48コード
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/07 01:16
2018/08/07 02:11