confusing error during realize of mediaplayer

S

SlowLearner

I'm geting a strange error when I try and play a simple midi 1.0 file.
The file is definitely valid, and plays in every other midi enabled
application I have.
The error occurs when I try and realize() the player. After about 3
seconds I get

Error: Unable to prefetch
com.sun.media.content.audio.midi.Handler$MidiController@c3c749


my code is

public class form1 extends javax.swing.JFrame {

File fp = new File("C:/TEST.MID");
Player player;

/** Creates new form form1 */
public form1() {
initComponents();
this.setVisible(true);
if (!fp.exists()) return;
try {

player=Manager.createPlayer(fp.toURL());

} catch (MalformedURLException ex) {
ex.printStackTrace();
} catch (NoPlayerException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}

player.addControllerListener( new ControllerListener() {
public void controllerUpdate( ControllerEvent ce) {
if ( ce instanceof RealizeCompleteEvent)
{
Component visual = player.getVisualComponent();
Component control =
player.getControlPanelComponent();
if (visual != null)
getContentPane().add(visual);
getContentPane().add(control);
pack();
player.start();
}
}
});
player.realise(); // here's where it says it can't preload
sun...midi etc

}


any help would be appreciated
 
S

SlowLearner

Ok I've removed the call to init components and spelt realize correctly
this time. The code now reads and still produces the same error as
before at runtime.




import java.io.*;
import javax.media.*;
import java.net.*;
import java.awt.*;

/**
*
* @author user1
*/
public class Form1 extends javax.swing.JFrame {

/** Creates new form Form1 */

File fp = new File("C:/TEST.MID");
Player player;

/** Creates new form form1 */
public Form1() {
// initComponents();
this.setVisible(true);
if (!fp.exists()) return;
try {
player=Manager.createPlayer(fp.toURL());
} catch (MalformedURLException ex) {
ex.printStackTrace();
} catch (NoPlayerException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}

player.addControllerListener( new ControllerListener() {
public void controllerUpdate( ControllerEvent ce) {
if ( ce instanceof RealizeCompleteEvent)
{
Component visual = player.getVisualComponent();
Component control =
player.getControlPanelComponent();
if (visual != null)
getContentPane().add(visual);
getContentPane().add(control);
pack();
player.start();
}
}
});
player.realize();


}

I pasted everything in the original post from compilable code. The only
line I typed in on the original post is the realise(); line because I
originally had it in a button event handler. Hence the mistake. Sorry!
I didn't realise I'd made a mistake, sorry to of wasted your time
earlier. However this code should compile.

I'm using netbeans 5.5 ide.
JDK 1.5.0_09 same number jre
windows XP Home Service pack 2

I dont know have a website to post a link to my test3.mid file. However
the code gives the same error with every single midi file I try. So
just pick your favourite midi file and you'll replicate the error, no
problem! If you give it an mp3 file it runs ok, but not midi files.

I should point out perhaps incase there's yet another silly mistake
somewhere, that I picked the name slowlearner for a reason. I suffered
chemical damage to my brain in 1978 from a pesticide accident. It's
only about a 18 months since I've been able to even watch TV or read
let alone program. So I am litteraly a slow learner.
 
O

Oliver Wong

SlowLearner said:
[most of the code snipped]
import javax.media.*;

This import requires that JMF (Java Media Framework) be installed. I
don't have it installed here, so I can't help other than to mention this as
a heads-up to other potential helpers. Next time, if you have a problem with
JMF, you might want to mention JMF in the subject line.

- Oliver
 
J

John Ersatznom

Oliver said:
This import requires that JMF (Java Media Framework) be installed. I
don't have it installed here, so I can't help other than to mention this as
a heads-up to other potential helpers. Next time, if you have a problem with
JMF, you might want to mention JMF in the subject line.

The word "mediaplayer" in the subject line is something of a clue. :)
 
K

Knute Johnson

SlowLearner said:
Ok I've removed the call to init components and spelt realize correctly
this time. The code now reads and still produces the same error as
before at runtime.




import java.io.*;
import javax.media.*;
import java.net.*;
import java.awt.*;

/**
*
* @author user1
*/
public class Form1 extends javax.swing.JFrame {

/** Creates new form Form1 */

File fp = new File("C:/TEST.MID");
Player player;

/** Creates new form form1 */
public Form1() {
// initComponents();
this.setVisible(true);
if (!fp.exists()) return;
try {
player=Manager.createPlayer(fp.toURL());
} catch (MalformedURLException ex) {
ex.printStackTrace();
} catch (NoPlayerException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}

player.addControllerListener( new ControllerListener() {
public void controllerUpdate( ControllerEvent ce) {
if ( ce instanceof RealizeCompleteEvent)
{
Component visual = player.getVisualComponent();
Component control =
player.getControlPanelComponent();
if (visual != null)
getContentPane().add(visual);
getContentPane().add(control);
pack();
player.start();
}
}
});
player.realize();


}

I pasted everything in the original post from compilable code. The only
line I typed in on the original post is the realise(); line because I
originally had it in a button event handler. Hence the mistake. Sorry!
I didn't realise I'd made a mistake, sorry to of wasted your time
earlier. However this code should compile.

I'm using netbeans 5.5 ide.
JDK 1.5.0_09 same number jre
windows XP Home Service pack 2

I dont know have a website to post a link to my test3.mid file. However
the code gives the same error with every single midi file I try. So
just pick your favourite midi file and you'll replicate the error, no
problem! If you give it an mp3 file it runs ok, but not midi files.

I should point out perhaps incase there's yet another silly mistake
somewhere, that I picked the name slowlearner for a reason. I suffered
chemical damage to my brain in 1978 from a pesticide accident. It's
only about a 18 months since I've been able to even watch TV or read
let alone program. So I am litteraly a slow learner.

It compiles but doesn't run without a main(). I added a main and it
compiles and runs my mpg file. I don't have a mid file to test with. I
think you can post attachments on this list but I haven't tried it. Post
a small file that duplicates your problem and I'll look at it. If you
can't post attachments, email me a small file.
 
S

SlowLearner

Knute said:
It compiles but doesn't run without a main(). I added a main and it
compiles and runs my mpg file. I don't have a mid file to test with. I
think you can post attachments on this list but I haven't tried it. Post
a small file that duplicates your problem and I'll look at it. If you
can't post attachments, email me a small file.

--



Knute Johnson
email s/nospam/knute/


If you pop over to Roedy's website you'll find plenty of midi files to
try. Even JmStudio cannot play them on my 3 machines. (I tried emailing
you but it bounced)
 
O

Oliver Wong

John Ersatznom said:
The word "mediaplayer" in the subject line is something of a clue. :)

You can write a media player using only the javax.sound.midi and
javax.sound.sampled packages.

- Oliver
 
K

Knute Johnson

SlowLearner said:
If you pop over to Roedy's website you'll find plenty of midi files to
try. Even JmStudio cannot play them on my 3 machines. (I tried emailing
you but it bounced)

I'm sorry but I don't have time to look over Roedy's site for midi
files. You can give me the URL of one or you can send me one via email.
The bounce was probably caused by not substituting knute for nospam.
 
K

Knute Johnson

Oliver said:

Thanks Oliver. I didn't mean you should do his searching for him.

I did manage to duplicate the error exactly with the files listed above.
I don't know enough about midi to tell you what the problem is. I do
know that it is possible to play midi with Java Sound although I have
not done it. JMF is no longer supported by Sun and will eventually
disappear. It is too bad too because it was a great start.

My suggestion is to try the JMF interest email list. Take a look at
Sun's JMF home page.

http://java.sun.com/products/java-media/jmf/
 
S

SlowLearner

Chris said:
SlowLearner said:
Ok I've removed the call to init components and spelt realize correctly
this time. The code now reads and still produces the same error as
before at runtime.

This problem seems to be caused by a problem of some sort (I don't know whether
it is actually a bug) in the underlying MIDI file support in the JRE (it's not
a problem with JMF as such).

Using your code (adding a main()) and setting it to play an MP3 file from the
"JavaSoundDemo" (from Sun's website somewhere[*]), and it all works OK. Change
it to play a MIDI file from the same distribution and it fails as you say.
However that was using a 1.6 or 1.5 JRE -- if I force the use of a 1.4.2 JRE
(and recompile) then it works perfectly.

For comparison, the program in "JavaSoundDemo" itself (which doesn't use JMF)
works perfectly with a 1.4.2 JRE, won't even open its main window with a 1.5
JRE, and /nearly/ works with a 1.6 JRE. With 1.6 it can use MIDI without
problems -- the interactive MIDI keyboard works fine, and playback of most
audio files works, but not MIDI files. Actually the problem seems to be that
the code is assuming that the default "sequencer" is also a "synthesiser",
that's not true under 1.6 -- with that assumption removed, the code works, and
plays MIDI files OK, but at the cost that there's no way to control the
playback volume from the application itself[**].

Also (to answer a question in another post of yours), I have JMF 2.1.1.e on
this WinXP system, and JMStudio won't play MIDI files under 1.5 or 1.6 (it
fails with "unable to prefetch"). Again, if I force it to use a 1.4.2 JRE (by
changing the parameter in the JMStudio shortcut to point to a 1.4 JRE), then it
works perfectly. (Note that that's using the same JMF jars in each case, so
the problem is definitely in 1.5 and 1.6 JRE, not JMF).

-- chris

[*] An URL for it is
http://java.sun.com/products/java-media/sound/samples/JavaSoundDemo/
but I haven't checked whether that's the same version as I have already.

[**] Indeed, I can't find any way at all to control the playback volume of the
thing answered by javax.sound.midi.MidiSystem.getSequencer().


Thanks for posting the url's Oliver. I've been trying to post some
links to Roedy's midi files for a day and a half but Google Groups has
been undergoing maintenance. I cannot access the usenet directly.
Thanks to everybody else who also posted help. I'll try the java sound
package instead as I'd really like to use Java if possible.

Martin
 
C

Chris Uppal

SlowLearner said:
Thanks to everybody else who also posted help. I'll try the java sound
package instead as I'd really like to use Java if possible.

This site

http://www.jsresources.org

seems[*] to have a lot of useful stuff on MIDI playback with JavaSound
(including examples) and the different MIDI playback options in different
versions of the Java platform.

-- chris

[*] It looks good to me, but I'm no expert in either MIDI or JavaSound, so I'm
not a good judge.
 
J

John Ersatznom

Oliver said:
You can write a media player using only the javax.sound.midi and
javax.sound.sampled packages.

You can write a Web browser using only assembly. What's your point? ;)
 
O

Oliver Wong

John Ersatznom said:
You can write a Web browser using only assembly. What's your point? ;)

My point is that the keyword "mediaplayer" in the subject line is not
sufficient to conclude that the post will be about JMF.

- Oliver
 
J

John Ersatznom

Oliver said:
My point is that the keyword "mediaplayer" in the subject line is not
sufficient to conclude that the post will be about JMF.

With certainty? Not sufficient.
Make it a very good guess? Sufficient.
 
L

Lew

John said:
You can write a Web browser using only assembly. What's your point? ;)

John said:
With certainty? Not sufficient.
Make it a very good guess? Sufficient.

Or, one could take the approach of not assuming a particular solution not
mentioned by the OP, and attempt to provide a generally useful answer to the
question actually asked. Given the reports of difficulties with JMF, such a
respondent may well conclude that it is reasonable to provide information
about non-JMF solutions.

Not so much recommending assembly to write a Web browser as recommending
Tomcat to someone who wanted to write a Web-app server.

If we must analogize.

- Lew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top