Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 12 of 12

Thread: Getting error messages with my javafx video player

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Getting error messages with my javafx video player

    Hi,
    I am building an application that will play video (and more later). When I run it I get run time error messages. I have checked it myself and I can't work out what is wrong. Although it seems to be a problem with the source string. Can any one guide me on how to correct my code?

    package javafxapplication1;
     
    import javafx.application.Application;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.layout.StackPane;
    import javafx.scene.media.Media;
    import javafx.scene.media.MediaPlayer;
    import javafx.scene.media.MediaView;
    import javafx.stage.Stage;
     
    /**
     *
     * @author Adam James Smalley
     */
    public class JavaFXApplication1 extends Application {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            launch(args);
        }
     
        @Override
        public void start(Stage primaryStage) {
            primaryStage.setTitle("Hello World!");
            String source = "C:\\Users\\Adam James Smalley\\Downloads\\vid.flv";
            Media media = new Media(source);
            MediaPlayer mediaPlayer = new MediaPlayer(media);
            mediaPlayer.setAutoPlay(true);
            MediaView mediaView = new MediaView(mediaPlayer);
            StackPane root = new StackPane();
            root.getChildren().add(mediaView);
            primaryStage.setScene(new Scene(root, 480, 640));
            primaryStage.show();
        }
    }

    The error messages are:

    Exception in Application start method
    java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.javafx.main.Main.launchApp(Main.java:486)
    at com.javafx.main.Main.main(Main.java:638)
    Caused by: java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchAppl ication1(Unknown Source)
    at com.sun.javafx.application.LauncherImpl.access$000 (Unknown Source)
    at com.sun.javafx.application.LauncherImpl$1.run(Unkn own Source)
    at java.lang.Thread.run(Thread.java:722)
    Caused by: java.lang.IllegalArgumentException: java.net.URISyntaxException: Illegal character in opaque part at index 2: C:\Users\Adam James Smalley\Downloads\vid.flv
    at javafx.scene.media.Media.<init>(Unknown Source)
    at javafxapplication1.JavaFXApplication1.start(JavaFX Application1.java:35)
    at com.sun.javafx.application.LauncherImpl$5.run(Unkn own Source)
    at com.sun.javafx.application.PlatformImpl$4.run(Unkn own Source)
    at com.sun.javafx.application.PlatformImpl$3.run(Unkn own Source)
    at com.sun.glass.ui.win.WinApplication._runLoop(Nativ e Method)
    at com.sun.glass.ui.win.WinApplication.access$100(Unk nown Source)
    at com.sun.glass.ui.win.WinApplication$2$1.run(Unknow n Source)
    ... 1 more
    Caused by: java.net.URISyntaxException: Illegal character in opaque part at index 2: C:\Users\Adam James Smalley\Downloads\vid.flv
    at java.net.URI$Parser.fail(URI.java:2829)
    at java.net.URI$Parser.checkChars(URI.java:3002)
    at java.net.URI$Parser.parse(URI.java:3039)
    at java.net.URI.<init>(URI.java:595)
    ... 9 more
    Java Result: 1


  2. #2
    Member
    Join Date
    Jul 2012
    Posts
    119
    Thanks
    0
    Thanked 19 Times in 19 Posts

    Default Re: Getting error messages with my javafx video player

    shark... Is this path and file exist in your System? "C:\\Users\\Adam James Smalley\\Downloads\\vid.flv"
    and the exception Caused by: java.net.URISyntaxException: Illegal character in opaque part at index 2: C:\Users\Adam James Smalley\Downloads\vid.flv at java.net.URI$Parser.fail(URI.java:2829) tells you the causes

  3. #3
    Junior Member
    Join Date
    Jul 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Getting error messages with my javafx video player

    Yes I'm sure it exists. I have even put it in the top level directory of the C drive to ensure there are no problems with the path and updated the code.

    String source = "C:\\vid.flv";

    I'm a beginner so I find it difficult to understand the error messages. Please can you explain them to me.

  4. #4
    Member
    Join Date
    Jul 2012
    Posts
    119
    Thanks
    0
    Thanked 19 Times in 19 Posts

    Default Re: Getting error messages with my javafx video player

    Quote Originally Posted by sharksaw40 View Post
    Yes I'm sure it exists. I have even put it in the top level directory of the C drive to ensure there are no problems with the path and updated the code.

    String source = "C:\\vid.flv";

    I'm a beginner so I find it difficult to understand the error messages. Please can you explain them to me.
    You misuderstand the concept of Java and Window. Java is UNIX (or SUNOS) oriented. That means the path seperator is NOT a backward slash "\" but a forward slash "/". And window is the opposite. Hence the Exception message "... Illegal character in opaque part at index 2: C:\Users\Adam James Smalley\Downloads\vid.flv..."
    Secondly an URI (Uniform Resource Identifier) orients to HTTP syntax. That means the backslash is an ILLEGAL character. More: An example HTML document

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Getting error messages with my javafx video player

    Always a good idea to read the API for the methods and classes you are using, in particular the Media class which is throwing the Exception.
    Media (JavaFX 2.1)
    It explicitly states
    The source must represent a valid URI and is immutable.
    You must pass a valid string representation of a URI. You can do so by manually, or create a File from the path you provided in the source above, convert to a URI, then use the toString() method (again, see the API for the appropriate methods).

  6. #6
    Junior Member
    Join Date
    Jul 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Getting error messages with my javafx video player

    Thanks for your help so far.

    There is still a problem though. The program runs and the window appears but it is blank and I can't see any video. Does anyone know how to fix this?

  7. #7
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Getting error messages with my javafx video player

    Just a thought...
    Maybe you don't want to post your real life name in code on a public forum.

  8. #8
    Member
    Join Date
    Jul 2012
    Posts
    119
    Thanks
    0
    Thanked 19 Times in 19 Posts

    Default Re: Getting error messages with my javafx video player

    Shark...
    are you sure that this vid.flv a real video?

  9. #9
    Junior Member
    Join Date
    Jul 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Getting error messages with my javafx video player

    I converted the format of the video to MPEG-4 with H.264/AVC and now I see a black box appear which must be the media view object. However there is nothing playing in it and no error messages.

  10. #10
    Member
    Join Date
    Jul 2012
    Posts
    119
    Thanks
    0
    Thanked 19 Times in 19 Posts

    Default Re: Getting error messages with my javafx video player

    ...then google for a flv-video and try with it.

  11. #11
    Junior Member
    Join Date
    Jul 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Getting error messages with my javafx video player

    Thanks.
    It is now working.

  12. #12
    Junior Member
    Join Date
    Jul 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Getting error messages with my javafx video player

    Thanks it now works. The video must have been converted wrong.

Similar Threads

  1. Video player with pseudo streaming
    By Wessel in forum AWT / Java Swing
    Replies: 0
    Last Post: April 25th, 2012, 05:06 PM
  2. Help needed to figure out why I keep getting error messages in Eclipse
    By RookieCodeWriter in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 18th, 2012, 11:31 AM
  3. Error Messages Best Practices
    By Dalek_Supreme in forum Java Theory & Questions
    Replies: 0
    Last Post: April 1st, 2011, 07:22 PM
  4. Replies: 2
    Last Post: March 16th, 2011, 06:32 AM
  5. Java error while Playing Video file.
    By ravigirismiles in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 7th, 2010, 11:09 AM

Tags for this Thread