0

I have made a simple game, it is a state based game meaning I have many different states (screens) such as the start-up screen, menu screen and the actual game, my menu screen is boring at the moment and I want a portion of it to be a video without any controls so it looks like its an animation built into the game, I looked into JMF and found that you only need the following code for it to work(note that I have removed the controls which were in the original code I had found so it is just the video left):

EIDT: The code is shown with comments explaining the error messaged:

    package javagame;

import java.awt.BorderLayout;
import java.awt.Component;
import java.net.URL;

import javax.swing.JFrame;

public class mediaPlayer extends JFrame
    {
        public mediaPlayer()
        {
            setLayout(new BorderLayout());


            URL mediaURL = //Whatever

            Player mediaPlayer = Manager.createRealizedPlayer(mediaURL);
            //Player cannot be resolved as a variable
            //mediaPlayer cannot be resolved as a variable
            //Manager cannot be resolved



            Component video = mediaPlayer.getVisualComponent();
            //The method getVisualComponent() is undefined for thetype mediaplayer
            add(video,BorderLayout.CENTER);

        }
    }

I had made a new class called mediaPlayer and put the above code in it, it extends JFrame but I am getting errors under things like player, mediaplayer and manager saying things like make methods for this, make class for this, make variable for this, I thought that this would work without errors as it extends JFrame and all of the methods, class's and variables required are already made, am I wrong about this?

Rahul Khosla
  • 349
  • 9
  • 21

2 Answers2

1

..am I wrong about this?

Yes, you are. The only methods that are automatically included in a frame are those defined for it.

The methods you are talking about, are part of the JMF. Those classes need to be imported at the top of the code. Something like:

import javax.media.*;
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    As an aside, fixing imports is 'Java 101' whereas using obsolete APIs to provide video is 'Master Class'. ..Consider doing easier projects till you have more experience. – Andrew Thompson Jan 08 '13 at 14:38
  • About the import, I tried that and it says remove unused import. I have all the imports required because I used the ctrl+o on eclipse to get them all. – Rahul Khosla Jan 08 '13 at 14:39
  • That is ridiculous. The code uses the `Player` class from [`javax.media.Player`](http://docs.oracle.com/cd/E17802_01/j2se/javase/technologies/desktop/media/jmf/2.1.1/apidocs/javax/media/Player.html). It should be showing a problem with `Player` that has no import, since there is no `Player` class in the entire J2SE 7. Please copy/paste compiler errors. And post them one at a time, rather than a complete bunch of them. – Andrew Thompson Jan 08 '13 at 14:43
  • I have edited my code to show the errors I am getting as comments on the code. – Rahul Khosla Jan 08 '13 at 14:48
  • `Player cannot be resolved as a variable` If your IDE claims both that and that `javax.media` is an unused import, I can only guess that the JMF API is not on the compile-time class-path. But that is an entirely different question. *This* question has effectively been answered IMO. – Andrew Thompson Jan 08 '13 at 14:51
  • could you please tell me how I get the JMF API on the compile-time class path? – Rahul Khosla Jan 08 '13 at 14:56
  • Does *that is an entirely different question* not mean anything to you? I was trying to subtly say *"Mark this question as answered, and ask a new question about 'putting Jars on the compile-time class-path using XYZ IDE'"*. But I see 'subtle' is not going to work here. And as an aside. Since I don't answer IDE questions, it won't be me who answers *that* question. – Andrew Thompson Jan 08 '13 at 15:00
0

Make sure you download Java Media Framework. Add the jar to a folder called lib in your project. Right click on the jar and add it to the build path. Then your import should work.

ControlAltDelete
  • 3,576
  • 5
  • 32
  • 50