11package com .redomar .game .audio ;
22
3+ import com .redomar .game .script .PrintTypes ;
4+ import com .redomar .game .script .Printing ;
5+
36import javax .sound .sampled .*;
47import java .io .File ;
58
@@ -8,20 +11,25 @@ public class AudioHandler {
811
912 private Clip clip ;
1013 private boolean active = false ;
14+ private Printing p = new Printing ();
1115
1216 public AudioHandler (String path ){
13- initiate (path );
17+ check (path );
1418 }
1519
1620 public AudioHandler (File file ){
21+ check (file .toString ());
22+ }
23+
24+ private void check (String path ){
1725 try {
18- if (file . toString () != "" ){
19- initiate (file . toString () );
26+ if (path != "" ){
27+ initiate (path );
2028 } else {
2129 throw new NullPointerException ();
2230 }
2331 } catch (NullPointerException e ){
24- System . err . println ("Destination Cannot be empty" );
32+ p . print ("Destination Cannot be empty" , PrintTypes . ERROR );
2533 throw e ;
2634 }
2735 }
@@ -44,15 +52,21 @@ private void initiate(String path){
4452 clip .open (decodedAudioInputStream );
4553 } catch (Exception e ){
4654 System .err .println (e .getStackTrace ());
55+ p .print ("Audio Failed to initiate" , PrintTypes .ERROR );
4756 }
4857 }
4958
5059 public void play (){
51- if (clip == null ) return ;
52- stop ();
53- clip .setFramePosition (0 );
54- clip .start ();
55- active = true ;
60+ try {
61+ if (clip == null ) return ;
62+ stop ();
63+ clip .setFramePosition (0 );
64+ clip .start ();
65+ active = true ;
66+ } catch (Exception e ) {
67+ p .print ("Audio Failed to play" , PrintTypes .ERROR );
68+ throw e ;
69+ }
5670 }
5771
5872 public void setVolume (float velocity ){
0 commit comments