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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:56:42+00:00 2026-06-17T16:56:42+00:00

i have a problem with the MediaMetadataRetriever setdatasource method. i created a simple project.

  • 0

i have a problem with the MediaMetadataRetriever setdatasource method. i created a simple project. the main.xml has only a textview, which should display the paramter of the music.mp3. the mp3 is in the project raw file. the mainActivity looks like:

public class MainActivity extends Activity {

 /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    TextView tvMain = (TextView)findViewById(R.id.textView_songParam);
    // load data file
    MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever();
    metaRetriever.setDataSource(R.raw.music);

    String out = "";
    // get mp3 info
    out += metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
    out += "\n";
    out += metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
    out += "\n";
    //out += metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
    //out += "\n";
    //out += metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR);
    //out += "\n";
    // convert duration to minute:seconds
    String duration = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
    long dur = Integer.parseInt(duration);
    String seconds = String.valueOf(dur % 60);
    String minutes = String.valueOf(dur / 60000);
    out += "Length: [ " + minutes + "m" + seconds + "s ]\n";

    // close object
    metaRetriever.release();
    // display output
    tvMain.setText(out);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

what i am doing wrong here in the line, where i set the data source?? i dont understand that?

  • 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-17T16:56:44+00:00Added an answer on June 17, 2026 at 4:56 pm

    You are passing an integer to setDataSource because R.raw.music returns the resource id related to the file, not the path to the file. You need to pass path or file descriptor as an argument to setDataSource. Try this code:

        AssetFileDescriptor afd = getResources().openRawResourceFd(R.raw.music);
        if (afd != null) {
            MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever();
            metaRetriever.setDataSource(afd.getFileDescriptor());
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem on deleting component which is created on runtime. Please help me.
I have problem about django template-db query relationship. For example, I created two tables
I have problem with Django templates. I want to create a base html, which
I have problem that in my MVC 3 project, the logon view do not
I have problem with building in Qt4 creator. I have some created projects and
I have problem to make work a resource file. This is my simple code
I have problem positioning left sidebar (variating height DIV) ON IE6. Main needs: 1.
I have problem with my spring-security.xml file. I have wanted to configure some session
I have problem with this method in NLog library: NLog.Targets.Wrappers.AsyncTargetWrapper.ProcessPendingEvents(object state) It consume too
I have problem running my app on Android 2.3 (Gingerbread). The app has a

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.