原始文件夹和SD卡上的机器人之间的媒体播放器问题 [英] media player problem between raw folder and sdcard on android

查看:92
本文介绍了原始文件夹和SD卡上的机器人之间的媒体播放器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜 我做的应用程序,用于播放歌搜索栏。如果从原始文件夹中发挥它的工作原理,但如果我从SD卡它显示空指针异常播放歌曲。

hi i am doing app for playing song with seek bar. if play from raw folder it works but if i play song from sdcard it shows null pointer exception.

private MediaPlayer mediaPlayer;

mediaPlayer = MediaPlayer.create(this, R.raw.t1); // it works

//  switch to sdcard

  mediaPlayer.setDataSource("/sdcard/t1.mp3"); // null pointer exception.

我不知道是什么问题。请帮助我。

i do not know what is the problem. please help me.

推荐答案

您需要确保你给的路径的setDataSource() 是完全正确的。这样做,而不是硬编码的参考/ SD卡/这一点,最好的办法,就是用 android.os.Environment.getExternalStorageDirectory()

You need to make sure the path you give to setDataSource() is exactly correct. The best way to do this, instead of hardcoding the reference to '/sdcard/', is to use android.os.Environment.getExternalStorageDirectory()

试试这个,我认为这将有助于你

Try this, I think it will help you

MediaPlayer mediaPlayer = new MediaPlayer();
File path = android.os.Environment.getExternalStorageDirectory();
mediaPlayer.setDataSource(path + "/t1.mp3");

我希望这可以帮助您

I hope this help you

这篇关于原始文件夹和SD卡上的机器人之间的媒体播放器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