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

  • Home
  • SEARCH
  • 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 9076021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:00:49+00:00 2026-06-16T19:00:49+00:00

After creating a player by using method this code: player = Manager.createPlayer(getClass().getInputStream(/sound.wav), audio/x-wav) Is

  • 0

After creating a player by using method this code:

player = Manager.createPlayer(getClass().getInputStream("/sound.wav"), "audio/x-wav")

Is it possible to pass an audio file to same instance of player?

I tried by doing this:

player = (Player) player.getClass().getInputStream("/sound.wav");

but this one give me an exception which is java.lang.ClassCastException

If its is possible then how it should be done?

  • 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-16T19:00:51+00:00Added an answer on June 16, 2026 at 7:00 pm

    This line

    player = (Player) player.getClass().getInputStream("/sound.wav");
    

    gives you a ClassCastException because you are trying to cast an InputStream into a Player. That’s wrong. This line correctly assigns a Player to your player variable:

    player = Manager.createPlayer(getClass().getInputStream("/sound.wav"), "audio/x-wav");
    

    If you want, you can use my second line again and again, when it’s time to replay the sound. You will just be recreating the player. If you are not changing the sound file (.wav), then when the sound finishes playing, I would just start it again without creating a new player:

    player.start();  // restart the same sound
    

    But, if you are changing which sound file you use, it might be easier just to call createPlayer again:

    player = Manager.createPlayer(getClass().getInputStream("/another_sound.wav"), "audio/x-wav");
    

    Here are some BlackBerry docs on the Player. Even though you may be on a different J2ME platform, I think the same lifecycle rules probably apply:

    A Player has five states: UNREALIZED, REALIZED, PREFETCHED, STARTED,
    CLOSED.

    The purpose of these life-cycle states is to provide programmatic
    control over potentially time-consuming operations. For example, when
    a Player is first constructed, it’s in the UNREALIZED state.
    Transitioned from UNREALIZED to REALIZED, the Player performs the
    communication necessary to locate all of the resources it needs to
    function (such as communicating with a server or a file system). The
    realize method allows an application to initiate this potentially
    time-consuming process at an appropriate time.

    Typically, a Player moves from the UNREALIZED state to the REALIZED
    state, then to the PREFETCHED state, and finally on to the STARTED
    state.

    A Player stops when it reaches the end of media; or when the stop
    method is invoked. When that happens, the Player moves from the
    STARTED state back to the PREFETCHED state. It is then ready to repeat
    the cycle.

    To use a Player, you must set up parameters to manage its movement
    through these life-cycle states and then move it through the states
    using the Player’s state transition methods.

    enter image description here

    Update: as you seem to be concerned with code complexity, and perhaps deallocating (?) objects, here is a code sample, that hopefully illustrates that it shouldn’t be too difficult. You would just take the code in that answer, and make it a method where you pass in the name of the autio file (musicFile).

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

Sidebar

Related Questions

After creating a new form, I usually perform this ritual: Change the name into
After creating a metaclass using Moose::Meta::Class->create , how do I instantiate a real Moose
After creating a div on the fly with this markup: $('.circuit').prepend(<div class='component' draggable='true'>TRANSISTOR</div>); It
After creating a document with a explicit id like this: Document(doc_id = 123) Is
After creating secret keys, how do I store them using the Keystore class' methods
I'm creating my own HTML5 audio player capable of handling playlists. I have created
I am working on Android , I am creating a player for audio songs.
I use this code to list processes: //Creating ListBox hPNList=CreateWindow(TEXT(ListBox),TEXT(),WS_CHILD|WS_VISIBLE|LBS_SORT|LBS_NOTIFY,30,132,185,380,hWnd,(HMENU)PNLIST_ID, GetModuleHandle(NULL),NULL); //changing Font SendMessage(
After creating a new object (Foo), I set the key (BarId) for an EntityRef
After creating a child process and exiting it immediately (_exit()), I want to perform

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.