简体   繁体   English

从内部存储android播放.mp3

[英]Playing .mp3 from internal storage android

I know there are several questions about this, sadly none of them helps me. 我知道有几个问题,可惜没有一个对我有帮助。 (or I am too stupid to apply the answer to my problem). (或者我太愚蠢而无法将答案应用于我的问题)。

On my virtual phone I created the folder "Musik" inside this folder a "King.mp3" is located. 在我的虚拟电话上,我在“ King.mp3”文件夹中创建了“ Musik”文件夹。

I am not able to play this mp3 via media player. 我无法通过媒体播放器播放此mp3。

This is the crucial part of my code: 这是我的代码的关键部分:

MediaPlayer mp;
mp = MediaPlayer.create(this, Uri.parse(Environment.getExternalStorageDirectory().getPath()+
                "/Musik/King.mp3"));
mp.start();

I already tried it with: 我已经尝试过:

mp.setDataSource(Environment.getExternalStorageDirectory().getPath()+
                    "/Musik/King.mp3");
mp.prepare();
mp.start();

but it is still not working. 但它仍然无法正常工作。

http://i.imgur.com/73vEaF9.png http://i.imgur.com/73vEaF9.png

(I know there is a lot of useless stuff in the code, I just wanted to show the mp3 path (on the right). (我知道代码中有很多无用的东西,我只想显示mp3路径(在右侧)。

I tried pasting the mp3 directly into the "sdcard". 我尝试将mp3直接粘贴到“ sdcard”中。

i dont even care if the path would be hard coded like "/storage/sdcard/Musik" (already tried, its not working. not even with mnt/sdcard/Musik 我什至不在乎路径是否会像“ / storage / sdcard / Musik”这样硬编码(已经尝试过,它无法正常工作。即使使用mnt / sdcard / Musik也无法使用)

Did you verify what path "Environment.getExternalStorageDirectory()" is? 您是否验证了“ Environment.getExternalStorageDirectory()”是什么路径? Maybe it is not what you expect it to be. 也许这不是您所期望的。 This path doesn't necessarily always point to the external sd card location. 此路径不一定总是指向外部SD卡位置。

Please check: 请检查:

http://www.weston-fl.com/blog/?p=2988 http://www.weston-fl.com/blog/?p=2988

You're probably using the wrong path o no permission. 您可能使用了错误的路径或没有权限。 I recommend you to check the path and check if exits with File.exists() method . 我建议您检查路径,并使用File.exists()方法检查是否退出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM