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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:20:35+00:00 2026-06-11T09:20:35+00:00

I am trying to play an mp3 using the Media player class. When I

  • 0

I am trying to play an mp3 using the Media player class. When I hardcode the mp3 resource it works, however I would like the resource to come from a string instead of directly accessing it like R.raw.mp3name.

Bundle bundle = getIntent().getExtras();
String Choice= bundle.getString("bundledChoice");        
Uri myUri = Uri.parse("R.raw." + Choice);        
mPlayer = MediaPlayer.create(activity.this, myUri);
mPlayer.start();

If I change the second to last line to mPlayer = MediaPlayer.create(activity.this, R.raw.song) it will work, the problem is creating the resource URI dynamically from the string which is obtained from the bundle.

Please advise.

  • 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-11T09:20:36+00:00Added an answer on June 11, 2026 at 9:20 am

    The solution I am using to this little challenge is based on @Creator’s answer to this post: Android – getting an image resource into Uri: IllegalArgumentException.

    The solution is to use

    Uri uri = Uri.parse("android.resource://[package]/[res type]/[res name]");
    

    [package] you either know (com.company.blah.superdooperthing), or can be determined using getPackageName().

    [res type] is (I think, and it seems to work) the directory inside “res” that you are pulling the resource from. So, for an audio file …/res/raw/nicemusic.mp3, res would be “raw”.

    [res name] is (I think, and it seems to work) the file name (less extension) of the resouce. So, for the example above, it would be “nicemusic”.

    So, a more systematic approach might be:

    String dataResourceDirectory = "raw";
    String dataResoruceFilename = "nicemusic";
    
    Uri uri=Uri.parse("android.resource://" + getPackageName() + "/" + 
                      dataResourceDirectory + "/" + dataResoruceFilename);
    

    Better solutions welcome!

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

Sidebar

Related Questions

I am trying to play an mp3 sound using the MediaPlayer class inside a
I am trying to play a song from my iPhone music library using AVPlayer.
I'm trying to play a remote MP3 file in my Xcode project, however the
I am trying to play 6 seperate .mp3 sound files using instances of AVAudioPlayer.
I am trying to play and audio file using DirectX dll. Audio.FromFile(Message 1.mp3).Play(); But
I am trying to make a simple mp3 player using flash. The songs are
I am trying to play dynamically few mp3 sounds using AVAudioPlayer. The following code
I'm trying to play a specific portion of a mp3 file using MediaElement. I
I want to play a mp3 using HTML 5 audio support. I was trying
I'm trying to play a mp3 file using AVFoundation framework. It can't detect the

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.