Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (753)
Games in Android Showcase (228)
games submitted by our members
Games in WIP (842)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Problem loading music with TinySound library  (Read 1762 times)
0 Members and 1 Guest are viewing this topic.
Offline rikqt

Senior Newbie





« Posted 2013-12-27 13:12:53 »

I have a problem loading the music with TinySound library.
I usually load every image like "res/.../fileName.ext", but now I've no idea what I'm missing...

1  
2  
3  
        TinySound.init();
        Music music = TinySound.loadMusic("res/music_tracks/Rayman_2_Cut.ogg");
        music.play(true);


Output:

1  
2  
3  
Unable to find resource /res/music_tracks/Rayman_2_Cut.ogg!
Exception in thread "main" java.lang.NullPointerException
   at poker.state.StartScreenState.init(StartScreenState.java:45)

Offline Longarmx
« Reply #1 - Posted 2013-12-27 15:49:02 »

Have you double checked that the path is EXACTLY the same? How are your files located?

Offline rikqt

Senior Newbie





« Reply #2 - Posted 2013-12-27 16:27:26 »

Yes! This link "res/music_tracks/Rayman_2_Cut.ogg",  worked fine for Slick2D Music.

Quote
How are your files located?

- Documents
   - NetBeansProjects
      - Rayman2D
         + nbproject
         + src
         ...
         - res
           + gui
           ...
           - music_tracks
             (.ogg files)



Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline rikqt

Senior Newbie





« Reply #3 - Posted 2013-12-27 18:47:08 »

But not for this library... Any one ?
Offline Axeman

Senior Devvie


Medals: 7



« Reply #4 - Posted 2013-12-27 19:32:30 »

I have noticed a similar problem when I´m trying to add new .png files in Eclipse. Sometimes, no matter how much I update, I´m getting an error that the file can´t be found. Then I have to open my .png files in the text editor in Eclipse and just add and delete a character, just so I can save it again. After that it works. It´s silly, really, but no one seems to know what to do about this problem so I guess I´ll just continue doing it. Smiley

If you are using Eclipse you can try it. Then at least you can rule out if that is the problem...

Offline tyeeeee1
« Reply #5 - Posted 2013-12-27 19:46:58 »

Here is how I load my files:

1  
2  
3  
4  
5  
Audio.storeSound("hit_shield", TinySound.loadSound(Audio.class.getResource("/audio/hit_shield.wav")));
      Audio.storeSound("shoot", TinySound.loadSound(Audio.class.getResource("/audio/shoot.wav")));
      Audio.storeSound("alien_death", TinySound.loadSound(Audio.class.getResource("/audio/alien_death.wav")));
      Audio.storeSound("player_hit", TinySound.loadSound(Audio.class.getResource("/audio/player_hit.wav")));
      Audio.storeSound("player_upgrade", TinySound.loadSound(Audio.class.getResource("/audio/player_upgrade.wav")));


Just do / isntead of /res/ I think.


Edit:
For the guy above me. Did you right click on your res folder and hit refresh after adding files/editing them?
Offline rikqt

Senior Newbie





« Reply #6 - Posted 2013-12-27 23:52:06 »

Just do / instead of /res/ I think.

That did not fix the problem...
Output:
1  
2  
Unable to find resource /music_tracks/Rayman_2_Cut.ogg!
Exception in thread "main" java.lang.NullPointerException


Here is how I load my files:

1  
2  
3  
4  
5  
Audio.storeSound("hit_shield", TinySound.loadSound(Audio.class.getResource("/audio/hit_shield.wav")));
      Audio.storeSound("shoot", TinySound.loadSound(Audio.class.getResource("/audio/shoot.wav")));
      Audio.storeSound("alien_death", TinySound.loadSound(Audio.class.getResource("/audio/alien_death.wav")));
      Audio.storeSound("player_hit", TinySound.loadSound(Audio.class.getResource("/audio/player_hit.wav")));
      Audio.storeSound("player_upgrade", TinySound.loadSound(Audio.class.getResource("/audio/player_upgrade.wav")));



Tell me, from which library did u pull Audio class and what are u doing with it after loading the sound?
Offline tyeeeee1
« Reply #7 - Posted 2013-12-28 00:47:39 »

Audio is one of my personal utility classes that I use to control TinySound with.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
package utilities;

