Android MediaPlayer Setdatasource failed

Source: Internet
Author: User

There was a problem with trying to play music with MediaPlayer today,

Mp.setdatasource (This, Uri.parse ("/sdcard/music/adele.mp3"));

This line of code for MediaPlayer set to play the music address, code execution to this line will always error, error message is: Setdatasource failed

Suddenly on the failed, why will not say Ah, on the Internet to check some information after a variety of attempts to use, and then use one of the overloaded method Setdatasource (filedescription filedescription) Finally, a decent error message is given: Open failed:eacces (Permission denied)

With this after a good solution, so with hundred poison search, in this article (portal) found the answer: because I want to play the SD card music, so I need to write the SD card permissions (why do I need to write permission to play music? ), you need to add the following permissions to the manifest file:

<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE" ></uses-permission>

Remember to remember ~

Android MediaPlayer Setdatasource failed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.