Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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  
  how do you play MID files using Java?  (Read 3473 times)
0 Members and 1 Guest are viewing this topic.
Offline nardev

Senior Newbie





« Posted 2005-11-23 11:29:11 »

I tried this....Help please!?

code:
public void playMidiFrom(String path) {
       try {
           Sequence midi = MidiSystem.getSequence(this.getClass().getClassLoader().getResource(path));
           Sequencer player = MidiSystem.getSequencer();
           player.open();
           player.setSequence(midi);
           player.start();
       } catch (IOException e) {
          System.out.println("else");
           e.printStackTrace();
       } catch (InvalidMidiDataException e) {
          System.out.println("Invalid MIDI data");
           e.printStackTrace();
       } catch (MidiUnavailableException e) {
          System.out.println("No midi");
           e.printStackTrace();
       }
  }

i get this error:
java.lang.IllegalArgumentException: Requested device not installed: null
   at javax.sound.midi.MidiSystem.getGenericDevice(MidiSystem.java:1073)
   at javax.sound.midi.MidiSystem.getSequencer(MidiSystem.java:277)
   at CroAsteroids1.lib.sounds.Sounds.playMidiFrom(Sounds.java:89)
   at CroAsteroids1.lib.sounds.Sounds.<init>(Sounds.java:83)
   at CroAsteroids1.lib.Asteroids.init(Asteroids.java:283)
   at CroAsteroids1.lib.Asteroids.run(Asteroids.java:116)
   at CroAsteroids1.lib.Asteroids.main(Asteroids.java:110)

I can play mid's in Winamp. And i am not trying to play it in winamp at the same time while running the code. Using windows xp.

<a href="http://vedsta5.freeserverhost.com/">CroAsteroids</a> - Shoot asteroids while doing math equations.
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #1 - Posted 2005-11-23 13:58:07 »

You could try the code over there:
http://www.java-gaming.org/forums/index.php?topic=406.0

弾幕 ☆ @mahonnaiseblog
Offline nardev

Senior Newbie





« Reply #2 - Posted 2005-11-24 13:59:32 »

I am having problems with the following line of code:

1  
o = MidiSystem.getSequencer();


This is the error i get:

1  
2  
3  
4  
Exception in thread "main" java.lang.IllegalArgumentException: Requested device not installed: null
   at javax.sound.midi.MidiSystem.getGenericDevice(MidiSystem.java:1073)
   at javax.sound.midi.MidiSystem.getSequencer(MidiSystem.java:277)
   at CroAsteroids1.lib.SimpleMidiPlayer.main(SimpleMidiPlayer.java:176)


Any ideas?

<a href="http://vedsta5.freeserverhost.com/">CroAsteroids</a> - Shoot asteroids while doing math equations.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline c_lilian

Senior Member


Projects: 1


Java games will probably rock someday...


« Reply #3 - Posted 2005-11-24 14:18:20 »

getSequencer(true) ?

(starting from 1.5 : this will connect the sequencer to the default internal synthetizer, if false, sound will be output by the os, not the java runtime).

Lilian

Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #4 - Posted 2005-11-24 14:40:40 »

There was no need to push both threads.

Do you have a soundbank installed? I still dont know that.

I have one installed and this program works just fine...

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  
import javax.sound.midi.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class MidiTest{

   private Sequencer sequencer = null;
   private Synthesizer synthesizer;
   public MidiTest(){
      try{
         synthesizer = MidiSystem.getSynthesizer();
         synthesizer.open();
         sequencer = MidiSystem.getSequencer();
         sequencer.open();
         sequencer.setSequence(new BufferedInputStream(getClass().getResourceAsStream("midi.mid")));
         sequencer.start();

         JFrame f=new JFrame("MidiTest");
         JLabel label=new JLabel("close to stop playback");
         label.setHorizontalAlignment(SwingConstants.CENTER);
         f.setSize(300,100);
         f.getContentPane().add(label);
         f.setVisible(true);
         f.addWindowListener(
            new WindowAdapter(){
               public void windowClosing(WindowEvent e){
                  sequencer.stop();
                  synthesizer.close();
                  System.exit(0);
               }
            }
         );
      }catch(Exception e){
         e.printStackTrace();
         System.exit(1);
      }
   }
   public static void main(String[]args){
      new MidiTest();
   }
}