/**
 * This class allows a quick way to utilize TinySound to play music and sound clips.
 *
 * @author Valkryst
 * --- Last Edit 23-Sep-2013
 */

import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

import kuusisto.tinysound.Music;
import kuusisto.tinysound.Sound;
import kuusisto.tinysound.TinySound;

public class Audio {
   public static boolean isDirectionalSoundOn = true;
   private static HashMap<String, Sound> storedSounds = new HashMap<String, Sound>();
    private static Music music; // The music file that is currently being played.

    /**
     * Prepares TinySound for use.
     */

    public static void initialize() {
       TinySound.init();
    }
   
    /**
     * This method plays a music file.
     * @param path The path to the music file that is going to be played.
     * @param loop Whether the music file should be played on loop or not.
     */

    public static void playMusic(final String path, final boolean loop) {
      music = TinySound.loadMusic(Audio.class.getResource(path));
     
      if(loop) {
          music.loop();
          music.play(true);
      }
    }

    /**
     * Set the volume of the music file that is currently being played.
     * @param volume The volume level that the currently playing music file should be played at.
     */

    public static void setVolume(final double volume) {
       music.setVolume(volume);
    }
   
    /**
     * Set the pan of the music file that is currently being played.
     * @param pan The pan that the currently playing music file should use.
     */

    public static void setPan(final double pan) {
       music.setPan(pan);
    }

    /**
     * Stops the currently playing music file.
     */

    public static void stopMusic() {
       music.stop();
    }
   
    /**
     * Pauses the currently playing music file.
     */

    public static void pauseMusic() {
       music.pause();
    }
   
    /**
     * Resumes the currently playing music file.
     */

    public static void resumeMusic() {
       music.resume();
    }
   
    /**
     * Stored the specified sound into a hashmap for use without reloading the file every use.
     * @param nameIn The name identifier of the sound to store.
     * @param soundIn The sound to store.
     */

    public static void storeSound(final String nameIn, final Sound soundIn) {
       storedSounds.put(nameIn, soundIn);
    }
   
    /**
     * This method plays a stored sound file.
     * @param nameIn The name identifier of the stored sound to play.
     * @param volumeIn The volume at which to play the stored sound.
     * @param xCoordIn the x coordinate of the object creating the
     */

    public static void playStoredSound(final String nameIn, final double volumeIn, final int xCoordIn) {
       if(isDirectionalSoundOn) {
          double pan = -1;
         
          if(xCoordIn >= 768) {
             pan = 1;
          } else if(xCoordIn >= 512) {
             pan = 0.66;
          } else if(xCoordIn >= 256) {
             pan = 0.33;
          } else {
             pan = 0;
          }
         
          storedSounds.get(nameIn).play(volumeIn, pan);
       } else {
          storedSounds.get(nameIn).play(volumeIn);
       }
    }
   
    /**
     * This method plays a sound file.
     * @param path The path to the music file that is going to be played.
     * @param loop Whether the music file should be played on loop or not.
     * @param loops The number of times to play the sound file.
     * @param volumeIn The volume at which to play the stored sound.
     */

    public static void playSound(final String path, final boolean loop, final int loops, final double volumeIn) {
      Sound sound = TinySound.loadSound(Audio.class.getResource(path));
     
      if (loop) {
          for (int i = 0; i < loops; i++) {
            sound.play();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
               Logger logger = Logger.getLogger(Audio.class.getName());
               logger.log(Level.SEVERE, e.toString(), e);
            }
          }
      } else {
          sound.play(volumeIn);
      }
    }

    /**
     * Shuts down TinySound.
     */

    public static void shutdown() {
       TinySound.shutdown();
    }
}


Derp, just noticed that you're using Netbeans. Can't help there, I'm using eclipse and the code I showed you works fine.
Pages: [1]
  ignore  |  Print  
 
 

 
nelsongames (17 views)
2018-04-24 18:15:36

nelsongames (13 views)
2018-04-24 18:14:32

ivj94 (587 views)
2018-03-24 14:47:39

ivj94 (50 views)
2018-03-24 14:46:31

ivj94 (400 views)
2018-03-24 14:43:53

Solater (65 views)
2018-03-17 05:04:08

nelsongames (110 views)
2018-03-05 17:56:34

Gornova (175 views)
2018-03-02 22:15:33

buddyBro (730 views)
2018-02-28 16:59:18

buddyBro (93 views)
2018-02-28 16:45:17
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!