Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9040495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:59:43+00:00 2026-06-16T09:59:43+00:00

I am trying to play an mp3 file using a neat library I just

  • 0

I am trying to play an mp3 file using a neat library I just discovered (JLayer) and it works fine when compiled (in Netbeans) with this code:

ClassLoader cl = this.getClass().getClassLoader();
url = cl.getResource("music/45.mp3");
pin = new FileInputStream(url.getFile());
p = new Player(pin);
p.play();

I built my project and attempted to run the executable jar. I extended JFrame so I could visually see that my program was running. The Frame appears when executed, but no sound. I though that using a class loader would fix this issue, but no luck. Help would be greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T09:59:45+00:00Added an answer on June 16, 2026 at 9:59 am

    Don’t use FileInputStream when you’ve got a resource which may be in a jar file – use ClassLoader.gerResourceAsStream or Class.getResourceAsStream. That’s what they’re there for. You haven’t got a separate file on disk, so it’s pointless trying to use FileInputStream with it.

    (Of course, you may also find that you’re not making the resource available properly – but that’s a separate issue.)

    So just use:

    Player p = new Player(getClass().getResourceAsStream("/music/45.mp3"));
    p.play();
    

    (From your code, it looks like you’re declaring your variables much earlier than you need to – or possibly even declaring them as fields when they should logically just be local variables. It’s worth keeping an eye on that. Make sure you only use fields when you really want to indicate some state of the class or instance, and declare local variables as late as you can – ideally at the point of initialization.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to play a local sound file with Phonegap. This works fine over
I'm trying to play a mp3 file using AVFoundation framework. It can't detect the
I am trying to play and audio file using DirectX dll. Audio.FromFile(Message 1.mp3).Play(); But
I'm trying to play a specific portion of a mp3 file using MediaElement. I
I'm trying to play an mp3 audio file on iPhone executing the following code:
I am trying to play a video file using JMF but it gives me
I am trying to play a song from my iPhone music library using AVPlayer.
I'm trying to play a 24bit audio file with my AutoHotkey app. It just
I am trying to play small mp3 file in my Windows Phone 7.5 MVVM
I'm trying to use fmodex 4.30.03 to play an MP3 file under Mono/Ubuntu. My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.