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 8467101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:32:40+00:00 2026-06-10T15:32:40+00:00

I am currently playing a song using MediaPlayer which plays fine. On user selecting

  • 0

I am currently playing a song using MediaPlayer which plays fine. On user selecting a different song, I’m trying to play that out.
But, I get error(1,-2147483648) and Error(1, -2147483648) by the MediaPlayer.
These logs are printed after the call to prepareASync();
Note: The path of the file looks correct. However, how do I check for a valid filepath?

The sequence is as follows:

           mPlayer.reset();
           Log.d(TAG,"after reset");
           mPlayer.setDataSource(mTrackToBePlayed);
           Log.d(TAG,"after setDataSource");
          // mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
           mPlayer.setOnPreparedListener(preparedListener);
           Log.d(TAG,"after setOnPreparedListener");
           mPlayer.setOnErrorListener(errorListener);
           Log.d(TAG,"after setting errorListener");
           mPlayer.prepareAsync();
           Log.d(TAG,"after prepareAsync");

The code for reference is this: in onResume() of my main activity(on returning to which, I want to start playback) I am making the calls MusicUtils.createPlayer(); and
MusicUtils.playTrack(mCurrentTrack);

public static void playTrack(String track) {

    mTrackToBePlayed = track;   

    try {
           mPlayer.reset();
           Log.d(TAG,"after reset");
           mPlayer.setDataSource(mTrackToBePlayed);
           Log.d(TAG,"after setDataSource");
          // mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
           mPlayer.setOnPreparedListener(preparedListener);
           Log.d(TAG,"after setOnPreparedListener");
           mPlayer.setOnErrorListener(errorListener);
           Log.d(TAG,"after setting errorListener");
           mPlayer.prepareAsync();
           Log.d(TAG,"after prepareAsync");

    } catch (IOException e) {

    } catch(IllegalArgumentException e) {

    }

    preparedListener = new MediaPlayer.OnPreparedListener() {

        @Override
        public void onPrepared(MediaPlayer mp) {
            // TODO Auto-generated method stub
            mp.start();
            Log.d(TAG,"after start");
        }
    };

     errorListener = new MediaPlayer.OnErrorListener() {
         public boolean onError(MediaPlayer mp, int what, int extra) {
             switch (what) {
             case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
                 Log.d(TAG,"in onError");
                // mIsInitialized = false;
                 mp.release();
                 // Creating a new MediaPlayer and settings its wakemode does not
                 // require the media service, so it's OK to do this now, while the
                 // service is still being restarted
                try{
                 mp = new MediaPlayer(); 
                 mp.reset();
                 mp.setDataSource(mTrackToBePlayed);
                // mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
                 mp.prepareAsync();
                 mPlayer = mp;
                // mPlayer.start();
                } catch (Exception e) {

                }
                 //MediaPlayer.create(mContext, mTrackToBePlayed);
                // mPlayer.setWakeMode(MediaPlaybackService.this, PowerManager.PARTIAL_WAKE_LOCK);                 
                 return true;
             default:
                 Log.d("MusicPlayer", "Error: " + what + "," + extra);
                 break;
             }
             return false;
        }
     };


    //mPlayer.start();

}

public static boolean isPlaying() {
    return mPlayer.isPlaying();
}

public static void pauseTrack() {
    mPlayer.pause();
}

public static void startTrack() {
    mPlayer.start();
}

public static void stopTrack() {
    mPlayer.stop();
}

public static void releasePlayer() {
    mPlayer.release();
}

This function is present in MusicUtils and is used to obtain the first track that the cursor returns

public static void retrieveDefaultPath() {

    String[] STAR = { "*" };           
    Uri allsongsuri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;    
    String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";     
    mCursor = mContentResolver.query(allsongsuri, STAR, selection, null, null);     
    if (mCursor != null) {        
        if (mCursor.moveToFirst()) {          
            //do {               
                //mSongName = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME));   
                //mSongList.add(mSongName);//populate the list of display names
                int song_id = mCursor.getInt(mCursor.getColumnIndex(MediaStore.Audio.Media._ID));   
                //mMusicIDs.put(song_id, counter++);//fill the HashMap with IDs corresponding to the positions
                String fullpath = mCursor.getString(mCursor.getColumnIndex(MediaStore.Audio.Media.DATA));            
                String album_name = mCursor.getString(mCursor.getColumnIndex(MediaStore.Audio.Media.ALBUM));          
                int album_id = mCursor.getInt(mCursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID));               
                String artist_name = mCursor.getString(mCursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));         
                int artist_id = mCursor.getInt(mCursor.getColumnIndex(MediaStore.Audio.Media.ARTIST_ID));        
                //} while (cursor.moveToNext());       


                 mDefaultPath = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI + "/" + song_id;
                 Slideshow.mCurrentTrack = mDefaultPath;

    }      
        if  (mCursor != null) { 
             mCursor.close();   
        }
    } 
}



The following function is used to obtain all the tracks on the device to display using the ListActivity.

public void getAllSongsFromSDCARD()  {     
    String[] STAR = { "*" };           
    Uri allsongsuri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;    
    String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";     
    cursor = managedQuery(allsongsuri, STAR, selection, null, null);     
    if (cursor != null) {        
        if (cursor.moveToFirst()) {          
            do {               
                mSongName = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME));   
                mSongList.add(mSongName);//populate the list of display names
                int song_id = cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Media._ID));   
                Log.d("Music List","ID: "+song_id+" counter:"+counter);

                mMusicIDs.put(counter++, song_id);//fill the HashMap with IDs corresponding to the positions
                String fullpath = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));            
                String album_name = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM));          
                int album_id = cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID));               
                String artist_name = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));         
                int artist_id = cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST_ID));        
                } while (cursor.moveToNext());       
    }      
       cursor.close();    
    } 
} 

