Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (577)
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 play a midi file?  (Read 1307 times)
0 Members and 1 Guest are viewing this topic.
Offline nhmllr

Senior Duke


Medals: 1
Projects: 3


slow and steady...


« Posted 2013-01-06 04:10:52 »

Really straightforward question here. I need to add midi music into my game. I already have the files. How do I load the files then loop their playing?

I'd appreciate some code or tutorials that you know for a fact work. I've looked at a few online tutorials but none have them have yet worked. I think they might have worked for some previous versions of java but not anymore.

Also, I'm not using any special libraries for this game and I'd appreciate if I didn't have to use LWJGL or anything of the like.

Thanks!
Offline ReBirth
« Reply #1 - Posted 2013-01-06 04:19:33 »

I remember somewhere princec talking about how bad MIDI is.

Have you read this?

Anyway, is there a good reason why you prefer MIDI on top of OGG or MP3?

Offline nhmllr

Senior Duke


Medals: 1
Projects: 3


slow and steady...


« Reply #2 - Posted 2013-01-06 04:40:09 »

That post seems to be trying to play a specific midi note, not a song file.

I dunno I just have a bunch of good songs in midi files that I want in my game. Midi files are small and fast, which is what I would prefer. MP3s are huge files.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline philfrei
« Reply #3 - Posted 2013-01-06 04:46:35 »

I'm curious to see what the answer will be...am going to tag along here.

MIDI data takes much less memory than even ogg. And isn't it supposed to be possible to load a set of playback sounds from Java? I haven't really played with it yet in Java. (I do a LOT with MIDI in my composing environments: Finale and Sonar Homestudio.)

"It's after the end of the world! Don't you know that yet?"
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #4 - Posted 2013-01-06 04:58:49 »

The main problem with Midi is that you can't be sure whether the user has a soundbank installed.  If a sound bank is not installed, then depending on the platform, you either get no sound, or a fail-over to using any hardware MIDI support on the machine (PC).  While you can supply and load your own sound bank, there were some bugs associated with that.  I vaguely remember it didn't work correctly on the PC.

There are a lot of at www.jsresources.org
The website doesn't appear to be actively updated, so doesn't cover any bug fixes in later java versions.

Time flies like a bird. Fruit flies like a banana.
Offline nsigma
« Reply #5 - Posted 2013-01-06 18:09:14 »

The main problem with Midi is that you can't be sure whether the user has a soundbank installed.  If a sound bank is not installed, then depending on the platform, you either get no sound, or a fail-over to using any hardware MIDI support on the machine (PC).  While you can supply and load your own sound bank, there were some bugs associated with that.  I vaguely remember it didn't work correctly on the PC.

Most of these issues should be a thing of the past now that Gervill is available in Java 7 / OpenJDK.

See here and here.

Midi files are small and fast, which is what I would prefer.

By the time you've included a decent soundbank, MIDI files are neither small or fast!  ReBirth mentions princec's comments on MIDI recently - I defended the potential of Gervill for live uses (eg. music / SFX that changes in response to user interaction / game states).  If you just want to play a file - don't use MIDI!  If you have some particular files you want to use, pre-render them to MP3, OGG, etc.

Praxis LIVE - open-source intermedia toolkit and live interactive visual editor
Digital Prisoners - interactive spaces and projections
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #6 - Posted 2013-01-06 19:13:48 »

Ah, I hadn't realised that the soundbank formats had changed.  The good news is it should be possible to do ones own soundbanks without having to buy the beatnik tool. Obviously not until Java7 has got a high install %age.  Still, I should go and take a look at what can be done.  Incidentally, does Java 7 install a soundbank (of whatever format) as standard, or is it still optional?

Time flies like a bird. Fruit flies like a banana.
Offline nsigma
« Reply #7 - Posted 2013-01-06 19:43:36 »

I think there is only an emergency (read useless!  Wink ) soundbank in the JRE so you'll have to ship your own.  You can ship Gervill yourself with Java 6 too.

Incidentally, as I mentioned in the other thread mentioned above, I wouldn't recommend using static MIDI files.  However, Gervill is a great synth / DSP engine which could be used for some cool game audio, or perhaps with JFugue to create some interesting live music that responds to game states / user interaction.

Praxis LIVE - open-source intermedia toolkit and live interactive visual editor
Digital Prisoners - interactive spaces and projections
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #8 - Posted 2013-01-06 19:46:34 »

Roger that on the Emergency Soundbank.

It also appears possible to create your own soundbank on the fly.  Most interesting.

Time flies like a bird. Fruit flies like a banana.
Offline doos

Senior Duke


Medals: 2
Projects: 2


Here be random


« Reply #9 - Posted 2013-01-20 17:28:18 »

Got a link for creating soundbanks on the fly? Sounds interesting!

I'd like to point out that including an entire midi soundbank might be larger than a single mp3 or ogg and have possible licensing issues, depends how much music you want, really.. There is usually a soundbank bundled with the jre, getDefaultSoundbank worked fine for me in windows for jre7, I had to copy the gm from libs, I think in jre6 to use that one.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline alesky

Junior Duke


Medals: 3
Exp: 15 years


mmm....


« Reply #10 - Posted 2013-01-20 18:02:43 »

hi man this is the easy answer to your question, pure java no other libs
hire i'm using the old applet lib, you can run wiht JVM 1.1 until JVM 1.7

mcdonald.mid is an old midi file, susbtitute with your

if u what to use pure java but you need something little more complex, you have to use JSA (java sound api)

JSA this is the official doc
http://docs.oracle.com/javase/tutorial/sound/index.html

this is a complex demo for ORACLE that will show to use the power of JSA
http://www.oracle.com/technetwork/java/index-139508.html


remeber you have to create a separate a thread to run the music in loop

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public class McDonald {

 public static void main(String[] args){
     AudioClip mcdClip =  Applet.newAudioClip( McDonald.class.getClassLoader().getResource("mcdonald.mid") );
     mcdClip.play();        
     // mcdClip.loop(); //if u what loop  
   
     while(true){
        System.out.println("manage music in a separate thread not in the main thread like this");
     }
  }
}


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.

Longarmx (49 views)
2014-10-17 03:59:02

Norakomi (38 views)
2014-10-16 15:22:06

Norakomi (31 views)
2014-10-16 15:20:20

lcass (34 views)
2014-10-15 16:18:58

TehJavaDev (65 views)
2014-10-14 00:39:48

TehJavaDev (65 views)
2014-10-14 00:35:47

TehJavaDev (55 views)
2014-10-14 00:32:37

BurntPizza (72 views)
2014-10-11 23:24:42

BurntPizza (43 views)
2014-10-11 23:10:45

BurntPizza (84 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!