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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:51:53+00:00 2026-06-04T08:51:53+00:00

Let’s say I have a full path to a file. Which is the better

  • 0

Let’s say I have a full path to a file. Which is the better approach to loading that file into a MediaPlayer?

String filePath = "somepath/somefile.mp3";
mediaPlayer.setDataSource(filePath);

OR

String filePath = "somepath/somefile.mp3";
File file = new File(filePath);
FileInputStream inputStream = new FileInputStream(file);
mediaPlayer.setDataSource(inputStream.getFD());
inputStream.close();

Does it matter? Simply using the path seems easier but is there a reason to do the extra work to use a FileDescriptor?

  • 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-04T08:51:54+00:00Added an answer on June 4, 2026 at 8:51 am

    Actually, it turns out that there IS a difference in certain situations.

    mediaPlayer.setDataSource(String path) will fail when you call mediaPlayer.prepare(), if you are trying to load a file from getApplicationContext().getFilesDir(), depending on how the file was saved. For example, if I write a file using new RandomAccessFile(filePath, "rw"), the file is not actually readable by the mediaplayer if you use mediaPlayer.setDataSource(String path). The prepare() will immediately trigger error(1, -2147483648) from the mediaplayer; essentially a file permission error. SDK 9 introduced file.setReadable (boolean readable, boolean ownerOnly) which would presumably allow you to resolve this issue by setting ownerOnly to false…but that doesn’t help you if you need to support older SDKs.

    HOWEVER, mediaPlayer.setDataSource(FileDescriptor fd) does NOT have this problem and mediaplayer will successfully prepare the same exact file without a permission problem.

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

Sidebar

Related Questions

Let's say I have an string variable called *magic_string* which value is set to
Let's say I have a method in java, which looks up a user in
Let me explain best with an example. Say you have node class that can
Let's say that I have a SQLite database that I create in a separate
Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
Let's say I have multiple requirements for a password. The first is that the
Let's say that I have a date in R and it's formatted as follows.
Let's say I have the following classes : public class MyProductCode { private String
Let's say you have a method that expects a numerical value as an argument.

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.