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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:44:14+00:00 2026-06-16T00:44:14+00:00

I have a section of code shown below that gets the pathname for an

  • 0

I have a section of code shown below that gets the pathname for an mp3 audio file stored in the content provider database. Next it uses this pathname to load the mp3 file and start playing it. The problem is that if I get a different pathname and hit pause or play it keeps playing the same old audio file, not the new file. What is the best way to solve this problem?

      String pathName; // pathname of audio file stored in SD card
      String selection = MediaStore.Images.Media.DATA + "='" + pathName +"'";
      String[] projection = { MediaStore.Images.Media.LATITUDE };
      cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, selection, null, null);

      if(cursor!=null){
         cursor.moveToFirst();
        }
        musicName = (String) cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.LATITUDE));

         Toast.makeText(AudioService.this, "from AUDIOSERVICE CLASS music name: " + musicName, Toast.LENGTH_SHORT).show();

         cursor.close();    

         player.setDataSource(musicName);

        player.prepare();

        player.start();

        }
  • 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-16T00:44:14+00:00Added an answer on June 16, 2026 at 12:44 am

    check if path is same then play same file again and if file path is different then first reset mediaplayer and then play new file change your code as:

          String pathName=""; // pathname of audio file stored in SD card
           public static String musicName="";
          String selection = MediaStore.Images.Media.DATA + "='" + pathName +"'";
          String[] projection = { MediaStore.Images.Media.LATITUDE };
          cursor = getContentResolver().query(MediaStore.Images.
                 Media.EXTERNAL_CONTENT_URI, projection, selection, null, null);
    
          if(cursor!=null){
             cursor.moveToFirst();
            }
    
    if(musicName.length()==0){
             musicName = (String) cursor.getString(cursor.getColumnIndex(
                                          MediaStore.Images.Media.LATITUDE));
    
             Toast.makeText(AudioService.this, 
                                        "from AUDIOSERVICE CLASS music name:
                                          " + musicName, Toast.LENGTH_SHORT).show();
    
             cursor.close();    
    
             player.setDataSource(musicName);
    
            player.prepare();
    
            player.start();
    
      }
    else{
     String musicNametemp = (String) cursor.getString(cursor.getColumnIndex(
                                              MediaStore.Images.Media.LATITUDE));
    
    if(musicNametemp.equals(musicName)){
    
    ///play old music here
    }
    
    else{
    //reset mediaplayer here
    
    if(player !=null){
     player.reset();
     player.release();
     player = new MediaPlayer();
    
    }
    cursor.close();    
    musicName=musicNametemp;
    player.setDataSource(musicName);
    
    player.prepare();
    
    player.start();
    }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a section of code that is supposed to check if an mp3
I have a section of code that can be summarised as follows; void MyFunc()
I have the following section of code in an app that I am writing:
I have a section of code which should be executed by a maximum number
I have this view (DetailsContainer, first class in code section of this question) with
I have some VERY simple code to return the title for a section header:
In my xaml code, inside the Window.Resources section, I have defined a Data Template
Javascript I have code that will hide various sections in a MS CRM form
I have the following json code file named: sections.json { section1: { priority: 1,
To cut a long story short I have a section of my application that

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.