@c_lilian

getSequencer(true)? What should that change?

getSequencer() "This method is equivalent to calling getSequencer(true)." (javadoc)

弾幕 ☆ @mahonnaiseblog
Offline c_lilian

Senior Member


Projects: 1


Java games will probably rock someday...


« Reply #5 - Posted 2005-11-24 14:59:58 »

ahh well, so it was getSequencer(false) Wink

As i've subscribed to the javasound mailing list, this is something that shows up somtimes, and as of 1.5, you can plug the sequencer into the java software synthetiser or to the soundcard. I was thinking the problem could be related to some incorrect settings preventing the sequencer to be properly connected to the soundcard...

Lilian

Offline nardev

Senior Newbie





« Reply #6 - Posted 2005-11-25 10:02:33 »

I also noticed a problem which might make my problem more clear to somebody...

1  
2  
3  
4  
5  
MidiDevice.Info[] info = MidiSystem.getMidiDeviceInfo();
         System.out.println("Info=" + info.length);
         for (int i = 0; i < info.length; i++) {
              System.out.println(info[i]);
         }


returns "0". Like i don't have a midi device on the system?

My friend with the same exact code gets:
Info=4
Java Sound Synthesizer
Java Sound Sequencer
Microsoft MIDI Mapper
Microsoft GS Wavetable SW Synth

I don't get it. I've been googling for a few days now and no luck. Here and there i find a comment saying it is not possible except by using Timidi or something like that. I looked that up to and i really don't understand where the problem is. My buddy uses the same code and it works for him. I can play the midi's using winamp.

the new error i get is:
java.lang.IllegalArgumentException: Requested device not installed: null
   at javax.sound.midi.MidiSystem.getGenericDevice(MidiSystem.java:1073)
   at javax.sound.midi.MidiSystem.getSynthesizer(MidiSystem.java:242)

I can't use the getSequencer(boolean) cause i don't have Java 1.5. At work we are using 1.4.

I can play wav's using java...

<a href="http://vedsta5.freeserverhost.com/">CroAsteroids</a> - Shoot asteroids while doing math equations.
Offline c_lilian

Senior Member


Projects: 1


Java games will probably rock someday...


« Reply #7 - Posted 2005-11-25 10:19:47 »

I suggest posting this question on the javasound mailing list as it should give you an answer in less than a day...

look ere   http://archives.java.sun.com/archives/javasound-interest.html

there's a bunch of folks always ready to help people there, including the previous lead developer of the javax.sound from sun.

Lilian

Offline nardev

Senior Newbie





« Reply #8 - Posted 2005-11-25 13:18:27 »

Ok. I did it. Now i suppose wait for a response. I'll get back with it ASAP.

<a href="http://vedsta5.freeserverhost.com/">CroAsteroids</a> - Shoot asteroids while doing math equations.
Offline nardev

Senior Newbie





« Reply #9 - Posted 2005-11-26 13:17:03 »

this is what i got:
--------------------------------------------------------------------------------
try
info.getName()
info.getDescription()

-------------------------------------------------------------------------------
You should get Java 1.5, as the midi sequencer gives good timing. Also
read :

http://java.sun.com/j2se/1.5.0/docs/relnotes/features.html#js

Albert

--------------------------------------------------------------------------------
that's alright:
- earlier versions of the JDK did not support external MIDI ports or
hardware synthesizers
- if the internal Java Sound synthesizer cannot be initialized, you
will
not have a single MIDI device accessible from Java

The internal Java synth needs:
- a soundcard with CD quality capability
- an installed Java soundbank (check java.sun.com/sound or this mailing
list's archive how to install a soundbank)

Florian

<a href="http://vedsta5.freeserverhost.com/">CroAsteroids</a> - Shoot asteroids while doing math equations.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

ctomni231 (34 views)
2014-07-18 06:55:21

Zero Volt (30 views)
2014-07-17 23:47:54

danieldean (25 views)
2014-07-17 23:41:23

MustardPeter (27 views)
2014-07-16 23:30:00

Cero (42 views)
2014-07-16 00:42:17

Riven (44 views)
2014-07-14 18:02:53

OpenGLShaders (33 views)
2014-07-14 16:23:47

Riven (34 views)
2014-07-14 11:51:35

quew8 (30 views)
2014-07-13 13:57:52

SHC (66 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!