I use the ID that the user selects and obtain the filepath in the following way:

 music_id = (Integer)mMusicIDs.get(position);
 mSelectedPath = mSelectedPath + "/" + music_id;

Logcat:

08-31 18:07:36.348: D/dalvikvm(23090): GC_EXTERNAL_ALLOC freed 2K, 46% free 3088K/5703K, external 1461K/1538K, paused 32ms

08-31 18:07:38.860: D/tag(23090): inside oncreate

08-31 18:07:38.860: D/ImageSwitcher(23090): cache size:1

08-31 18:07:39.030: D/ImageSwitcher(23090): TOTAL NUM IMAGES: 838

08-31 18:07:39.150: I/AudioSystem(23090): getting audio flinger

08-31 18:07:39.150: I/AudioSystem(23090): returning new audio session id

08-31 18:07:39.150: D/IAudioFlinger(23090): newAudioSessionId In

08-31 18:07:39.150: D/IAudioFlinger(23090): newAudioSessionId Out, id = 175

08-31 18:07:39.150: D/MediaPlayer(23090): reset() in

08-31 18:07:39.150: D/MediaPlayer(23090): reset() out

08-31 18:07:39.150: D/MusicUtils(23090): after reset

08-31 18:07:39.160: D/MusicUtils(23090): after setDataSource

08-31 18:07:39.160: D/MusicUtils(23090): after setOnPreparedListener

08-31 18:07:39.160: D/MusicUtils(23090): after setting errorListener

08-31 18:07:39.170: D/MusicUtils(23090): after prepareAsync

08-31 18:07:39.250: D/MediaPlayer(23090): start() in

08-31 18:07:39.260: D/MediaPlayer(23090): start() out

08-31 18:07:39.270: D/MediaPlayer(23090): start() in

08-31 18:07:39.270: D/MediaPlayer(23090): start() out

08-31 18:07:39.270: D/MusicUtils(23090): after start

08-31 18:07:49.340: D/MediaPlayer(23090): pause() in

08-31 18:07:49.340: D/MediaPlayer(23090): pause() out
08-31 18:07:49.560: D/dalvikvm(23090): GC_CONCURRENT freed 239K, 45% free 3260K/5831K, external 494K/1006K, paused 10ms+7ms

08-31 18:07:50.842: D/Music List(23090): in onCreate before getAllSongsFromSDCARD

08-31 18:07:50.922: D/TAG(23090): set adapter

08-31 18:07:50.922: D/TAG(23090): set adapter done

08-31 18:07:51.953: D/dalvikvm(23090): GC_EXTERNAL_ALLOC freed 146K, 45% free 3264K/5831K, external 794K/855K, paused 29ms

08-31 18:07:53.905: D/MusicList(23090): after setItemChecked

08-31 18:07:54.585: D/Settings(23090): inside onActivityResult

08-31 18:07:55.476: W/KeyCharacterMap(23090): Can’t open keycharmap file

08-31 18:07:55.476: W/KeyCharacterMap(23090): Error loading keycharmap

file ‘/system/usr/keychars/cy8c-touchscreen.kcm.bin’. hw.keyboards.65538.devname=’cy8c-touchscreen’
08-31 18:07:55.476: I/KeyCharacterMap(23090): Using default
keymap: /system/usr/keychars/qwerty.kcm.bin

08-31 18:07:55.486: D/MediaPlayer(23090): reset() in

08-31 18:07:55.486: D/MediaPlayer(23090): reset() out

08-31 18:07:55.486: D/MusicUtils(23090): after reset

08-31 18:07:55.486: D/MusicUtils(23090): after setDataSource

08-31 18:07:55.486: D/MusicUtils(23090): after setOnPreparedListener

08-31 18:07:55.486: D/MusicUtils(23090): after setting errorListener

08-31 18:07:55.486: D/MusicUtils(23090): after prepareAsync

08-31 18:07:55.496: E/MediaPlayer(23090): error (1, -2147483648)

08-31 18:07:55.506: E/MediaPlayer(23090): Error (1,-2147483648)

08-31 18:07:55.506: D/MusicPlayer(23090): Error: 1,-2147483648

  • 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-10T15:32:42+00:00Added an answer on June 10, 2026 at 3:32 pm

    The sequence is correct. The path was going wrong. A hardcoded string instead of a Uri was being used. Thanks.

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

Sidebar

Related Questions

Using C# i'm trying to retrieve the name of the song that is currently
Possible Duplicate: On iPhone: Find out what song is currently playing? (in the iPod
I'd like to get the name of the song that iTunes is currently playing.
I'm trying to get the lyrics to the current playing song in iTunes using
My application generates a link from the song that is currently playing. My idea
I am using dbus to get the current playing song from Songbird Media Player
I am using python-mpd to fetch current playing song artist and title. I am
I'm currently playing with C, C++ and ASM. I can see that there's always
I am currently playing with Qt trying to set up a small particle system.
I am using MPMoviePlayerController to play streaming audio. I'm trying to get background audio

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.