running an auio file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hsn
    New Member
    • Sep 2007
    • 237

    #1

    running an auio file

    i'm creating a system that in a time it will run an auio file
    the problem is that i don't know how to run an audio file in JAVA
    i have been searching around the internet in meny websites but i can't find helpful information that will help me to run the audio file

    PLEASE HELP ME IN THIS PROBLEM
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    For starters, read the API documentation for the Applet class and pay
    special attention to the newAudioClip method. I find it a bit strange that
    this method is part of the Applet class because you don't need an Applet at all
    to read and play audio files; but that's just me ;-)

    kind regards,

    Jos

    Comment

    • hsn
      New Member
      • Sep 2007
      • 237

      #3
      when i tryied to work on it i have to enter a url
      the problem i don't know how to do it
      some help please
      and by the way the music file is in the computer not in the internet

      PLEASE HELP ME

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by hsn
        when i tryied to work on it i have to enter a url
        the problem i don't know how to do it
        some help please
        and by the way the music file is in the computer not in the internet

        PLEASE HELP ME
        URLs can point to anything on your hard disk too; read up on them.
        The following snippet of code does the job:

        [code=java]
        URL url = this.getClass() .getResource(na me);

        if (url != null)
        clip= Applet.newAudio Clip(url);
        [/code]

        The String 'name' is just a relative file path; relative to the class in which the
        above code is written.

        kind regards,

        Jos

        Comment

        • hsn
          New Member
          • Sep 2007
          • 237

          #5
          Originally posted by JosAH
          URLs can point to anything on your hard disk too; read up on them.
          The following snippet of code does the job:

          [code=java]
          URL url = this.getClass() .getResource(na me);

          if (url != null)
          clip= Applet.newAudio Clip(url);
          [/code]

          The String 'name' is just a relative file path; relative to the class in which the
          above code is written.

          kind regards,

          Jos
          the problem is that when i put the path it show me an error message that \(something ) is not valid

          how can i give the path correctly

          hsn

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by hsn
            the problem is that when i put the path it show me an error message that \(something ) is not valid

            how can i give the path correctly

            hsn
            Did you read the API documentation for the Class.getResour ce() method?
            Also did you really read the last paragraph in my previous message?

            kind regards,

            Jos

            Comment

            Working...