Ngewe
SMM Automation Expert
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
200 XP
This tutorial will teach you how to create a program that will load and play a MIDI sound file in java. We all know that MIDI or Musical Instrument Digital Interface) is a sound designed for recording and playing back music on digital synthesizers that is supported by many makes of personal computer sound cards. It has .mid extension file.
So, now let's start this tutorial!
1. Open JCreator or NetBeans and make a java program with a file name of playMIDI.java.
2. Import the following package library:
3. Now, you have to put your MIDI file on the same folder with the your program. Then access the MIDI file with this code:
midifile.mid is the filename of the MIDI filie and you can change this to your MIDI file name.
4. Create a sequencer for the sequence of the MIDI file.
5. To start playing your MIDI file, have this code below:
Output:
When pressing the run button in your Java software, the MIDI filename will automatically play.
Here's the full code of this tutorial:
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Best Regards,
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware
Download
So, now let's start this tutorial!
1. Open JCreator or NetBeans and make a java program with a file name of playMIDI.java.
2. Import the following package library:
- import
java.io.*
;
//used to access the File class
- import
javax.sound.midi.*
;
//used to access MidiSystem, Sequence, and Sequencer class
3. Now, you have to put your MIDI file on the same folder with the your program. Then access the MIDI file with this code:
- // From file
- Sequence
sequence =
MidiSystem
.getSequence
(
new
File
(
"midifile.mid"
)
)
;
midifile.mid is the filename of the MIDI filie and you can change this to your MIDI file name.
4. Create a sequencer for the sequence of the MIDI file.
- Sequencer
sequencer =
MidiSystem
.getSequencer
(
)
;
- sequencer.open
(
)
;
- sequencer.setSequence
(
sequence)
;
5. To start playing your MIDI file, have this code below:
- // Start playing
- sequencer.start
(
)
;
Output:
When pressing the run button in your Java software, the MIDI filename will automatically play.
Here's the full code of this tutorial:
- import
java.io.File
;
- import
javax.sound.midi.MidiSystem
;
- import
javax.sound.midi.Sequence
;
- import
javax.sound.midi.Sequencer
;
- public
class
playMIDI {
- public
static
void
main(
String
[
]
argv)
throws
Exception
{
- // From file
- Sequence
sequence =
MidiSystem
.getSequence
(
new
File
(
"midifile.mid"
)
)
;
- // Create a sequencer for the sequence
- Sequencer
sequencer =
MidiSystem
.getSequencer
(
)
;
- sequencer.open
(
)
;
- sequencer.setSequence
(
sequence)
;
- // Start playing
- sequencer.start
(
)
;
- }
- }
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Best Regards,
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware
Download
You must upgrade your account or reply in the thread to view the hidden content.